| 12 | }; |
| 13 | |
| 14 | export default function loading( |
| 15 | state: LoadingState = {}, |
| 16 | action: LoadingAction |
| 17 | ) { |
| 18 | switch (action.type) { |
| 19 | case 'LOADED': |
| 20 | return action.payload.reduce((acc, load) => { |
| 21 | const loadPath = [JSON.stringify(load.path)]; |
| 22 | const prev = pathOr<any>([], loadPath, acc); |
| 23 | return assocPath( |
| 24 | loadPath, |
| 25 | prev.filter( |
| 26 | (loading: any) => loading.property !== load.property |
| 27 | ), |
| 28 | acc |
| 29 | ); |
| 30 | }, state); |
| 31 | case 'LOADING': |
| 32 | return action.payload.reduce((acc, load) => { |
| 33 | const loadPath = [JSON.stringify(load.path)]; |
| 34 | const prev = pathOr<any>([], loadPath, acc); |
| 35 | if (!includes(load, prev)) { |
| 36 | // duplicate outputs |
| 37 | prev.push(load); |
| 38 | } |
| 39 | return assocPath(loadPath, prev, acc); |
| 40 | }, state); |
| 41 | default: |
| 42 | return state; |
| 43 | } |
| 44 | } |