Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

abstract-state-router

Package Overview
Dependencies
Maintainers
1
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

abstract-state-router - npm Package Compare versions

Comparing version 5.9.0 to 5.10.0

changelog.md

30

index.js

@@ -14,6 +14,7 @@ var StateState = require('./lib/state-state')

var newHashBrownRouter = require('hash-brown-router')
var Promise = require('native-promise-only/npo')
var combine = require('combine-arrays')
var buildPath = require('page-path-builder')
require('native-promise-only/npo')
var expectedPropertiesOfAddState = ['name', 'route', 'defaultChild', 'data', 'template', 'resolve', 'activate', 'querystringParameters', 'defaultQuerystringParameters']

@@ -57,6 +58,2 @@

function destroyStateName(stateName) {
activeEmitters[stateName].emit('destroy')
activeEmitters[stateName].removeAllListeners()
delete activeEmitters[stateName]
delete activeStateResolveContent[stateName]
var state = prototypalStateHolder.get(stateName)

@@ -68,2 +65,7 @@ stateProviderEmitter.emit('beforeDestroyState', {

activeEmitters[stateName].emit('destroy')
activeEmitters[stateName].removeAllListeners()
delete activeEmitters[stateName]
delete activeStateResolveContent[stateName]
return destroyDom(activeDomApis[stateName]).then(function() {

@@ -78,5 +80,2 @@ delete activeDomApis[stateName]

function resetStateName(parameters, stateName) {
activeEmitters[stateName].emit('destroy')
delete activeEmitters[stateName]
var domApi = activeDomApis[stateName]

@@ -92,2 +91,5 @@ var content = getContentObject(activeStateResolveContent, stateName)

activeEmitters[stateName].emit('destroy')
delete activeEmitters[stateName]
return resetDom({

@@ -301,3 +303,7 @@ domApi: domApi,

function makePath(stateName, parameters) {
function makePath(stateName, parameters, options) {
if (options && options.inherit) {
parameters = extend(current.get().parameters, parameters)
}
prototypalStateHolder.guaranteeAllStatesExist(stateName)

@@ -317,3 +323,3 @@ var route = prototypalStateHolder.buildFullStateRoute(stateName)

return promiseMe(makePath, newStateName, parameters).then(goFunction, handleError.bind(null, 'stateChangeError'))
return promiseMe(makePath, newStateName, parameters, options).then(goFunction, handleError.bind(null, 'stateChangeError'))
}

@@ -327,4 +333,4 @@ stateProviderEmitter.evaluateCurrentRoute = function evaluateCurrentRoute(defaultState, defaultParams) {

}
stateProviderEmitter.makePath = function makePathAndPrependHash(stateName, parameters) {
return stateRouterOptions.pathPrefix + makePath(stateName, parameters)
stateProviderEmitter.makePath = function makePathAndPrependHash(stateName, parameters, options) {
return stateRouterOptions.pathPrefix + makePath(stateName, parameters, options)
}

@@ -331,0 +337,0 @@ stateProviderEmitter.stateIsActive = function stateIsActive(stateName, opts) {

2

package.json
{
"name": "abstract-state-router",
"version": "5.9.0",
"version": "5.10.0",
"description": "The basics of a client-side state router ala the AngularJS ui-router, but without any DOM interactions",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -167,6 +167,8 @@ [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.

## stateRouter.makePath(stateName, [stateParameters])
## stateRouter.makePath(stateName, [stateParameters], options)
Returns a path to the state, starting with an [optional](#options) octothorpe `#`, suitable for inserting straight into the `href` attribute of a link.
The `options` object supports one property: `inherit` - if true, querystring parameters are inherited from the current state. Defaults to false.
```js

@@ -176,2 +178,22 @@ stateRouter.makePath('app.tab2', { pants: 'no' })

## Events
These are all emitted on the state router object.
### State change
- `stateChangeAttempt(functionThatBeginsTheStateChange)` - used by the state transition manager, probably not use to anyone else at the moment
- `stateChangeStart(state, parameters)` - emitted after the state name and parameters have been validated
- `stateChangeCancelled(err)` - emitted if a redirect is issued in a resolve function
- `stateChangeEnd(state, parameters)` - after all activate functions are called
### DOM API interactions
- `beforeCreateState({state, content})`
- `afterCreateState({state, domApi, content})`
- `beforeResetState({state, domApi, content})`
- `afterResetState({state, domApi, content})`
- `beforeDestroyState({state, domApi})`
- `afterDestroyState({state})`
# Testing/development

@@ -178,0 +200,0 @@

var test = require('tape-catch')
var qs = require('querystring')
var getTestState = require('./helpers/test-state-factory')

@@ -35,3 +36,3 @@

t.equal('#/parent/child1?param=value', stateRouter.makePath('parent.child1', { param: 'value' }))
t.equal(stateRouter.makePath('parent.child1', { param: 'value' }), '#/parent/child1?param=value')

@@ -50,6 +51,32 @@ t.throws(function() {

t.equal('/parent/child1?thingy=value', stateRouter.makePath('parent.child1', { thingy: 'value' }))
t.equal('/parent?thingy=value', stateRouter.makePath('parent', { thingy: 'value' }))
t.equal(stateRouter.makePath('parent.child1', { thingy: 'value' }), '/parent/child1?thingy=value')
t.equal(stateRouter.makePath('parent', { thingy: 'value' }), '/parent?thingy=value')
t.end()
})
test('makePath respects the inherit option', function(t) {
var stateRouter = basicRouterSetup(t)
function justTheQuerystring(str) {
var match = /\?(.+)$/.exec(str)
return qs.parse(match[1])
}
stateRouter.on('stateChangeEnd', function() {
var output = justTheQuerystring(stateRouter.makePath('parent.child2', { otherParameter: 'other value' }, { inherit: true }))
t.equal(output.originalParameter, 'original value')
t.equal(output.otherParameter, 'other value')
t.equal(Object.keys(output).length, 2)
output = justTheQuerystring(stateRouter.makePath('parent.child2', { originalParameter: 'new value' }, { inherit: true }))
t.equal(output.originalParameter, 'new value')
t.equal(Object.keys(output).length, 1)
t.end()
})
stateRouter.go('parent.child1', {
originalParameter: 'original value'
})
})

@@ -287,30 +287,2 @@ var test = require('tape-catch')

test('propertiesInRoute', function(t) {
var testState = getTestState(t)
var stateRouter = testState.stateRouter
var hashRouter = testState.hashRouter
t.plan(2)
var timesActivatedCalled = 0
stateRouter.addState({
name: 'only',
template: '',
route: '/something/:param/whatever',
activate: function(context) {
timesActivatedCalled++
if (timesActivatedCalled === 1) {
t.equal(context.parameters.param, 'firstTime')
hashRouter.go('/something/secondTime/whatever')
} else {
t.equal(context.parameters.param, 'secondTime')
t.end()
}
}
})
stateRouter.go('only', { param: 'firstTime' })
})
test('evaluateCurrentRoute with url set', function(t) {

@@ -317,0 +289,0 @@ var testState = getTestState(t)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc