1.0.3 • Published 9 years ago

octane v1.0.3

Weekly downloads
2
License
MIT
Repository
github
Last release
9 years ago

Router

-

Router.add(pattern, callback) ⇒ this

Add a route to be called when the URL changes

Kind: static method of Router
Returns: this - for method chaining
Access: public

ParamTypeDescription
patternregexp | stringA 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.
callbackfunctionThe callback to execute on a matching route, will be applied with the matched values of the route regexp

-

Router.atRoot ⇒ boolean

Determine if the current location is the Application's root

Kind: static property of Router
Access: public
Read only: true

-

Router.beforePageLoad(page(s), deferred) ⇒ this

Add a Promise that must resolve before a page (or pages) can load

Kind: static method of Router
Returns: this - for method chaining
Access: public
See: OctanePage

ParamTypeDescription
page(s)string | arrayThe names of pages the condition should be evaluated for
deferredfunctionA deferred function that will be wrapped in a Promise

Example

Octane.Router.beforePageLoad('about',function(resove,reject){...});

-

Router.clearRoutes()

Remove all routes from the Router

Kind: static method of Router
Access: public

-

Router.currentPage

Get the current page of the Application

Kind: static property of Router
Access: public
Read only: true

-

Router.isLocked ⇒ boolean

Is the router locked?

Kind: static property of Router
Access: public
Read only: true

-

Router.lock() ⇒ string

Lock the Router

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

-

Router.mode ⇒ object

Get the mode details of the application

Kind: static property of Router
Returns: object - Returns an object with keys history, hash, and local. Values are booleans
Access: public
Read only: true

-

Router.onPageExit(page(s), callback, argsArray, thisArg) ⇒ this

Add a callback to the array of callbacks executed when a page has animated offscreen. Callbacks are wrapped in Promises at time of execution.

Kind: static method of Router
Returns: this - for method chaining
Access: public
See: OctanePage

ParamTypeDescription
page(s)string | arrayThe names of pages the callback should execute for
callbackfunctionA callback to execute
argsArrayarrayAn array of arguments to be applied to the callback at execution
thisArgobjectThe 'this' value of the callback at execution time, default is the Page object

-

Router.onPageLoad(page(s), callback, argsArray, thisArg) ⇒ this

Add a callback to the array of callbacks executed when a page has animated onscreen. Callbacks are wrapped in Promises at time of execution.

Kind: static method of Router
Returns: this - for method chaining
Access: public
See: OctanePage

ParamTypeDescription
page(s)string | arrayThe names of pages the callback should execute for
callbackfunctionA callback to execute
argsArrayarrayAn array of arguments to be applied to the callback at execution
thisArgobjectThe 'this' value of the callback at execution time, default is the Page object

Example

// 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);

-

Router.onUndefined()

Define a function to call in the event no routes exist on the specified path

Kind: static method of Router
Access: public

-

Router.pageLoadIf(page(s), predicate) ⇒ this

Add a predicate condition that must be true for a page(s) to load

Kind: static method of Router
Returns: this - for method chaining
Access: public
See: OctanePage

ParamTypeDescription
page(s)string | arrayThe names of page(s) the condition should be evaluated for
predicatefunctionA function that should return a truthy or falsy value

-

Router.queue ⇒ array

Queued Pages waiting to load during a lock

Kind: static property of Router
Returns: array - the array of queued pages
Access: public
Read only: true

-

Router.remove(pattern)

Remove a route from the array of saved routes

Kind: static method of Router
Access: public

ParamTypeDescription
patternregexpThe pattern to remove

-

Router.route(route)

Determine hashing format and page from fragment, then use history.pushState or hashchange to set the route

Kind: static method of Router
Access: public

ParamTypeDescription
routestringRoot-relative URL fragment to be mapped by Router._executeRoute

-

Router.routes ⇒ array

List of routes registered with the Router

Kind: static property of Router
Returns: array - the array of registered routes
Access: public
Read only: true

-

Router.unlock(key) ⇒ boolean

Unlock the router from a calling of Router.lock. 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 10

Kind: 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

ParamTypeDescription
keystringThe key returned from Router.lock to unlock the lock it placed. Other locks may still be in place.

-

Router.urlSearchObject() ⇒ object

Helper to parse URL's search string into an object

Kind: static method of Router
Returns: object - an object of search parameters
Access: public
Example

Router.urlSearchObject("http://yoursite.com?pawns=5&kings=1")
=> {kings: 1, pawns: 5}

-

Router.useBrowserEvents()

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

-

Router.usePolling()

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

-