Skip to content

Commit 774a6aa

Browse files
Swordsman-Inactionaksonov
authored andcommitted
Feature(multiple pop): now we can pop multipe scenes with Actions.pop (#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)
1 parent b58d21c commit 774a6aa

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/Reducer.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,33 @@ function inject(state, action, props, scenes) {
7070
}
7171

7272
case POP_ACTION2:
73-
case POP_ACTION:
73+
case POP_ACTION: {
7474
assert(!state.tabs, 'pop() operation cannot be run on tab bar (tabs=true)');
7575
if (state.index === 0) {
7676
return state;
7777
}
7878

79+
let popNum = 1;
80+
if (action.popNum) {
81+
assert(typeof(action.popNum) === 'number',
82+
'The data is the number of scenes you want to pop, it must be Number');
83+
popNum = action.popNum;
84+
assert(popNum % 1 === 0,
85+
'The data is the number of scenes you want to pop, it must be integer.');
86+
assert(popNum > 1,
87+
'The data is the number of scenes you want to pop, it must be bigger than 1.');
88+
assert(popNum <= state.index,
89+
'The data is the number of scenes you want to pop, ' +
90+
"it must be smaller than scenes stack's length.");
91+
}
92+
7993
return {
8094
...state,
81-
index: state.index - 1,
82-
from: state.children[state.children.length - 1],
83-
children: state.children.slice(0, - 1),
95+
index: state.index - popNum,
96+
from: state.children[state.children.length - popNum],
97+
children: state.children.slice(0, -1 * popNum),
8498
};
99+
}
85100
case REFRESH_ACTION:
86101
return props.base ?
87102
{ navBar: state.navBar,

0 commit comments

Comments
 (0)