Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature(multiple pop): now we can pop multipe scenes with Actions.pop #806

Merged
merged 6 commits into from
Jun 15, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/Reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,21 @@ function inject(state, action, props, scenes) {
if (state.index === 0) {
return state;
}

let popNum = 1
if (action.data) {
assert(typeof(action.data) === 'number', 'The data is the number of scenes you want to pop, it must be Number')
popNum = action.data
assert(popNum % 1 === 0, 'The data is the number of scenes you want to pop, it must be integer.')
assert(popNum > 1, 'The data is the number of scenes you want to pop, it must be bigger than 1.')
assert(popNum < state.children.length, "The data is the number of scenes you want to pop, it must be smaller than scenes stack's length.")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably you need to check against state.index, not state.children.length...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aksonov changed

}

return {
...state,
index: state.index - 1,
from: state.children[state.children.length - 1],
children: state.children.slice(0, -1),
index: state.index - popNum,
from: state.children[state.children.length - popNum],
children: state.children.slice(0, -1 * popNum),
};
case REFRESH_ACTION:
return props.base ?
Expand Down