| 339 | }); |
| 340 | }, |
| 341 | moveBefore(key: Key, keys: Iterable<Key>) { |
| 342 | dispatch(state => { |
| 343 | let toIndex = state.items.findIndex(item => getKey!(item) === key); |
| 344 | if (toIndex === -1) { |
| 345 | return state; |
| 346 | } |
| 347 | |
| 348 | // Find indices of keys to move. Sort them so that the order in the list is retained. |
| 349 | let keyArray = Array.isArray(keys) ? keys : [...keys]; |
| 350 | let indices = keyArray |
| 351 | .map(key => state.items.findIndex(item => getKey!(item) === key)) |
| 352 | .sort((a, b) => a - b); |
| 353 | return move(state, indices, toIndex); |
| 354 | }); |
| 355 | }, |
| 356 | moveAfter(key: Key, keys: Iterable<Key>) { |
| 357 | dispatch(state => { |
| 358 | let toIndex = state.items.findIndex(item => getKey!(item) === key); |