abstract-state-router
Advanced tools
Comparing version 5.0.2 to 5.1.0
27
index.js
@@ -14,4 +14,5 @@ var StateState = require('./state-state') | ||
var StateTransitionManager = require('./state-transition-manager') | ||
var debug = require('debug')('abstract-state-router') | ||
module.exports = function StateProvider(makeRenderer, rootElement, hashRouter) { | ||
module.exports = function StateProvider(makeRenderer, rootElement, stateRouterOptions) { | ||
var prototypalStateHolder = StateState() | ||
@@ -21,3 +22,10 @@ var current = CurrentState() | ||
StateTransitionManager(stateProviderEmitter) | ||
hashRouter = hashRouter || newHashBrownRouter() | ||
stateRouterOptions = extend({ | ||
throwOnError: true | ||
}, stateRouterOptions) | ||
if (!stateRouterOptions.router) { | ||
stateRouterOptions.router = newHashBrownRouter() | ||
} | ||
current.set('', {}) | ||
@@ -37,3 +45,6 @@ | ||
stateProviderEmitter.emit(event, err) | ||
console.error(err) | ||
debug(event + ' - ' + err.message) | ||
if (stateRouterOptions.throwOnError) { | ||
throw err | ||
} | ||
}) | ||
@@ -112,3 +123,3 @@ } | ||
hashRouter.add(route, onRouteChange.bind(null, state)) | ||
stateRouterOptions.router.add(route, onRouteChange.bind(null, state)) | ||
} | ||
@@ -199,3 +210,3 @@ | ||
} catch (e) { | ||
handleError('error', e) | ||
handleError('stateError', e) | ||
} | ||
@@ -231,3 +242,3 @@ }).catch(ifNotCancelled(function handleStateChangeError(err) { | ||
options = extend({}, defaultOptions, options) | ||
var goFunction = options.replace ? hashRouter.replace : hashRouter.go | ||
var goFunction = options.replace ? stateRouterOptions.router.replace : stateRouterOptions.router.go | ||
@@ -238,5 +249,5 @@ return promiseMe(makePath, newStateName, parameters).then(goFunction, handleError.bind(null, 'stateChangeError')) | ||
return promiseMe(makePath, defaultRoute, defaultParams).then(function(defaultPath) { | ||
hashRouter.evaluateCurrent(defaultPath) | ||
stateRouterOptions.router.evaluateCurrent(defaultPath) | ||
}).catch(function(err) { | ||
handleError('error', err) | ||
handleError('stateError', err) | ||
}) | ||
@@ -243,0 +254,0 @@ } |
{ | ||
"name": "abstract-state-router", | ||
"version": "5.0.2", | ||
"version": "5.1.0", | ||
"description": "The basics of a client-side state router ala the AngularJS ui-router, but without any DOM interactions", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "tape test/*.js" | ||
"zuul": "zuul -- test/*.js", | ||
"test": "tape test/*.js | faucet" | ||
}, | ||
@@ -26,2 +27,3 @@ "repository": { | ||
"combine-arrays": "^1.0.0", | ||
"debug": "^2.1.3", | ||
"extend": "^2.0.0", | ||
@@ -35,4 +37,6 @@ "hash-brown-router": "^1.3.0", | ||
"devDependencies": { | ||
"tape": "^2.14.0" | ||
"faucet": "0.0.1", | ||
"tape": "^2.14.0", | ||
"zuul": "^3.0.0" | ||
} | ||
} |
@@ -16,3 +16,3 @@ [ui-router](https://github.com/angular-ui/ui-router/wiki) is fantastic, and I would use it in all of my projects if it wasn't tied to AngularJS. | ||
var stateRouter = createStateRouter(makeRenderer, rootElement, router) | ||
var stateRouter = createStateRouter(makeRenderer, rootElement, options) | ||
``` | ||
@@ -24,4 +24,7 @@ | ||
`router` defaults to an instance of a [hash brown router](https://github.com/TehShrike/hash-brown-router/). It's an optional argument for the purpose of passing in a mock for unit tests. | ||
`options` are mostly to override some defaults while testing. You shouldn't need to change any of the defaults while developing. Possible properties are: | ||
- `router` defaults to an instance of a [hash brown router](https://github.com/TehShrike/hash-brown-router/). The abstract-state-router unit tests use the [hash brown router stub](https://github.com/TehShrike/hash-brown-router/#testability). | ||
- `throwOnError` defaults to true, because you get way better stack traces in Chrome when you throw than if you `console.log(err)` or emit `'error'` events. The unit tests disable this. | ||
## stateRouter.addState({name, route, defaultChild, data, template, resolve, activate, querystringParameters}) | ||
@@ -28,0 +31,0 @@ |
@@ -54,3 +54,3 @@ var test = require('tape') | ||
stateRouter.on('stateChangeError', failure('stateChangeError') ) | ||
stateRouter.on('error', failure('error')) | ||
stateRouter.on('stateError', failure('stateError')) | ||
@@ -57,0 +57,0 @@ stateRouter.addState({ name: 'hello', template: 'hello' }) |
@@ -9,3 +9,6 @@ var hashRouterFactory = require('hash-brown-router') | ||
var hashRouter = hashRouterFactory(location) | ||
var stateRouter = stateRouterFactory(renderFn || mockRenderFn, 'body', hashRouter) | ||
var stateRouter = stateRouterFactory(renderFn || mockRenderFn, 'body', { | ||
router: hashRouter, | ||
throwOnError: false | ||
}) | ||
hashRouter.setDefault(function noop() {}) | ||
@@ -12,0 +15,0 @@ |
@@ -5,3 +5,2 @@ var test = require('tape') | ||
function testParsing(t, input, output) { | ||
// console.log(t, t.deepEqual, parse) | ||
t.deepEqual(parse(input), output, input + ' produces ' + output.length + ' results') | ||
@@ -8,0 +7,0 @@ } |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
83203
28
2430
169
8
3
+ Addeddebug@^2.1.3
+ Addeddebug@2.6.9(transitive)
+ Addedms@2.0.0(transitive)