UNPKG

abstract-state-router

Version:

The basics of a client-side state router ala the AngularJS ui-router, but without any DOM interactions

30 lines (24 loc) 672 B
module.exports = function stateChangeLogic(stateComparisonResults) { var hitChangingState = false var hitDestroyedState = false var output = { destroy: [], change: [], create: [] } stateComparisonResults.forEach(function(state) { hitChangingState = hitChangingState || state.stateParametersChanged hitDestroyedState = hitDestroyedState || state.stateNameChanged if (state.nameBefore) { if (hitDestroyedState) { output.destroy.push(state.nameBefore) } else if (hitChangingState) { output.change.push(state.nameBefore) } } if (state.nameAfter && hitDestroyedState) { output.create.push(state.nameAfter) } }) return output }