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AI,EAAO,OACT,IACE,EAAe,EAAO,QAAQ,EAAO,MAAM,EAAM,EAAO,QAAS,EACnE,CAAE,MAAM,GAAQ,MAGhB,IAAK,IAAK,CAAE,KAAa,EACc,mBAA1B,EAAS,EAAO,OACzB,EAAS,EAAO,MAAM,EAAO,EACnC,WAIK,MAAM,WAAa,IAAI,IAAU,OAAO,KAAK,IAAI,SAAS,WAE1D,MAAM,MAAQ,CAAC,EAAS,EAAO,IACpC,OAAO,KACL,IAAI,KAAI,EAAE,EAAO,KACO,IAAjB,EAAM,SAAgB,EAAM,SAAS,EAAO,OAAU,EAAO,MAC1C,IAAnB,EAAQ,SAAgB,EAAQ,SAAS,EAAO,SAAY,EAAO,OAI/D,MAHP,EAAO,UAAY,EAAO,WAAa,MAAO,GACvC,EAAE,EAAO,IAAW,SAK/B,WAAU,GAAG,GAAK,QAAQ,KAAK","file":"/npm/@t-wilkinson/rxjs-redux-store@1.0.9/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@t-wilkinson/rxjs-redux-store@1.0.9/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","import produce, {enableES5, enableMapSet} from \"immer\"\nimport React from \"react\"\nimport * as rxjs from \"rxjs\"\nimport * as ops from \"rxjs/operators\"\n\nenableES5()\nenableMapSet()\n\n/*\n   action$ serves as the main handler for events.\n   after these are run, the updated state are then sent to async$ handlers.\n*/\nexport const action$ = new rxjs.Subject()\nexport const async$ = new rxjs.Subject()\nexport const dispatch = (action) => action$.next(action)\n\nexport const createStore = (slice) => {\n  let slices = makeSlices(slice)\n  slices.reducers = mergeReducers(slices.reducers)\n\n  const Context = React.createContext(slices.states)\n  const Provider = Context.Provider\n  const useStore = (f) => f(React.useContext(Context))\n\n  const subscribe = (f) => action$.pipe(\n    ops.startWith(slices.states), // init state\n    ops.scan(slices.reducers), // reducer\n  ).subscribe((state) => f(state, Context))\n\n  return [Provider, useStore, subscribe, slices.actions]\n}\n\nconst makeSlices = (slice) => {\n  let slices = { reducers: {}, states: {}, actions: {} }\n  for (let [name, {initialState, reducers}] of Object.entries(slice)) {\n    // init state\n    if (typeof initialState === \"function\")\n      slices.states[name] = initialState()\n    else slices.states[name] = initialState\n    slices.reducers[name] = reducers\n    slices.actions[name] = {}\n\n    // Create action functions based on given slices\n    for (let [reducer_name] of Object.entries(reducers)) {\n      slices.actions[name][reducer_name] = (action={}) => dispatch(({filter: name, type: reducer_name, ...action}))\n    }\n  }\n  return slices\n}\n\nconst mergeReducers = (reducerEntries) =>  {\n  let entries = Object.entries(reducerEntries)\n  return (oldState, action) => {\n    let newState = updateState(reducerEntries, entries, action, oldState)\n    // let javascript reflow before triggering async$\n    setTimeout(() => async$.next([newState, action]), 0)\n    return newState\n  }\n}\n\nconst updateState = (reducerEntries, entries, action, oldState) => produce(oldState, (state) => {\n  if (action.filter) {\n    try { // too many potential errors to check. Move on if error\n      reducerEntries[action.filter][action.type](state[action.filter], action)\n    } catch(error) {}\n  }\n  else {\n    for (let [, reducers] of entries)\n      if (typeof reducers[action.type] === \"function\")\n        reducers[action.type](state, action)\n  }\n})\n\n// Listen to '$action.next()' and pipe stream to function\nexport const mergeEpics = (...epics) => async$.pipe(ops.merge(...epics))\n\nexport const ofMap = (filters, types, f) =>\n  async$.pipe(\n    ops.map(([state, action]) => {\n      if ((types.length === 0 || types.includes(action.type) || !action.type)\n       && (filters.length === 0 || filters.includes(action.filter) || !action.filter)) {\n        action.onSuccess = action.onSuccess || (()=>{})\n        return f(state, action) || null\n      } else {\n        return null\n      }\n    })\n  ).subscribe(v=>v && action$.next(v))\n\n// // Listen to '$action.next()' and pipe stream to function\n// export const epic = (...fs) => async$.pipe(...fs).subscribe(v => v && action$.next(v))\n// export const mergeEpics = (...epics) => async$.pipe(ops.merge(...epics))\n// export const ofMap = (filters, types, f) =>\n//   epic(\n//     ops.map(([state, action]) => {\n//       if ((types.length === 0 || types.includes(action.type) || !action.type) &&\n//         (filters.length === 0 || filters.includes(action.filter) || !action.filter))\n//         return f(state, action) || null\n//       return null\n//     })\n//   )\n"]}