| 79 | } |
| 80 | |
| 81 | export class Ikari<State> { |
| 82 | static createAndBindAt<S>(target: Ayanami<S>, config: Config<S>): Ikari<S> { |
| 83 | const createdIkari = this.getFrom(target) |
| 84 | |
| 85 | if (createdIkari) { |
| 86 | return createdIkari |
| 87 | } else { |
| 88 | const ikari = new Ikari(target, config) |
| 89 | Reflect.defineMetadata(ikariSymbol, ikari, target) |
| 90 | return ikari |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | static getFrom<S>(target: { defaultState: S }): Ikari<S> | undefined { |
| 95 | return Reflect.getMetadata(ikariSymbol, target) |
| 96 | } |
| 97 | |
| 98 | state = createState(this.config.defaultState) |
| 99 | |
| 100 | effectActionFactories = this.config.effectActionFactories |
| 101 | |
| 102 | triggerActions: TriggerActions = {} |
| 103 | |
| 104 | subscription = new Subscription() |
| 105 | |
| 106 | // @internal |
| 107 | terminate$ = new Subject<typeof TERMINATE_ACTION | null>() |
| 108 | |
| 109 | // eslint-disable-next-line @typescript-eslint/explicit-member-accessibility |
| 110 | constructor(readonly ayanami: Ayanami<State>, private readonly config: Readonly<Config<State>>) { |
| 111 | const [effectActions$, effectActions] = setupEffectActions( |
| 112 | this.config.effects, |
| 113 | this.state.state$, |
| 114 | ) |
| 115 | |
| 116 | const [reducerActions$, reducerActions] = setupReducerActions( |
| 117 | this.config.reducers, |
| 118 | this.state.getState, |
| 119 | ) |
| 120 | |
| 121 | const [immerReducerActions$, immerReducerActions] = setupImmerReducerActions( |
| 122 | this.config.immerReducers, |
| 123 | this.state.getState, |
| 124 | ) |
| 125 | |
| 126 | this.triggerActions = { |
| 127 | ...effectActions, |
| 128 | ...reducerActions, |
| 129 | ...immerReducerActions, |
| 130 | ...mapValues(this.config.defineActions, ({ next }) => next), |
| 131 | } |
| 132 | |
| 133 | let effectActionsWithTerminate$: Observable<Action<any>> |
| 134 | |
| 135 | if (!isSSREnabled()) { |
| 136 | effectActionsWithTerminate$ = effectActions$ |
| 137 | } else { |
| 138 | effectActionsWithTerminate$ = effectActions$.pipe( |
nothing calls this directly
no test coverage detected