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 3.5.0 to 3.5.1

3

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

@@ -29,2 +29,3 @@ "main": "index.js",

"page-path-builder": "^1.0.1",
"path-to-regexp-with-reversible-keys": "^1.0.3",
"promise": "^6.0.1",

@@ -31,0 +32,0 @@ "promise-map-series": "^0.2.0"

var stateStringParser = require('./state-string-parser')
var combine = require('combine-arrays')
var pathToRegexp = require('path-to-regexp-with-reversible-keys')
module.exports = function StateComparison(stateState) {
var parametersChanged = parametersThatMatterWereChanged.bind(null, stateState)
var getPathParameters = pathParameters()
var parametersChanged = parametersThatMatterWereChanged.bind(null, stateState, getPathParameters)
return stateComparison.bind(null, parametersChanged)
}
function parametersThatMatterWereChanged(stateState, stateName, fromParameters, toParameters) {
var parameters = stateState.get(stateName).querystringParameters
function pathParameters() {
var parameters = {}
return function getPathParameters(path) {
if (!path) {
return []
}
if (!parameters[path]) {
parameters[path] = pathToRegexp(path).keys.map(function(key) {
return key.name
})
}
return parameters[path]
}
}
function parametersThatMatterWereChanged(stateState, getPathParameters, stateName, fromParameters, toParameters) {
var state = stateState.get(stateName)
var querystringParameters = state.querystringParameters || []
var parameters = getPathParameters(state.route).concat(querystringParameters)
return Array.isArray(parameters) && parameters.some(function(key) {

@@ -14,0 +37,0 @@ return fromParameters[key] !== toParameters[key]

@@ -5,6 +5,7 @@ var test = require('tape')

function simpleState(name, querystringParameters) {
function simpleState(name, querystringParameters, route) {
return {
name: name,
querystringParameters: querystringParameters
querystringParameters: querystringParameters,
route: route || ''
}

@@ -17,3 +18,3 @@ }

simpleState('app', ['appParam1']),
simpleState('app.main', ['main1']),
simpleState('app.main', ['main1'], '/:routeParam'),
simpleState('app.main.tab1', ['main1', 'main2']),

@@ -228,1 +229,24 @@ simpleState('app.main.tab2', ['main2', 'main3']),

})
test('changing states by modifying only a route parameter', function(t) {
var compare = setup()
var expected = [{
stateNameChanged: false,
stateParametersChanged: false,
nameBefore: 'app',
nameAfter: 'app'
}, {
stateNameChanged: false,
stateParametersChanged: true,
nameBefore: 'app.main',
nameAfter: 'app.main'
}]
compareAllElements(t, expected, compare('app.main', { main1: 'nothing' }, 'app.main', { main1: 'nothing', routeParam: 'something-new' }))
compareAllElements(t, expected, compare('app.main', { routeParam: 'something' }, 'app.main', { routeParam: 'something-new' }))
t.end()
})
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