abstract-state-router
Advanced tools
Comparing version 7.2.0 to 7.3.0
@@ -195,3 +195,2 @@ 'use strict'; | ||
var stateChangeLogic$1 = function stateChangeLogic(stateComparisonResults) { | ||
let hitChangingState = false; | ||
let hitDestroyedState = false; | ||
@@ -201,3 +200,2 @@ | ||
destroy: [], | ||
change: [], | ||
create: [], | ||
@@ -207,11 +205,6 @@ }; | ||
stateComparisonResults.forEach(state => { | ||
hitChangingState = hitChangingState || state.stateParametersChanged; | ||
hitDestroyedState = hitDestroyedState || state.stateNameChanged; | ||
hitDestroyedState = hitDestroyedState || state.stateNameChanged || state.stateParametersChanged; | ||
if (state.nameBefore) { | ||
if (hitDestroyedState) { | ||
output.destroy.push(state.nameBefore); | ||
} else if (hitChangingState) { | ||
output.change.push(state.nameBefore); | ||
} | ||
if (state.nameBefore && hitDestroyedState) { | ||
output.destroy.push(state.nameBefore); | ||
} | ||
@@ -340,3 +333,2 @@ | ||
let renderDom = null; | ||
let resetDom = null; | ||
@@ -377,36 +369,2 @@ let activeStateResolveContent = {}; | ||
function resetStateName(parameters, stateName) { | ||
const domApi = activeDomApis[stateName]; | ||
const content = getContentObject(activeStateResolveContent, stateName); | ||
const state = prototypalStateHolder.get(stateName); | ||
stateProviderEmitter.emit(`beforeResetState`, { | ||
domApi, | ||
content, | ||
state, | ||
parameters, | ||
}); | ||
activeEmitters[stateName].emit(`destroy`); | ||
delete activeEmitters[stateName]; | ||
return resetDom({ | ||
domApi, | ||
content, | ||
template: state.template, | ||
parameters, | ||
}).then(newDomApi => { | ||
if (newDomApi) { | ||
activeDomApis[stateName] = newDomApi; | ||
} | ||
stateProviderEmitter.emit(`afterResetState`, { | ||
domApi: activeDomApis[stateName], | ||
content, | ||
state, | ||
parameters, | ||
}); | ||
}) | ||
} | ||
function getChildElementForStateName(stateName) { | ||
@@ -417,3 +375,5 @@ return new Promise(resolve => { | ||
resolve(getDomChild(activeDomApis[parent.name]).then(childDomApi => { | ||
if (!childDomApi) return Promise.reject(new Error(`getDomChild returned a falsey element, did you forget to add a place for a child state to go?`)) | ||
if (!childDomApi) { | ||
return Promise.reject(new Error(`getDomChild returned a falsey element, did you forget to add a place for a child state to go?`)) | ||
} | ||
return childDomApi | ||
@@ -515,3 +475,3 @@ })); | ||
function getStatesToResolve(stateChanges) { | ||
return stateChanges.change.concat(stateChanges.create).map(prototypalStateHolder.get) | ||
return stateChanges.create.map(prototypalStateHolder.get) | ||
} | ||
@@ -570,3 +530,3 @@ | ||
const activateAll = () => activateStates( | ||
stateChanges.change.concat(stateChanges.create), | ||
stateChanges.create, | ||
); | ||
@@ -576,6 +536,3 @@ | ||
return series(reverse(stateChanges.destroy), destroyStateName).then(() => series( | ||
reverse(stateChanges.change), | ||
stateName => resetStateName(extend(parameters), stateName), | ||
)).then( | ||
return series(reverse(stateChanges.destroy), destroyStateName).then( | ||
() => renderAll(stateChanges.create, extend(parameters)).then(activateAll), | ||
@@ -679,3 +636,2 @@ ) | ||
renderDom = denodeify(renderer.render); | ||
resetDom = denodeify(renderer.reset); | ||
@@ -682,0 +638,0 @@ return stateProviderEmitter |
{ | ||
"name": "abstract-state-router", | ||
"version": "7.2.0", | ||
"version": "7.3.0", | ||
"description": "Like ui-router, but without all the Angular. The best way to structure a single-page webapp.", | ||
@@ -5,0 +5,0 @@ "main": "bundle.js", |
@@ -80,3 +80,3 @@ **[Changelog](./changelog.md) • [Join the chat on Discord](https://discord.gg/G8FrErC) • [API documentation](#api)** | ||
The `makeRenderer` should be a function that returns an object with four properties: render, destroy, getChildElement, and reset. Documentation is [here](https://github.com/TehShrike/abstract-state-router/blob/master/renderer.md) - see [test/support/renderer-mock.js](https://github.com/TehShrike/abstract-state-router/blob/master/test/helpers/renderer-mock.js) for an example implementation. | ||
The `makeRenderer` should be a function that returns an object with these properties: render, destroy, and getChildElement. Documentation is [here](https://github.com/TehShrike/abstract-state-router/blob/master/renderer.md) - see [test/support/renderer-mock.js](https://github.com/TehShrike/abstract-state-router/blob/master/test/helpers/renderer-mock.js) for an example implementation. | ||
@@ -184,9 +184,6 @@ The `rootElement` is the element where the first-generation states will be created. | ||
defaultChild: 'tab1', | ||
resolve: function(data, parameters, cb) { | ||
// Sync or async stuff; just call the callback when you're done | ||
isLoggedIn(function(err, isLoggedIn) { | ||
cb(err, isLoggedIn) | ||
}) | ||
async resolve(data, parameters) { | ||
return isLoggedIn() | ||
}, | ||
activate: function(context) { | ||
activate(context) { | ||
// Normally, you would set data in your favorite view library | ||
@@ -204,6 +201,6 @@ var isLoggedIn = context.content | ||
template: '', | ||
resolve: function(data, parameters, cb) { | ||
getTab1Data(cb) | ||
async resolve(data, parameters) { | ||
return getTab1Data() | ||
}, | ||
activate: function(context) { | ||
activate(context) { | ||
document.getElementById('tab').innerText = context.content | ||
@@ -226,6 +223,6 @@ | ||
template: '', | ||
resolve: function(data, parameters, cb) { | ||
getTab2Data(cb) | ||
async resolve(data, parameters) { | ||
return getTab2Data() | ||
}, | ||
activate: function(context) { | ||
activate(context) { | ||
document.getElementById('tab').innerText = context.content | ||
@@ -324,4 +321,2 @@ } | ||
- `afterCreateState({state, domApi, content, parameters})` | ||
- `beforeResetState({state, domApi, content, parameters})` | ||
- `afterResetState({state, domApi, content, parameters})` | ||
- `beforeDestroyState({state, domApi})` | ||
@@ -344,5 +339,4 @@ - `afterDestroyState({state})` | ||
- **NO LONGER AT PREVIOUS STATE** | ||
- destroy the contexts of all "destroy" and "change" states | ||
- destroy the contexts of all "destroy" states | ||
- destroy appropriate dom elements | ||
- reset "change"ing dom elements | ||
- call render functions for "create"ed states | ||
@@ -355,3 +349,2 @@ - call all activate functions | ||
- destroy: states that are no longer active at all. The contexts are destroyed, and the DOM elements are destroyed. | ||
- change: states that remain around, but with different parameter values - the DOM sticks around, but the contexts are destroyed and resolve/activate are called again. | ||
- create: states that weren't active at all before. The DOM elements are rendered, and resolve/activate are called. | ||
@@ -402,3 +395,3 @@ | ||
If anyone else has need of this functionality and wants to get keep making progress on it, I'd be happy to help. Stop by the [chat room](https://gitter.im/TehShrike/abstract-state-router) to ask any questions. | ||
If anyone else has need of this functionality and wants to get keep making progress on it, I'd be happy to help. Stop by the [chat room](https://discord.gg/G8FrErC) to ask any questions. | ||
@@ -405,0 +398,0 @@ # Maintainers |
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
86312
557
398