* Resets all routes. * Note that this moves the index to the position to where the last route in the * stack is at if the param `index` isn't provided.
(state, routes, index)
| 178 | * stack is at if the param `index` isn't provided. |
| 179 | */ |
| 180 | reset(state, routes, index) { |
| 181 | invariant( |
| 182 | routes.length && Array.isArray(routes), |
| 183 | 'invalid routes to replace' |
| 184 | ); |
| 185 | |
| 186 | const nextIndex = index === undefined ? routes.length - 1 : index; |
| 187 | |
| 188 | if (state.routes.length === routes.length && state.index === nextIndex) { |
| 189 | const compare = (route, ii) => routes[ii] === route; |
| 190 | if (state.routes.every(compare)) { |
| 191 | return state; |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | invariant(!!routes[nextIndex], 'invalid index %s to reset', nextIndex); |
| 196 | |
| 197 | return { |
| 198 | ...state, |
| 199 | index: nextIndex, |
| 200 | routes, |
| 201 | }; |
| 202 | }, |
| 203 | }; |
| 204 | |
| 205 | export default StateUtils; |
nothing calls this directly
no test coverage detected
searching dependent graphs…