Skip to content
_gt3 edited this page Aug 13, 2017 · 9 revisions

Primary Operations

check(...identifiers)(...checks)

identifier: string, check: regex literal/object

Create a validation object to check one or more identifiers with one or more regular expressions (literal/object form). The returned object has keys that are identifiers and values are corresponding regex checks wrapped in an executable function.

let yearChk = check(':year')(/^201[0-7]$/) // 2010 - 2017
let typeColorChk = check(':type', ':color')(/.{3}/, /^[a-z]+$/) // at least 3 characters

spec(...pathKeys)(next, err?, fail?)

pathKey: string, next,err,fail: function

Create a spec over one or more path keys and actions.

// show vehicle "type" by "year" or "color"
let vehicleSpec = spec('/:type', '/:type/:year', '/:type/:color')(next, err, fail)

match(specs, checks?, matchCheck?)

specs: object or [object], checks: object, matchCheck: function

Create a matcher object from one or more specs. Pass checks object to validate identifiers. Pass matchCheck function to modify current route path before specs are executed.

let vehicleMatcher = match(vehicleSpec, {...yearChk, ...typeColorChk})

container(matchers, mismatchers?, instance?, scheduleDispatch?)

matchers, mismatchers: object or [object], instance: object, scheduleDispatch: boolean

Create an ultra instance that runs provided matchers for the current url and registers a listener to handle pushstate routing. Pass ultra instance to update that instance with new matchers. scheduleDispatch controls if current url should be dispatched. scheduleDispatch is true by default if an instance is not provided or if the provided instance has not dispatched yet. Override the default value by providing true/false.

let ultra = container(vehicleMatcher)
/*** example run ***/
/*

next: called on exact match for sample routes
  /automobile or /motorcycle
  /automobile/red or /automobile/2017
  /motorcycle/blue or /motorcycle/2017

err: called on partial match
  /automobile/2020 or /motorcycle/z

fail: called after matching is complete and spec did not match
  /z

*/

Other Operations

prefixMatch(prefixKey, matcher, prematchCheck?)

prefixKey: string, matcher: object, prematchCheck: function

Create a prefixed matcher. prefixKey can contain literals and identifiers. matcher is invoked only if prefixKey matches the path (exactly or partially). Pass prematchCheck function to modify current route path before matcher is executed.

toggle(matcher, newKey?, replacement?)

newKey: string, matcher, replacement: object

Dectivate/reactivate a matcher. Use newKey to identify the matcher later. Replace original matcher with replacement matcher.

toggleSelected(matchers, key, replacements?)

matchers: [object], key: string, replacements: object or [object]

Toggle multiple matchers identified by key. Provide replacements to sequentially replace identified matchers.

miss(next, ...pathKeys)

next: function, pathKey: string

Create a missMatcher to invoke next if none of the provided pathKeys matched.

Utility Functions

a.link

assignValues

parseQS

prependPath

appendPath

scheduleTask

Clone this wiki locally