(state, action)
| 100 | } |
| 101 | |
| 102 | const reducer = (state, action) => { |
| 103 | switch (action.type) { |
| 104 | case 'set': |
| 105 | action.loaders.forEach(({ id, key }) => { |
| 106 | state[key].add(id) |
| 107 | }) |
| 108 | |
| 109 | return { ...state } |
| 110 | case 'clear': |
| 111 | action.loaders.forEach(({ id, key }) => { |
| 112 | state[key].delete(id) |
| 113 | }) |
| 114 | |
| 115 | return { ...state } |
| 116 | default: |
| 117 | throw new Error(`Unexpected action: ${action.type}`) |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | export const LoadingProvider = ({ children }) => { |
| 122 | const [state, dispatch] = useReducer(reducer, { |
nothing calls this directly
no outgoing calls
no test coverage detected