abstract-state-router
Advanced tools
Comparing version 5.12.5 to 5.13.0
@@ -0,8 +1,16 @@ | ||
# [5.13.0](https://github.com/TehShrike/abstract-state-router/releases/tag/v5.13.0) | ||
- functional: made `stateName` optional for `go`/`replace`/`makePath` [#83](https://github.com/TehShrike/abstract-state-router/pull/83) | ||
# [5.12.5](https://github.com/TehShrike/abstract-state-router/releases/tag/v5.12.5) | ||
- dependency update: require page-path-builder 1.0.3, fixing a path-building bug [#650af6af](https://github.com/TehShrike/abstract-state-router/commit/650af6af9ad622caecd1c8ea7b02dfb22aa63ff2) | ||
# [5.12.4](https://github.com/TehShrike/abstract-state-router/releases/tag/v5.12.4) | ||
- bug fix: `stateIsActive` was doing an extremely naive check https://github.com/TehShrike/abstract-state-router/pull/71 | ||
- bug fix: `stateIsActive` was doing an extremely naive check [#71](https://github.com/TehShrike/abstract-state-router/pull/71) | ||
# [5.12.3](https://github.com/TehShrike/abstract-state-router/releases/tag/v5.12.3) | ||
- bug fix: `makePath(stateName, params, { inherit: true })` now properly inherits route parameters during the render/activate phases https://github.com/TehShrike/abstract-state-router/commit/7617d74be416d57ac2726cd0d45744627963ec2e | ||
- bug fix: `makePath(stateName, params, { inherit: true })` now properly inherits route parameters during the render/activate phases [#7617d74b](https://github.com/TehShrike/abstract-state-router/commit/7617d74be416d57ac2726cd0d45744627963ec2e) | ||
@@ -15,3 +23,3 @@ # [5.12.2](https://github.com/TehShrike/abstract-state-router/releases/tag/v5.12.2) | ||
- bug fix: states that had child states without routes weren't necessarily loading the correct child state when you browsed to them https://github.com/TehShrike/abstract-state-router/commit/85112c7965c1bcdea1576b9d8c4f7585b65380e4 | ||
- bug fix: states that had child states without routes weren't necessarily loading the correct child state when you browsed to them [#85112c79](https://github.com/TehShrike/abstract-state-router/commit/85112c7965c1bcdea1576b9d8c4f7585b65380e4) | ||
@@ -18,0 +26,0 @@ # [5.12.0](https://github.com/TehShrike/abstract-state-router/releases/tag/v5.12.0) |
14
index.js
@@ -307,8 +307,16 @@ var StateState = require('./lib/state-state') | ||
function makePath(stateName, parameters, options) { | ||
function getGuaranteedPreviousState() { | ||
if (!lastStateStartedActivating.get().name) { | ||
throw new Error('makePath required a previous state to exist, and none was found') | ||
} | ||
return lastStateStartedActivating.get() | ||
} | ||
if (options && options.inherit) { | ||
parameters = extend(lastStateStartedActivating.get().parameters, parameters) | ||
parameters = extend(getGuaranteedPreviousState().parameters, parameters) | ||
} | ||
prototypalStateHolder.guaranteeAllStatesExist(stateName) | ||
var route = prototypalStateHolder.buildFullStateRoute(stateName) | ||
var destinationState = stateName === null ? getGuaranteedPreviousState().name : stateName | ||
prototypalStateHolder.guaranteeAllStatesExist(destinationState) | ||
var route = prototypalStateHolder.buildFullStateRoute(destinationState) | ||
return buildPath(route, parameters || {}) | ||
@@ -315,0 +323,0 @@ } |
{ | ||
"name": "abstract-state-router", | ||
"version": "5.12.5", | ||
"version": "5.13.0", | ||
"description": "The basics of a client-side state router ala the AngularJS ui-router, but without any DOM interactions", | ||
@@ -38,5 +38,5 @@ "main": "index.js", | ||
"devDependencies": { | ||
"browserify": "13.0.1", | ||
"browserstack-runner": "0.4.4", | ||
"browserstack-tape-reporter": "1.0.2", | ||
"browserify": "13.1.0", | ||
"browserstack-runner": "TehShrike/browserstack-runner#fixing-json-borking", | ||
"browserstack-tape-reporter": "~1.1.0", | ||
"covert": "^1.1.0", | ||
@@ -43,0 +43,0 @@ "faucet": "0.0.1", |
@@ -160,2 +160,4 @@ [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. | ||
If `stateName` is `null`, the current state is used as the destination. | ||
```js | ||
@@ -194,2 +196,4 @@ stateRouter.go('app') | ||
If `stateName` is `null`, the current state is used. | ||
```js | ||
@@ -196,0 +200,0 @@ stateRouter.makePath('app.tab2', { pants: 'no' }) |
@@ -136,1 +136,23 @@ var test = require('tape-catch') | ||
}) | ||
test('makePath with null state name goes to the current state', function(t) { | ||
var stateRouter = basicRouterSetup(t) | ||
stateRouter.go('parent.child2', { thinger: 'whatsit' }) | ||
stateRouter.on('stateChangeEnd', function() { | ||
var output = stateRouter.makePath(null, { thinger: 'eh' }) | ||
t.equal(output, '#/parent/child2?thinger=eh') | ||
t.end() | ||
}) | ||
}) | ||
test('makePath with null state name throws an error if there is no current state', function(t) { | ||
var stateRouter = basicRouterSetup(t) | ||
t.throws(function() { | ||
stateRouter.makePath(null, { thinger: 'eh' }) | ||
}, /previous state/) | ||
t.end() | ||
}) |
106
test/test.js
var test = require('tape-catch') | ||
var assertingRendererFactory = require('./helpers/asserting-renderer-factory') | ||
var getTestState = require('./helpers/test-state-factory') | ||
var Promise = require('native-promise-only/npo') | ||
@@ -369,3 +368,2 @@ test('normal, error-less state activation flow for two states', function(t) { | ||
var stateRouter = testState.stateRouter | ||
var hashRouter = testState.hashRouter | ||
@@ -406,3 +404,2 @@ var correctRouteCalled = false | ||
var stateRouter = testState.stateRouter | ||
var hashRouter = testState.hashRouter | ||
@@ -445,3 +442,3 @@ t.plan(1) | ||
stateRouter.go('x', {foo: 'abc'}) | ||
}); | ||
}) | ||
@@ -467,4 +464,101 @@ test('reset fn receives parameters', function(t) { | ||
stateRouter.go('x', {foo: 'def'}) | ||
}); | ||
}) | ||
stateRouter.go('x', {foo: 'abc'}) | ||
}); | ||
}) | ||
test('go uses current state when no stateName is provided', function(t) { | ||
var testState = getTestState(t) | ||
var stateRouter = testState.stateRouter | ||
var firstActivateDidHappen = false | ||
t.plan(1) | ||
stateRouter.addState({ | ||
name: 'some-state', | ||
template: '', | ||
route: 'someState', | ||
querystringParameters: ['poop'], | ||
activate: function(context) { | ||
if (firstActivateDidHappen) { | ||
t.deepEqual(context.parameters, {poop: 'wet'}) | ||
t.end() | ||
} else { | ||
firstActivateDidHappen = true | ||
process.nextTick(function() { | ||
stateRouter.go(null, {poop: 'wet'}) | ||
}) | ||
} | ||
} | ||
}) | ||
stateRouter.go('some-state', {poop: 'dry'}) | ||
}) | ||
test('go uses current state when no stateName is provided with 2 parameters', function(t) { | ||
var testState = getTestState(t) | ||
var stateRouter = testState.stateRouter | ||
var firstActivateDidHappen = false | ||
t.plan(1) | ||
stateRouter.addState({ | ||
name: 'some-state', | ||
template: '', | ||
route: 'someState', | ||
querystringParameters: ['poop'], | ||
activate: function(context) { | ||
if (firstActivateDidHappen) { | ||
t.deepEqual(context.parameters, {poop: 'wet'}) | ||
t.end() | ||
} | ||
else { | ||
firstActivateDidHappen = true | ||
process.nextTick(function() { | ||
stateRouter.go(null, {poop: 'wet'}, {replace: true}) | ||
}) | ||
} | ||
} | ||
}) | ||
stateRouter.go('some-state', {poop: 'dry'}, {replace: true}) | ||
}) | ||
test('calling redirect with no stateName in resolve should use current state', function(t) { | ||
t.plan(1) | ||
var stateRouter = getTestState(t).stateRouter | ||
var isFirstResolve = true | ||
//This state is just so we have a "current state" we can get to first | ||
stateRouter.addState({ | ||
name: 'first', | ||
route: 'FRIST', | ||
template: '', | ||
activate: function(context) { | ||
process.nextTick(function() { | ||
stateRouter.go('second', {wut: 'fart'}) | ||
}) | ||
} | ||
}) | ||
stateRouter.addState({ | ||
name: 'second', | ||
route: 'SCONDE', | ||
template: '', | ||
querystringParameters: ['wut'], | ||
resolve: function(data, parameters, cb) { | ||
if (isFirstResolve) { | ||
isFirstResolve = false | ||
cb.redirect(null, {wut: 'butt'}) | ||
} else { | ||
cb() | ||
} | ||
}, | ||
activate: function(context) { | ||
//this should never get hit the first time since redirect gets called in resolve | ||
t.equal(context.parameters.wut, 'butt') | ||
t.end() | ||
} | ||
}) | ||
stateRouter.go('first') | ||
}) |
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
131684
3412
320