node_modules/@rest-hooks/core/lib/react-integration/provider/CacheProvider.js
/** Controller managing state of the REST cache and coordinating network requests. */
Controller managing state of the REST cache and coordinating network requests.
Controller managing state of the REST cache and coordinating network requests .
function CacheProvider({
  children,
  managers,
  initialState
}) {
  const denormalizeCache = useRef({
    entities: {},
    results: {}
  });
  const [state, dispatch] = useEnhancedReducer(masterReducer, initialState, managers.map(manager => manager.getMiddleware()));
  const optimisticState = useMemo(() => state.optimistic.reduce(masterReducer, state), [state]); 
  useEffect(() => {
    for (let i = 0; i < managers.length; ++i) {
      var _managers$i$init, _managers$i;
      (_managers$i$init = (_managers$i = managers[i]).init) === null || _managers$i$init === void 0 ? void 0 : _managers$i$init.call(_managers$i, state);
    }
    return () => {
      for (let i = 0; i < managers.length; ++i) {
        managers[i].cleanup();
      }
    }; 
  }, managers);
  return _jsx(DispatchContext.Provider, {
    value: dispatch
  }, void 0, _jsx(StateContext.Provider, {
    value: optimisticState
  }, void 0, _jsx(DenormalizeCacheContext.Provider, {
    value: denormalizeCache.current
  }, void 0, children)));
}
function CacheProvider ( { children , managers , initialState } ) { const denormalizeCache = useRef ( { entities : { } , results : { } } ) ; const [ state , dispatch ] = useEnhancedReducer ( masterReducer , initialState , managers . map ( manager => manager . getMiddleware ( ) ) ) ; const optimisticState = useMemo ( ( ) => state . optimistic . reduce ( masterReducer , state ) , [ state ] ) ; useEffect ( ( ) => { for ( let i = 0 ; i < managers . length ; ++ i ) { var _managers$i$init , _managers$i ; ( _managers$i$init = ( _managers$i = managers [ i ] ) . init ) === null || _managers$i$init === void 0 ? void 0 : _managers$i$init . call ( _managers$i , state ) ; } return ( ) => { for ( let i = 0 ; i < managers . length ; ++ i ) { managers [ i ] . cleanup ( ) ; } } ; } , managers ) ; return _jsx ( DispatchContext . Provider , { value : dispatch } , void 0 , _jsx ( StateContext . Provider , { value : optimisticState } , void 0 , _jsx ( DenormalizeCacheContext . Provider , { value : denormalizeCache . current } , void 0 , children ) ) ) ; }
Controller managing state of the REST cache and coordinating network requests.
Controller managing state of the REST cache and coordinating network requests .
// if we change out the manager we need to make sure it has no hanging async // eslint-disable-next-line react-hooks/exhaustive-deps /*#__PURE__*/ /*#__PURE__*/ /*#__PURE__*/