ngrx-immer
Version:
Immer wrappers around NgRx methods createReducer, on, and ComponentStore
1 lines • 1.94 kB
Source Map (JSON)
{"version":3,"file":"ngrx-immer-store.mjs","sources":["../../src/store/index.ts","../../src/store/ngrx-immer-store.ts"],"sourcesContent":["import {\n\tAction,\n\tReducerTypes,\n\tActionReducer,\n\tcreateReducer,\n\tActionCreator,\n\tActionType,\n\ton,\n} from '@ngrx/store';\nimport { Draft } from 'immer';\n\nimport { immerReducer } from 'ngrx-immer/shared';\n\n/**\n * An immer reducer that allows a void return\n */\nexport interface ImmerOnReducer<State, AC extends ActionCreator[]> {\n\t(state: Draft<State>, action: ActionType<AC[number]>): void;\n}\n\n/**\n * Immer wrapper around `on` to mutate state\n */\nexport function immerOn<State, Creators extends ActionCreator[]>(\n\t...args: [...creators: Creators, reducer: ImmerOnReducer<State extends infer S ? S : never, Creators>]\n): ReducerTypes<State, Creators> {\n\tconst reducer = (args.pop() as Function) as ActionReducer<State>;\n\treturn (on as any)(...(args as ActionCreator[]), immerReducer(reducer));\n}\n\n/**\n * Immer wrapper around `createReducer` to mutate state\n */\nexport function createImmerReducer<State, A extends Action = Action>(\n\tinitialState: State,\n\t...ons: ReducerTypes<State, any>[]\n): ActionReducer<State, A> {\n\tconst reducer = createReducer(initialState, ...ons);\n\treturn function reduce(state: State = initialState, action: A) {\n\t\treturn immerReducer<State, A>(reducer)(state, action);\n\t};\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;AAoBA;;AAEG;AACG,SAAU,OAAO,CACtB,GAAG,IAAmG,EAAA;AAEtG,IAAA,MAAM,OAAO,GAAI,IAAI,CAAC,GAAG,EAAuC;IAChE,OAAQ,EAAU,CAAC,GAAI,IAAwB,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC;AACxE;AAEA;;AAEG;SACa,kBAAkB,CACjC,YAAmB,EACnB,GAAG,GAA+B,EAAA;IAElC,MAAM,OAAO,GAAG,aAAa,CAAC,YAAY,EAAE,GAAG,GAAG,CAAC;AACnD,IAAA,OAAO,SAAS,MAAM,CAAC,KAAA,GAAe,YAAY,EAAE,MAAS,EAAA;QAC5D,OAAO,YAAY,CAAW,OAAO,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC;AACtD,IAAA,CAAC;AACF;;ACzCA;;AAEG;;;;"}