Comments (3)
This might be a difficult bug to fix in sticky-states.
here's a workaround for now: http://plnkr.co/edit/998o5W3o3yLqbkykJFy2?p=preview
from sticky-states.
Hi, I've tried to solve this bug without making any internal code changes and came up with the following solution. This only attempts to solve TypeError: Cannot read property 'reduce' of undefined
that was triggered by adding an onExit hook to one or more of your sticky states.
` $transitions.onStart({}, function(transition) {
var hasStickyInPath = (path) => _.any(path, parentsOrSelf => parentsOrSelf.sticky);
var leavingStickyStates = _.filter(transition._treeChanges.exiting, path => path.state && hasStickyInPath(path.state.path));
var isLeavingNonStickyState = _.difference(transition._treeChanges.exiting, leavingStickyStates).length;
//Only fires when exiting a sticky state or a child of a sticky state (probably entering another child of sticky state) WHILE ALSO exiting an active non-sticky state
if(isLeavingNonStickyState && leavingStickyStates.length) {
//Don't exit from root sticky states, since they're sticky!
var removeStickyStatesFromExiting = transition._treeChanges.exiting.filter(path => !path.state.sticky);
transition._treeChanges.exiting = removeStickyStatesFromExiting;
//Add the sticky child's paths to _treeChanges.from in order to resolve its path and its resolves from the transition hooks. (This is technically the issue, the transition hooks have no idea we're going FROM this state TO the next even though it's present in EXITING)
var stickyChildPath = _.find(leavingStickyStates, path => !path.state.sticky);
//path.views[0].path has resolvable PathNodes unlike path.state.path, needed to resolve resolvables
//TODO: handle multiple views
var stickyChildAndParentsPath = stickyChildPath && stickyChildPath.views && stickyChildPath.views.length && stickyChildPath.views[0] && stickyChildPath.views[0].path;
var addStickyChildAndParentsPathToPath = transition._treeChanges.from.concat(stickyChildAndParentsPath || []);
var removeDuplicatePaths = _.pluck(_.groupBy(addStickyChildAndParentsPathToPath, (path) => path.state.name), 0);
transition._treeChanges.from = removeDuplicatePaths;
}
})`
Basically, when exiting both a sticky state and non-sticky state, such as when navigating from one sticky child to another and deactivating a non-sticky state in the process, we have to:
- stop the root sticky states from being exited, since they're sticky. (otherwise, it adds the root sticky state to treeChanges.exiting if there's an onExit on the child sticky state and can't transition)
- notify the transition that we're transitioning FROM the child sticky state's path. (otherwise, it can't resolve the child sticky state's path or local resolves in the main transition hook, causing the
TypeError: Cannot read property 'reduce' of undefined
)
2a. make sure the paths added to FROM have resolvables, in case the transition hooks have dependencies. This is whypath.views[0].path
is used instead ofpath.state.path
.
from sticky-states.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
This does not mean that the issue is invalid. Valid issues may be reopened.
Thank you for your contributions.
from sticky-states.
Related Issues (20)
- OnRetain not called
- Sticky state resetting issue HOT 2
- Stuck sticky states HOT 1
- exitSticky typings issue HOT 1
- UI-router uiOnParamsChanged event is not triggered when StickyStatesPlugin is enabled HOT 3
- toggle show sub-views like TAB behavior
- Trouble using angularjs + npm + scripts solution HOT 1
- Action required: Greenkeeper could not be activated 🚨
- Action required: Greenkeeper could not be activated 🚨
- How to setup "sticky-states" with views HOT 11
- Using sticky-states, the destruction function is not triggered when the page is refreshed HOT 1
- Error with sticky-states and chromium 40 HOT 2
- Sticky States v1.5.0 throws error in IE 11 (Object doesn't support property or method 'find') HOT 2
- Check to see if sticky state is loaded? HOT 2
- Import required even when `exitSticky` property (on `TransitionOptions`) needs to be used. HOT 1
- Load sticky state if non-sticky state was loaded from server HOT 1
- Not able to navigate back HOT 1
- How to deactivate existing sticky state HOT 1
- How to use pamas in sticky state HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sticky-states.