Skip to content

Commit

Permalink
Feature(multiple pop): now we can pop multipe scenes with Actions.pop (
Browse files Browse the repository at this point in the history
…#806)

* Feature(multiple pop): now we can pop multipe scenes with Actions.pop([number]), like Actions.pop(2)

* Fix(format)

* Fix(data check, format): compare data with index, add semicolon

* -Fix(format)

* Fix(format)
  • Loading branch information
Swordsman-Inaction authored and aksonov committed Jun 15, 2016
1 parent b58d21c commit 774a6aa
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/Reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,33 @@ function inject(state, action, props, scenes) {
}

case POP_ACTION2:
case POP_ACTION:
case POP_ACTION: {
assert(!state.tabs, 'pop() operation cannot be run on tab bar (tabs=true)');
if (state.index === 0) {
return state;
}

let popNum = 1;
if (action.popNum) {
assert(typeof(action.popNum) === 'number',
'The data is the number of scenes you want to pop, it must be Number');
popNum = action.popNum;
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.index,
'The data is the number of scenes you want to pop, ' +
"it must be smaller than scenes stack's length.");
}

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 ?
{ navBar: state.navBar,
Expand Down

0 comments on commit 774a6aa

Please sign in to comment.