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.8.1 to 5.9.0

55

index.js

@@ -60,4 +60,13 @@ var StateState = require('./lib/state-state')

delete activeStateResolveContent[stateName]
var state = prototypalStateHolder.get(stateName)
stateProviderEmitter.emit('beforeDestroyState', {
state: state,
domApi: activeDomApis[stateName]
})
return destroyDom(activeDomApis[stateName]).then(function() {
delete activeDomApis[stateName]
stateProviderEmitter.emit('afterDestroyState', {
state: state
})
})

@@ -69,7 +78,24 @@ }

delete activeEmitters[stateName]
var domApi = activeDomApis[stateName]
var content = getContentObject(activeStateResolveContent, stateName)
var state = prototypalStateHolder.get(stateName)
stateProviderEmitter.emit('beforeResetState', {
domApi: domApi,
content: content,
state: state
})
return resetDom({
domApi: activeDomApis[stateName],
content: getContentObject(activeStateResolveContent, stateName),
template: prototypalStateHolder.get(stateName).template,
domApi: domApi,
content: content,
template: state.template,
parameters: parameters
}).then(function() {
stateProviderEmitter.emit('afterResetState', {
domApi: domApi,
content: content,
state: state
})
})

@@ -92,11 +118,24 @@ }

return getChildElementForStateName(stateName).then(function(childElement) {
var state = prototypalStateHolder.get(stateName)
var content = getContentObject(activeStateResolveContent, stateName)
stateProviderEmitter.emit('beforeCreateState', {
state: state,
content: content
})
return renderDom({
element: childElement,
template: prototypalStateHolder.get(stateName).template,
content: getContentObject(activeStateResolveContent, stateName),
template: state.template,
content: content,
parameters: parameters
}).then(function(domApi) {
activeDomApis[stateName] = domApi
stateProviderEmitter.emit('afterCreateState', {
state: state,
domApi: domApi,
content: content
})
return domApi
})
}).then(function(domApi) {
activeDomApis[stateName] = domApi
return domApi
})

@@ -103,0 +142,0 @@ }

2

package.json
{
"name": "abstract-state-router",
"version": "5.8.1",
"version": "5.9.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",

@@ -192,3 +192,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.

- emit StateChangeStart
- emit stateChangeStart
- call all resolve functions

@@ -202,3 +202,3 @@ - resolve functions return

- call all activate functions
- emit StateChangeEnd
- emit stateChangeEnd

@@ -205,0 +205,0 @@ # Every state change does this to states

var test = require('tape-catch')
var assertingRendererFactory = require('./helpers/asserting-renderer-factory')
var getTestState = require('./helpers/test-state-factory')
var mockRendererFacotry = require('./helpers/renderer-mock')

@@ -190,1 +191,221 @@ test('Emitting errors when attempting to navigate to invalid states', function(t) {

})
test('emitting dom api create', function(t) {
var originalDomApi = {}
var renderCalled = false
var beforeEventFired = false
var afterEventFired = false
t.plan(14)
var state = getTestState(t, function() {
return {
render: function(context, cb) {
t.ok(beforeEventFired)
renderCalled = true
t.notOk(afterEventFired)
cb(null, originalDomApi)
},
reset: function(context, cb) {
cb(null)
},
destroy: function(renderedTemplateApi, cb) {
cb(null)
},
getChildElement: function getChildElement(renderedTemplateApi, cb) {
cb(null, {})
}
}
})
var stateRouter = state.stateRouter
var originalStateObject = {
name: 'state',
route: '/state',
template: {},
querystringParameters: [ 'wat', 'much' ],
defaultQuerystringParameters: { wat: 'lol', much: 'neat' },
resolve: function(data, params, cb) {
cb(null, {
value: 'legit'
})
}
}
stateRouter.addState(originalStateObject)
stateRouter.on('beforeCreateState', function(context) {
t.notOk(renderCalled)
t.notOk(afterEventFired)
t.notOk(beforeEventFired)
beforeEventFired = true
t.equal(context.state, originalStateObject)
t.equal(context.content.value, 'legit')
t.notOk(context.domApi)
})
stateRouter.on('afterCreateState', function(context) {
t.ok(beforeEventFired)
t.ok(renderCalled)
t.notOk(afterEventFired)
afterEventFired = true
t.equal(context.state, originalStateObject)
t.equal(context.content.value, 'legit')
t.equal(context.domApi, originalDomApi)
t.end()
})
stateRouter.go('state', {})
})
test('emitting dom api destroy', function(t) {
var originalDomApi = {}
var beforeEventFired = false
var afterEventFired = false
var destroyCalled = false
var state = getTestState(t, function() {
return {
render: function(context, cb) {
cb(null, originalDomApi)
},
reset: function(context, cb) {
cb(null)
},
destroy: function(renderedTemplateApi, cb) {
t.ok(beforeEventFired)
t.notOk(afterEventFired)
destroyCalled = true
cb(null)
},
getChildElement: function getChildElement(renderedTemplateApi, cb) {
cb(null, {})
}
}
})
var stateRouter = state.stateRouter
t.plan(11)
var originalStateObject = {
name: 'state',
route: '/state',
template: {},
activate: function() {
stateRouter.go('second-state', {})
}
}
stateRouter.addState(originalStateObject)
stateRouter.addState({
name: 'second-state',
route: '/second',
template: {},
activate: function(context) {
t.ok(afterEventFired)
t.end()
}
})
stateRouter.on('beforeDestroyState', function(context) {
t.notOk(destroyCalled)
t.notOk(afterEventFired)
beforeEventFired = true
t.equal(context.state, originalStateObject)
t.equal(context.domApi, originalDomApi)
})
stateRouter.on('afterDestroyState', function(context) {
t.ok(beforeEventFired)
t.ok(destroyCalled)
afterEventFired = true
t.equal(context.state, originalStateObject)
t.notOk(context.domApi)
})
stateRouter.go('state', {})
})
test('emitting dom api reset', function(t) {
var originalDomApi = {}
var secondDomApi = {}
var domApis = [originalDomApi, secondDomApi]
var beforeEventFired = false
var afterEventFired = false
var resetCalled = false
t.plan(14)
var state = getTestState(t, function() {
return {
render: function(context, cb) {
cb(null, domApis.shift())
},
reset: function(context, cb) {
if (!resetCalled) {
t.ok(beforeEventFired)
t.notOk(afterEventFired)
resetCalled = true
}
cb(null)
},
destroy: function(renderedTemplateApi, cb) {
cb(null)
},
getChildElement: function getChildElement(renderedTemplateApi, cb) {
cb(null, {})
}
}
})
var stateRouter = state.stateRouter
var originalStateObject = {
name: 'state',
route: '/state',
template: {},
querystringParameters: [ 'wat' ],
resolve: function(data, params, cb) {
cb(null, {
value: 'legit'
})
},
activate: function() {
setTimeout(function() {
stateRouter.go('state', { wat: 20 })
}, 10)
}
}
stateRouter.addState(originalStateObject)
stateRouter.on('beforeResetState', function(context) {
t.notOk(beforeEventFired)
t.notOk(resetCalled)
t.notOk(afterEventFired)
beforeEventFired = true
t.equal(context.state, originalStateObject)
t.equal(context.domApi, originalDomApi)
t.equal(context.content.value, 'legit')
})
stateRouter.on('afterResetState', function(context) {
t.ok(beforeEventFired)
t.ok(resetCalled)
t.notOk(afterEventFired)
afterEventFired = true
t.equal(context.state, originalStateObject)
t.equal(context.domApi, originalDomApi)
t.equal(context.content.value, 'legit')
t.end()
})
stateRouter.go('state', { wat: 10 })
})

@@ -1,2 +0,2 @@

var myArbitraryRenderFunction = function lol(parent, cb) {
function myArbitraryRenderFunction(parent, cb) {
var child = {}

@@ -3,0 +3,0 @@

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