MVCVM UI-Routing app framework with uni-directional dataflow
npm install octane* Router
* .add(pattern, callback) ⇒ this
* .atRoot ⇒ boolean
* .beforePageLoad(page(s), deferred) ⇒ this
* .clearRoutes()
* .currentPage
* .isLocked ⇒ boolean
* .lock() ⇒ string
* .mode ⇒ object
* [.onPageExit(page(s), callback, [argsArray], [thisArg])](#Octane.module_Router.onPageExit) ⇒ this
* [.onPageLoad(page(s), callback, [argsArray], [thisArg])](#Octane.module_Router.onPageLoad) ⇒ this
* .onUndefined()
* .pageLoadIf(page(s), predicate) ⇒ this
* .queue ⇒ array
* .remove(pattern)
* .route(route)
* .routes ⇒ array
* .unlock(key) ⇒ boolean
* .urlSearchObject() ⇒ object
* .useBrowserEvents()
* .usePolling()
-
Kind: static method of Router
Returns: this - for method chaining
Access: public
| Param | Type | Description |
| --- | --- | --- |
| pattern | regexp | string | A regexp pattern that matches a route against a URL. If passed as a string, beginning and trailing slashes will be stripped before being added to the routes array. |
| callback | function | The callback to execute on a matching route, will be applied with the matched values of the route regexp |
-
Kind: static property of Router
Access: public
Read only: true
-
Kind: static method of Router
Returns: this - for method chaining
Access: public
See: OctanePage
| Param | Type | Description |
| --- | --- | --- |
| page(s) | string | array | The names of pages the condition should be evaluated for |
| deferred | function | A deferred function that will be wrapped in a Promise |
Example
``js`
Octane.Router.beforePageLoad('about',function(resove,reject){...});
-
Kind: static method of Router
Access: public
-
Kind: static property of Router
Access: public
Read only: true
-
Kind: static property of Router
Access: public
Read only: true
-
Kind: static method of Router
Returns: string - A randomly generated key to unlock the router from __THIS__ lock. Other locks may still be in place.
Access: public
-
Kind: static property of Router
Returns: object - Returns an object with keys history, hash, and local. Values are booleans
Access: public
Read only: true
-
Kind: static method of Router
Returns: this - for method chaining
Access: public
See: OctanePage
| Param | Type | Description |
| --- | --- | --- |
| page(s) | string | array | The names of pages the callback should execute for |
| callback | function | A callback to execute |
| [argsArray] | array | An array of arguments to be applied to the callback at execution |
| [thisArg] | object | The 'this' value of the callback at execution time, default is the Page object |
-
Kind: static method of Router
Returns: this - for method chaining
Access: public
See: OctanePage
| Param | Type | Description |
| --- | --- | --- |
| page(s) | string | array | The names of pages the callback should execute for |
| callback | function | A callback to execute |
| [argsArray] | array | An array of arguments to be applied to the callback at execution |
| [thisArg] | object | The 'this' value of the callback at execution time, default is the Page object |
Example
`js`
// creates new Person with current values of Registrant ViewModel when page 'registrants' is loaded
Octane.Router.onPageLoad('registrants',
addNewPerson,
[octane.get('Registrant.name'),octane.get('Registrant.job')],
Person);
-
Kind: static method of Router
Access: public
-
Kind: static method of Router
Returns: this - for method chaining
Access: public
See: OctanePage
| Param | Type | Description |
| --- | --- | --- |
| page(s) | string | array | The names of page(s) the condition should be evaluated for |
| predicate | function | A function that should return a truthy or falsy value |
-
Kind: static property of Router
Returns: array - the array of queued pages
Access: public
Read only: true
-
Kind: static method of Router
Access: public
| Param | Type | Description |
| --- | --- | --- |
| pattern | regexp | The pattern to remove |
-
Kind: static method of Router
Access: public
| Param | Type | Description |
| --- | --- | --- |
| route | string | Root-relative URL fragment to be mapped by Router._executeRoute |
-
Kind: static property of Router
Returns: array - the array of registered routes
Access: public
Read only: true
-
.
If the Router is locked, then after X number of failed unlocked attempts in a row,
the Router will lock out and the Application will need to be restarted.
Number of attempts can be set at Octane.initialize via appConfig.maxConsecutiveAllowedRouterUnlockAttemps, or defaults to 10Kind: static method of Router
Returns: boolean - false if key is invalid or more locks remain, otherwise true and loads pages queued during lock
Throws:
- Error thrown when the maximum number of consecutive failed unlocks is attempted. Router becomes permanently locked and Application will need restarted (prevent brute force unlocks)
Access: public
| Param | Type | Description |
| --- | --- | --- |
| key | string | The key returned from
Router.lock to unlock the lock it placed. Other locks may still be in place. |
-
$3
Helper to parse URL's search string into an objectKind: static method of Router
Returns: object - an object of search parameters
Access: public
Example
`js
Router.urlSearchObject("http://yoursite.com?pawns=5&kings=1")
=> {kings: 1, pawns: 5}
`-
$3
Update App state on URL change. Turns off polling interval if set. Octane calls this during initilization, unless overridden by appConfig.legacyRouting: true.Kind: static method of Router
Access: public
-
$3
Set fallback to use polling in case popstate/hashchange is being finicky. Drops popstate or hashchange` event listeners.Kind: static method of Router
Access: public
-