(partial, replace)
| 5 | const listeners = new Set(); |
| 6 | |
| 7 | const setState = (partial, replace) => { |
| 8 | const nextState = typeof partial === 'function' ? partial(state) : partial |
| 9 | |
| 10 | if (!Object.is(nextState, state)) { |
| 11 | const previousState = state; |
| 12 | |
| 13 | if(!replace) { |
| 14 | state = (typeof nextState !== 'object' || nextState === null) |
| 15 | ? nextState |
| 16 | : Object.assign({}, state, nextState); |
| 17 | } else { |
| 18 | state = nextState; |
| 19 | } |
| 20 | listeners.forEach((listener) => listener(state, previousState)); |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | const getState = () => state; |
| 25 |
nothing calls this directly
no outgoing calls
no test coverage detected