{"version":3,"file":"index.cjs","names":[],"sources":["../src/lib/action/action-config.interface.ts","../src/lib/action/action-packet.interface.ts","../src/lib/helper/comparator.function.ts","../src/lib/helper/consts.ts","../src/lib/helper/entity-slice-reducer.function.ts","../src/lib/helper/has-key.function.ts","../src/lib/helper/if-latest-from.function.ts","../src/lib/helper/keyer.function.ts","../src/lib/helper/non-nullable.function.ts","../src/lib/helper/update-object.function.ts","../src/lib/action/action.class.ts","../src/lib/store/reducer.type.ts","../src/lib/store/slice.class.ts","../src/lib/store/scope.class.ts"],"sourcesContent":["import type { Observable } from 'rxjs';\n\nexport interface ActionConfig {\n\t/**\n\t * Defining this adds a throttleTime operator to the actions dispatcher\n\t * pipeline with start and end emits enabled. You will always get the first\n\t * and the last emit of a throttled timeframe if there is one.\n\t *\n\t * ```ts\n\t * \tthrottleTime(this.config.throttleTime, asyncScheduler, {\n\t * \t\t\tleading: true,\n\t * \t\t\ttrailing: true,\n\t * \t)\n\t * ```\n\t */\n\tthrottleTime?: number | undefined;\n\tpauseWhile?: Observable<boolean> | undefined;\n}\n\nexport const DEFAULT_ACTION_CONFIG: ActionConfig = {\n\tthrottleTime: undefined,\n};\n","import { isNotNullish } from '@alexaegis/common';\nimport type { Action } from './action.class.js';\n\nexport interface ActionPacket<Payload = unknown> {\n\ttype: string;\n\tpayload: Payload;\n}\n\nexport type ActionPacketTuple<T> = {\n\t[K in keyof T]: ActionPacket<T[K]>;\n};\n\nexport const isActionPacket = <P>(\n\tactionPacket?: unknown,\n\tregisteredInActionMap?: Map<string, Action<unknown>>,\n): actionPacket is ActionPacket<P> => {\n\treturn (\n\t\tactionPacket !== undefined &&\n\t\tisNotNullish((actionPacket as ActionPacket).type) &&\n\t\t(registeredInActionMap?.has((actionPacket as ActionPacket).type) ?? true)\n\t);\n};\n","export type Comparator<T> = (a: T, b: T) => boolean;\n\nexport const includesArrayComparator = <T>(prev: T[], next: T[]) =>\n\tprev.every((slice) => next.includes(slice));\n\nexport const fastArrayComparator = <T>(prev: T[], next: T[]) => {\n\tif (prev.length !== next.length) {\n\t\treturn false;\n\t} else if (next.length === 0) {\n\t\treturn true;\n\t} else {\n\t\tfor (let i = 0; i <= next.length; i++) {\n\t\t\tif (prev[i] !== next[i]) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n};\n","export const TINYSLICE_PREFIX = '[TinySlice]';\nexport const TINYSLICE_INTERNAL_PREFIX = `${TINYSLICE_PREFIX} [Internal]`;\nexport const TINYSLICE_DEFAULT_PREFIX = `${TINYSLICE_PREFIX} [Default]`;\n","import type { ActionReducer } from '../store/index.js';\n\nexport const entitySliceReducerWithPrecompute = <\n\tState extends Record<Key, Entity>,\n\tKey extends keyof State,\n\tEntity extends State[Key],\n\tPayload,\n\tPrecomputed,\n>(\n\tprecompute: (state: State, payload: Payload) => Precomputed,\n\tentityReducer: (\n\t\tkey: Key,\n\t\tentity: Entity,\n\t\tpayload: Payload,\n\t\tprecomputed: Precomputed,\n\t) => Entity | undefined,\n): ActionReducer<State, Payload> => {\n\treturn (state, payload) => {\n\t\tconst precomputed = precompute(state, payload);\n\t\t// todo use mapRecord\n\t\t// const b = Object.fromEntries<Entity>(\n\t\t// \t(Object.entries<Entity>(state) as [Key, Entity][]).map<[Key, Entity]>(([key, tile]) => {\n\t\t// \t\treturn [key, entityReducer(key, tile, payload, precomputed) ?? tile];\n\t\t// \t})\n\t\t// );\n\t\t// return b as State;\n\t\treturn (Object.entries<Entity>(state) as [Key, Entity][]).reduce<State>(\n\t\t\t(acc, [key, tile]) => {\n\t\t\t\tacc[key] = entityReducer(key, tile, payload, precomputed) ?? tile;\n\t\t\t\treturn acc;\n\t\t\t},\n\t\t\t// eslint-disable-next-line @typescript-eslint/prefer-reduce-type-parameter\n\t\t\t{} as State,\n\t\t);\n\t};\n};\n\nexport const entitySliceReducer = <\n\tState extends Record<Key, Entity>,\n\tKey extends keyof State,\n\tEntity extends State[Key],\n\tPayload,\n>(\n\tentityReducer: (key: Key, entity: Entity, payload: Payload) => Entity | undefined,\n): ActionReducer<State, Payload> => {\n\treturn (state, payload) =>\n\t\t(Object.entries<Entity>(state) as [Key, Entity][]).reduce<State>(\n\t\t\t(acc, [key, tile]) => {\n\t\t\t\tacc[key] = entityReducer(key, tile, payload) ?? tile;\n\t\t\t\treturn acc;\n\t\t\t},\n\t\t\t// eslint-disable-next-line @typescript-eslint/prefer-reduce-type-parameter\n\t\t\t{} as State,\n\t\t);\n};\n","import { isNotNullish } from '@alexaegis/common';\n\nexport const hasKey = <T>(parent: T, key: string | number | symbol | undefined): boolean => {\n\treturn (\n\t\tisNotNullish(key) &&\n\t\tisNotNullish(parent) &&\n\t\ttypeof parent === 'object' &&\n\t\tObject.hasOwn(parent, key)\n\t);\n};\n","import {\n\tfilter,\n\tmap,\n\twithLatestFrom,\n\ttype Observable,\n\ttype ObservableInput,\n\ttype OperatorFunction,\n} from 'rxjs';\n\nexport function ifLatestFrom<T, O>(\n\tinput: ObservableInput<O>,\n\tcondition: (inputResult: O, sourceResult: T) => boolean,\n): OperatorFunction<T, T> {\n\treturn (source: Observable<T>) => {\n\t\treturn source.pipe(\n\t\t\twithLatestFrom(input),\n\t\t\tfilter(([sourceResult, inputResult]) => condition(inputResult, sourceResult)),\n\t\t\tmap(([a]) => a),\n\t\t);\n\t};\n}\n","export type GetNext<T> = (keys: T[]) => T;\nexport type GetKeys<T, K> = (state: T) => K[];\n\nexport const getObjectKeys: GetKeys<Record<string | number, unknown>, string> = (\n\tstate: Record<string | number, unknown>,\n): string[] => Object.keys(state);\nexport const getObjectKeysAsNumbers: GetKeys<Record<number, unknown>, number> = (\n\tstate: Record<number, unknown>,\n): number[] => Object.keys(state).map((key) => Number.parseInt(key, 10));\n\nexport const getNextNumberLikeStringKey: GetNext<`${number}`> = (keys: `${number}`[]) =>\n\t(\n\t\tkeys.map((key) => Number.parseInt(key, 10)).reduce((a, b) => (a > b ? a : b), 0) + 1\n\t).toString() as `${number}`;\n\nexport const getNextLargestNumber: GetNext<number> = (keys: number[]): number =>\n\tkeys.reduce((a, b) => (a > b ? a : b), 0) + 1;\n\nexport const getNextSmallestNumber: GetNext<number> = (keys: number[]): number => {\n\tconst sortedKeys = [...keys].sort((a, b) => a - b);\n\n\tfor (let i = 0; i < sortedKeys.length; i++) {\n\t\tif (!sortedKeys.includes(i + 1)) {\n\t\t\treturn i + 1;\n\t\t}\n\t}\n\treturn (sortedKeys.at(-1) ?? 0) + 1;\n};\n\nexport enum PremadeGetNext {\n\tnextLargest = 'nextlargest',\n\tnextSmallest = 'nextsmallest',\n}\n\nexport type NextKeyStrategy = PremadeGetNext | GetNext<number>;\n\nexport const getNextKeyStrategy = (nextKeyStrategy?: NextKeyStrategy): GetNext<number> => {\n\tif (typeof nextKeyStrategy === 'function') {\n\t\treturn nextKeyStrategy;\n\t} else if (nextKeyStrategy === PremadeGetNext.nextLargest) {\n\t\treturn getNextLargestNumber;\n\t} else if (nextKeyStrategy === PremadeGetNext.nextSmallest) {\n\t\treturn getNextSmallestNumber;\n\t} else {\n\t\treturn getNextLargestNumber;\n\t}\n};\n","/**\n * @deprecated use common\n */\nexport const isNonNullable = <T>(o: T | undefined | null): o is NonNullable<T> =>\n\to !== undefined && o !== null;\n\nexport const isNullish = <T>(o: T | undefined | null): o is undefined | null =>\n\to === undefined || o === null;\n","export const updateObject = <T, O extends T>(base: T, other: O | Partial<T>): T => {\n\tif (other !== undefined && other !== null) {\n\t\tif (typeof base === 'object') {\n\t\t\tif (Array.isArray(base)) {\n\t\t\t\tconst copy = [...base];\n\t\t\t\tfor (const [key, value] of (other as unknown[]).entries()) {\n\t\t\t\t\tif (value !== undefined) {\n\t\t\t\t\t\tcopy[key] = value;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn copy as T;\n\t\t\t} else {\n\t\t\t\treturn { ...base, ...other };\n\t\t\t}\n\t\t} else {\n\t\t\treturn other as O;\n\t\t}\n\t} else {\n\t\treturn base;\n\t}\n};\n","import { isNotNullish } from '@alexaegis/common';\nimport {\n\tEMPTY,\n\tObservable,\n\tSubject,\n\tSubscription,\n\tasyncScheduler,\n\tfilter,\n\tthrottleTime,\n\ttype MonoTypeOperatorFunction,\n} from 'rxjs';\nimport { ifLatestFrom } from '../helper/index.js';\nimport type { Scope } from '../store/index.js';\nimport type { ActionReducer, ReducerConfiguration } from '../store/reducer.type.js';\nimport { DEFAULT_ACTION_CONFIG, type ActionConfig } from './action-config.interface.js';\nimport type { ActionPacket } from './action-packet.interface.js';\n\nexport type ActionTuple<T> = {\n\t[K in keyof T]: Action<T[K]>;\n};\n\nexport type ActionDispatch = () => void;\n\n/**\n * TODO: Actions should be able to switch or hold multiple scopes\n * TODO: .and method to chain actions for multireducers and multieffects\n */\nexport class Action<Payload = void> extends Subject<Payload> {\n\tprivate dispatchSubscription?: Subscription | undefined;\n\n\tprivate config: ActionConfig;\n\n\tprivate scope: Scope | undefined;\n\n\tpublic registrations = new Subscription();\n\n\t/**\n\t * This will emit every action of this type, both direct dispatches and\n\t * effect dispatches\n\t */\n\tpublic get listenPackets$(): Observable<ActionPacket<Payload>> {\n\t\treturn this.scope?.listen$(this) ?? EMPTY;\n\t}\n\n\t/**\n\t * This won't receive actions from effects\n\t */\n\tpublic get listen$(): Observable<Payload> {\n\t\treturn this.actionPipeline;\n\t}\n\n\tprivate actionPipeline: Observable<Payload>;\n\n\t//\toverride subscribe;\n\n\t/**\n\t * TODO: Make this private, refactor angular solution\n\t * @param type\n\t * @param config\n\t */\n\tpublic constructor(\n\t\tpublic type: string,\n\t\tconfig: Partial<ActionConfig> = DEFAULT_ACTION_CONFIG,\n\t) {\n\t\tsuper();\n\t\tthis.config = {\n\t\t\t...DEFAULT_ACTION_CONFIG,\n\t\t\t...config,\n\t\t};\n\n\t\tthis.actionPipeline = this;\n\n\t\tif (isNotNullish(this.config.pauseWhile)) {\n\t\t\tthis.actionPipeline = this.actionPipeline.pipe(\n\t\t\t\tifLatestFrom(this.config.pauseWhile, (paused) => !paused),\n\t\t\t);\n\t\t}\n\n\t\tif (isNotNullish(this.config.throttleTime)) {\n\t\t\tthis.actionPipeline = this.actionPipeline.pipe(\n\t\t\t\tthrottleTime(this.config.throttleTime, asyncScheduler, {\n\t\t\t\t\tleading: true,\n\t\t\t\t\ttrailing: true,\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\t// this.subscribe = this.#actionPipeline.subscribe.bind(this.#actionPipeline);\n\t}\n\n\tpublic register(scope: Scope): this {\n\t\tthis.scope = scope;\n\t\tthis.dispatchSubscription = this.scope.registerAction(this, true);\n\t\treturn this;\n\t}\n\n\tpublic unregister(): void {\n\t\tthis.dispatchSubscription?.unsubscribe();\n\t}\n\n\tpublic makePacket(payload: Payload): ActionPacket<Payload> {\n\t\treturn { type: this.type, payload };\n\t}\n\n\t/**\n\t * The finalize operator will take care of removing it from the actionMap\n\t */\n\tpublic override complete(): void {\n\t\tthis.unregister();\n\t\tthis.registrations.unsubscribe();\n\t\tthis.unsubscribe();\n\t}\n\n\t/**\n\t *\n\t */\n\tpublic getFilter(): MonoTypeOperatorFunction<ActionPacket<Payload>> {\n\t\treturn <T>(source: Observable<ActionPacket<T>>) =>\n\t\t\tsource.pipe(filter((value) => value.type === this.type));\n\t}\n\n\tpublic static makeFilter<T extends readonly unknown[]>(\n\t\t...actions: [...ActionTuple<T>]\n\t): MonoTypeOperatorFunction<ActionPacket<T[number]>> {\n\t\tconst allowedTypes = new Set<string>(actions.map((action) => action.type));\n\t\treturn (source: Observable<ActionPacket<T[number]>>) =>\n\t\t\tsource.pipe(filter((value) => allowedTypes.has(value.type)));\n\t}\n\n\tpublic reduce<State>(\n\t\tactionReducer: ActionReducer<State, Payload>,\n\t): ReducerConfiguration<State, Payload> {\n\t\treturn {\n\t\t\tpacketReducer: (\n\t\t\t\tstate: State,\n\t\t\t\tactionPacket: ActionPacket<Payload> | undefined,\n\t\t\t): State => (actionPacket ? actionReducer(state, actionPacket.payload) : state),\n\t\t\taction: this,\n\t\t};\n\t}\n}\n","import { isNotNullish } from '@alexaegis/common';\nimport type { ActionPacket } from '../action/action-packet.interface.js';\nimport type { Action } from '../action/action.class.js';\n\nexport interface InitialSliceSnapshot<State> {\n\tnextState: State;\n}\n\nexport interface ReduceActionSliceSnapshot<State> {\n\tactionPacket: ActionPacket;\n\tprevState: State;\n\tnextState: State;\n}\n\nexport type SliceSnapshot<State> = InitialSliceSnapshot<State> | ReduceActionSliceSnapshot<State>;\n\nexport const isReduceActionSliceSnapshot = <State>(\n\tt: ReduceActionSliceSnapshot<State> | InitialSliceSnapshot<State>,\n): t is ReduceActionSliceSnapshot<State> =>\n\tisNotNullish((t as ReduceActionSliceSnapshot<State>).actionPacket);\n\nexport interface MetaReducer {\n\tpreRootReduce: (absolutePath: string, state: unknown, action: ActionPacket) => void;\n\tpreReduce: (absolutePath: string, state: unknown, action: ActionPacket) => void;\n\tpostReduce: MetaSnapshotReducer;\n\tpostRootReduce: MetaSnapshotReducer;\n}\n\nexport type MetaSnapshotReducer = (\n\tabsolutePath: string,\n\tsnapshot: ReduceActionSliceSnapshot<unknown>,\n) => void;\n\nexport type PacketReducer<State, Payload = unknown> = (\n\tstate: State,\n\tactionPacket: ActionPacket<Payload> | undefined,\n) => State;\n\nexport type PayloadReducer<State, Payload> = (state: State, payload: Payload) => State;\nexport type StatelessReducer<State> = () => State;\nexport type ActionReducer<State, Payload> =\n\tPayloadReducer<State, Payload> | StatelessReducer<State>;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface ReducerConfiguration<State, Payload = any> {\n\taction: Action<Payload>;\n\tpacketReducer: PacketReducer<State, Payload>;\n}\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type CancellableReducerConfiguration<State, Payload = any> = ReducerConfiguration<\n\tState,\n\tPayload\n> & { reducerCanceller: () => void };\n","import { isNotNullish } from '@alexaegis/common';\nimport {\n\tBehaviorSubject,\n\tcatchError,\n\tcombineLatest,\n\tdistinctUntilChanged,\n\tfilter,\n\tfinalize,\n\tfirstValueFrom,\n\tmap,\n\tNEVER,\n\tObservable,\n\tof,\n\tpairwise,\n\tshare,\n\tshareReplay,\n\tskip,\n\tstartWith,\n\tSubscription,\n\tswitchMap,\n\ttake,\n\ttakeWhile,\n\ttap,\n\twithLatestFrom,\n\tzip,\n} from 'rxjs';\nimport type { Action, ActionConfig, ActionPacket } from '../action/index.js';\nimport {\n\tfastArrayComparator,\n\tgetNextKeyStrategy,\n\tgetObjectKeysAsNumbers,\n\thasKey,\n\tifLatestFrom,\n\tisNullish,\n\tTINYSLICE_DEFAULT_PREFIX,\n\tTINYSLICE_PREFIX,\n\tupdateObject,\n\ttype GetNext,\n\ttype NextKeyStrategy,\n} from '../helper/index.js';\nimport type { TinySlicePlugin } from '../plugins/index.js';\nimport type { Merger } from './merger.type.js';\nimport type {\n\tMetaReducer,\n\tPacketReducer,\n\tReduceActionSliceSnapshot,\n\tReducerConfiguration,\n} from './reducer.type.js';\nimport type { Scope } from './scope.class.js';\nimport type { Selector } from './selector.type.js';\nimport type { StrictRuntimeChecks } from './strict-runtime-checks.interface.js';\n\nexport type ObjectKey = string | number | symbol;\nexport type UnknownObject<T = unknown> = Record<ObjectKey, T>;\nexport type SliceDetacher = () => void;\n\nexport interface DicedSlice<\n\tState,\n\tChildState,\n\tParentInternals,\n\tChildInternals,\n\tDiceKey extends ObjectKey,\n> {\n\tslice: Slice<unknown, State & Record<DiceKey, ChildState>, ParentInternals>;\n\tkeys: () => DiceKey[];\n\tkeys$: Observable<DiceKey[]>;\n\tcount$: Observable<number>;\n\titems$: Observable<ChildState[]>;\n\tsome$: (predicate: (item: ChildState) => boolean) => Observable<boolean>;\n\tevery$: (predicate: (item: ChildState) => boolean) => Observable<boolean>;\n\tadd: (data: ChildState) => void;\n\tcreate: () => void;\n\tset: (key: DiceKey, data: ChildState) => void;\n\tremove: (key: DiceKey) => void;\n\tgetNextKey: () => DiceKey;\n\thas: (key: DiceKey) => boolean;\n\tget: (\n\t\tkey: DiceKey,\n\t) => Slice<State & Record<DiceKey, ChildState>, NonNullable<ChildState>, ChildInternals>;\n\tselectOnceDefined: (\n\t\tkey: DiceKey,\n\t) => Promise<\n\t\tSlice<State & Record<DiceKey, ChildState>, NonNullable<ChildState>, ChildInternals>\n\t>;\n}\n\n/**\n * This type can be used to get the Child slice signature of a diced slice\n * ```ts\n * const pieDice = pies$.dice({...});\n * DicedSliceChild<typeof pieDice>; // Slice<>\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type DicedSliceChild<D extends DicedSlice<any, any, any, any, any>> = ReturnType<D['get']>;\n\nexport interface SliceCoupling<ParentState, State> {\n\tparentSlice: Slice<unknown, ParentState, UnknownObject>;\n\trawParentState: Observable<ParentState>;\n\t/**\n\t * Used to check the lifetime of the slice, once the key itself is removed\n\t * from the parent object, the subslice is completed.\n\t * Most subslices are attached via a key, only custom select baseds are not.\n\t */\n\tkey: ObjectKey | undefined;\n\tslicer: SelectSlicer<ParentState, State>;\n\tdroppable: boolean;\n}\n\nexport interface SliceRegistration<ParentState, State, Internals> {\n\tslice: Slice<ParentState, State, Internals>;\n\tslicer: SelectSlicer<ParentState, State>;\n\tkey: ObjectKey | undefined;\n\tinitialState: State | undefined;\n}\n\nexport interface SliceOptions<ParentState, State, Internals> {\n\treducers?: ReducerConfiguration<State>[] | undefined;\n\tplugins?: TinySlicePlugin<State>[] | undefined;\n\tmetaReducers?: MetaReducer[] | undefined;\n\t/**\n\t * ? Setting the passed slices Internal generic to unknown is crucial for\n\t * ? type inference to work\n\t */\n\tdefineInternals?: ((slice: Slice<ParentState, State>) => Internals) | undefined;\n}\n\nexport interface RootSliceOptions<State, Internals> extends SliceOptions<never, State, Internals> {\n\t/**\n\t * Runtime checks can slow the store down, turn them off in production,\n\t * they are all on by default.\n\t */\n\truntimeChecks?: StrictRuntimeChecks;\n}\n\nexport type RootSlice<State, Internals = unknown> = Slice<never, State, Internals>;\n\nexport interface SliceConstructOptions<ParentState, State, Internals> extends SliceOptions<\n\tParentState,\n\tState,\n\tInternals\n> {\n\tscope: Scope;\n\tinitialState: State;\n\tparentCoupling?: SliceCoupling<ParentState, State>;\n\tpathSegment: string;\n}\n\nexport interface DiceConstructOptions<\n\tState,\n\tChildState,\n\tChildInternals,\n\tDiceKey,\n> extends SliceOptions<State, ChildState, ChildInternals> {\n\tgetAllKeys: (state: State) => DiceKey[];\n\tgetNextKey: GetNext<DiceKey>;\n}\n\nexport interface PremadeDiceConstructOptions<\n\tParentState,\n\tState,\n\tChildState,\n\tInternals,\n\tChildInternals,\n> extends SliceOptions<State, ChildState, ChildInternals> {\n\tgetNextKeyStrategy?: NextKeyStrategy;\n\tdicedSliceOptions?: SliceOptions<ParentState, State, Internals>;\n}\n\nconst extractSliceOptions = <ParentState, State, Internals>(\n\tconstructOptions?: SliceOptions<ParentState, State, Internals>,\n): SliceOptions<ParentState, State, Internals> => {\n\treturn {\n\t\tdefineInternals: constructOptions?.defineInternals,\n\t\tmetaReducers: constructOptions?.metaReducers,\n\t\tplugins: constructOptions?.plugins,\n\t\treducers: constructOptions?.reducers,\n\t};\n};\n\nexport interface ChildSliceConstructOptions<ParentState, State, Internals> extends SliceOptions<\n\tParentState,\n\tState,\n\tInternals\n> {\n\tinitialState?: State | undefined;\n\t/**\n\t * Marks if a slice should be dropped when its key is dropped from its\n\t * parent. It's generally only safe to do with dynamic slices (dices)\n\t * that are only accessed through lazy slice accessors\n\t */\n\tdroppable: boolean;\n\tpathSegment: string;\n\tslicer: SelectSlicer<ParentState, State>;\n\tkey: ObjectKey | undefined;\n}\n\nexport interface SelectSlicer<ParentState, State> {\n\tselector: Selector<ParentState, State>;\n\tmerger: Merger<ParentState, State>;\n}\n\nexport interface SliceChange<State> {\n\tsnapshot: ReduceActionSliceSnapshot<unknown>;\n\tsliceRegistration: SliceRegistration<State, unknown, unknown>;\n}\n\n/**\n * TODO: Create a variant where the key must not already be part of ParentState\n * TODO: and State must not already be a value of ParentState\n */\nexport type SliceDirection<ParentState, State> =\n\tstring | number | symbol | keyof ParentState | SelectSlicer<ParentState, State>;\n\nexport const normalizeSliceDirection = <ParentState, State>(\n\tsliceDirection: SliceDirection<ParentState, State>,\n): SelectSlicer<ParentState, State> => {\n\tif (typeof sliceDirection === 'object') {\n\t\treturn sliceDirection;\n\t} else {\n\t\tconst key = sliceDirection;\n\t\tconst selector: Selector<ParentState, State> = (state) => {\n\t\t\treturn isNotNullish(state) && typeof state === 'object'\n\t\t\t\t? (state[key as keyof ParentState] as State)\n\t\t\t\t: (undefined as State);\n\t\t};\n\t\tconst merger: Merger<ParentState, State | undefined> = (parentState, state) => {\n\t\t\tif (isNullish(parentState)) {\n\t\t\t\treturn parentState;\n\t\t\t}\n\n\t\t\t// ? state can be nullish, and the key should be defined in that case too.\n\t\t\treturn typeof parentState === 'object'\n\t\t\t\t? {\n\t\t\t\t\t\t...parentState,\n\t\t\t\t\t\t[key]: state,\n\t\t\t\t\t}\n\t\t\t\t: parentState;\n\t\t};\n\n\t\treturn {\n\t\t\tmerger,\n\t\t\tselector,\n\t\t};\n\t}\n};\n\n/**\n * It's pizza time!\n */\nexport class Slice<ParentState, State, Internals = unknown> extends Observable<State> {\n\tprivate readonly sink = new Subscription();\n\n\tprivate options: SliceConstructOptions<ParentState, State, Internals>;\n\tprivate scope: Scope;\n\tprivate initialState: State;\n\tprivate parentCoupling: SliceCoupling<ParentState, State> | undefined;\n\tprivate initialReducers: ReducerConfiguration<State>[];\n\tprivate initialPlugins: TinySlicePlugin<State>[];\n\tprivate state$: BehaviorSubject<State>;\n\tprivate _pathSegment: string;\n\tprivate _absolutePath: string;\n\tpublic setAction: Action<State>;\n\tpublic updateAction: Action<Partial<State>>;\n\tpublic deleteKeyAction: Action<ObjectKey>;\n\tpublic defineKeyAction: Action<{ key: ObjectKey; data: unknown }>;\n\tprivate observableState$: Observable<State>;\n\tprivate defaultReducerConfigurations: ReducerConfiguration<State>[];\n\tprivate reducerConfigurations$: BehaviorSubject<ReducerConfiguration<State>[]>;\n\tprivate autoRegisterReducerActions$: Observable<ReducerConfiguration<State, unknown>[]>;\n\tprivate downStreamReducers$: Observable<string[]>;\n\tprivate sliceReducer$: Observable<PacketReducer<State>>;\n\tprivate sliceReducingActions$: Observable<string[]>;\n\tprivate plugins$: BehaviorSubject<TinySlicePlugin<State>[]>;\n\tprivate autoRegisterPlugins$: Observable<unknown>;\n\tprivate nullishParentPause$: BehaviorSubject<boolean>;\n\tprivate manualPause$: BehaviorSubject<boolean>;\n\tprivate pause$: Observable<boolean>;\n\n\tprivate keyedSlices$ = new BehaviorSubject<\n\t\tRecord<string, SliceRegistration<State, unknown, Internals>>\n\t>({});\n\n\tprivate slices$: Observable<SliceRegistration<State, unknown, Internals>[]> =\n\t\tthis.keyedSlices$.pipe(map((keyedSlices) => Object.values(keyedSlices)));\n\n\toverride subscribe;\n\n\t// Listens to the parent for changes to select itself from\n\t// check if the parent could do it instead\n\tprivate parentListener: Observable<State | undefined> | undefined;\n\n\tprivate inactivePipeline: Observable<ReduceActionSliceSnapshot<State>>;\n\tprivate activePipeline: Observable<ReduceActionSliceSnapshot<State>>;\n\n\tprivate pipeline: Observable<ReduceActionSliceSnapshot<State>>;\n\n\tprivate defineInternals: ((state: Slice<ParentState, State>) => Internals) | undefined;\n\tprivate _internals: Internals;\n\tprivate scopedActions: Action<unknown>[] = [];\n\n\tget internals(): Internals {\n\t\treturn this._internals;\n\t}\n\n\tget absolutePath(): string {\n\t\treturn this._absolutePath;\n\t}\n\n\tget pathSegment(): string {\n\t\treturn this._pathSegment;\n\t}\n\n\t/**\n\t * For debugging purposes\n\t */\n\tpublic printSliceStructure(indentationLevel = 0): void {\n\t\tif (indentationLevel === 0) {\n\t\t\tconsole.groupCollapsed('Slice Structure', this.absolutePath);\n\t\t}\n\t\tconsole.log('\\t'.repeat(indentationLevel) + this.pathSegment);\n\t\tfor (const [, value] of Object.entries(this.keyedSlices$.value)) {\n\t\t\tvalue.slice.printSliceStructure(indentationLevel + 1);\n\t\t}\n\t\tif (indentationLevel === 0) {\n\t\t\tconsole.groupEnd();\n\t\t}\n\t}\n\n\t/**\n\t *\n\t * @param initialState\n\t * @param sliceSegment a string that represents this slice, has to be\n\t * unique on it's parent.\n\t */\n\tprivate constructor(options: SliceConstructOptions<ParentState, State, Internals>) {\n\t\tsuper();\n\t\tthis.options = options;\n\t\tthis.scope = options.scope;\n\t\tthis._pathSegment = options.pathSegment;\n\t\tthis.initialState = options.initialState;\n\t\tthis.parentCoupling = options.parentCoupling;\n\t\tthis.initialReducers = options.reducers ?? [];\n\t\tthis.initialPlugins = options.plugins ?? [];\n\t\tthis.defineInternals = options.defineInternals;\n\n\t\tthis.nullishParentPause$ = new BehaviorSubject(false);\n\t\tthis.manualPause$ = new BehaviorSubject(false);\n\t\tthis.pause$ = combineLatest([this.nullishParentPause$, this.manualPause$]).pipe(\n\t\t\tmap(([nullishParentPause, manualPause]) => nullishParentPause || manualPause),\n\t\t);\n\n\t\tthis._absolutePath = Slice.calculateAbsolutePath(this.parentCoupling, this._pathSegment);\n\n\t\tthis.setAction = this.createAction<State>(`${TINYSLICE_DEFAULT_PREFIX} set`);\n\t\tthis.updateAction = this.createAction<Partial<State>>(`${TINYSLICE_DEFAULT_PREFIX} update`);\n\n\t\tthis.deleteKeyAction = this.createAction<ObjectKey>(\n\t\t\t`${TINYSLICE_DEFAULT_PREFIX} delete key`,\n\t\t);\n\n\t\tthis.defineKeyAction = this.createAction<{ key: ObjectKey; data: unknown }>(\n\t\t\t`${TINYSLICE_DEFAULT_PREFIX} define key`,\n\t\t);\n\n\t\tthis.state$ = new BehaviorSubject<State>(this.initialState);\n\t\tthis.observableState$ = this.state$.pipe(distinctUntilChanged());\n\n\t\tthis.defaultReducerConfigurations = [\n\t\t\tthis.setAction.reduce((_state, payload) => payload),\n\t\t\tthis.updateAction.reduce((state, payload) => updateObject(state, payload)),\n\t\t\tthis.deleteKeyAction.reduce((state, payload) => {\n\t\t\t\tif (typeof state === 'object') {\n\t\t\t\t\tconst nextState = { ...state };\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n\t\t\t\t\tdelete (nextState as State)[payload as keyof State];\n\t\t\t\t\treturn nextState;\n\t\t\t\t} else {\n\t\t\t\t\treturn state;\n\t\t\t\t}\n\t\t\t}),\n\t\t\tthis.defineKeyAction.reduce((state, payload) => {\n\t\t\t\treturn typeof state === 'object'\n\t\t\t\t\t? {\n\t\t\t\t\t\t\t...state,\n\t\t\t\t\t\t\t[payload.key]: payload.data,\n\t\t\t\t\t\t}\n\t\t\t\t\t: state;\n\t\t\t}),\n\t\t];\n\n\t\tthis.reducerConfigurations$ = new BehaviorSubject<ReducerConfiguration<State>[]>([\n\t\t\t...this.defaultReducerConfigurations,\n\t\t\t...this.initialReducers,\n\t\t]);\n\n\t\tthis.autoRegisterReducerActions$ = this.reducerConfigurations$.pipe(\n\t\t\ttap((reducerConfigurations) => {\n\t\t\t\tfor (const reducerConfiguration of reducerConfigurations) {\n\t\t\t\t\tthis.scope.registerAction(reducerConfiguration.action);\n\t\t\t\t}\n\t\t\t}),\n\t\t);\n\n\t\tthis.sliceReducer$ = this.reducerConfigurations$.pipe(\n\t\t\tmap(\n\t\t\t\t(reducerConfigurations): PacketReducer<State> =>\n\t\t\t\t\t(state, action) =>\n\t\t\t\t\t\taction\n\t\t\t\t\t\t\t? reducerConfigurations\n\t\t\t\t\t\t\t\t\t.filter((rc) => rc.action.type === action.type)\n\t\t\t\t\t\t\t\t\t.reduce(\n\t\t\t\t\t\t\t\t\t\t(acc, { packetReducer }) => packetReducer(acc, action),\n\t\t\t\t\t\t\t\t\t\tstate,\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t: state,\n\t\t\t),\n\t\t\tshareReplay(1),\n\t\t);\n\n\t\tthis.sliceReducingActions$ = this.reducerConfigurations$.pipe(\n\t\t\tmap((reducerConfigurations) => [\n\t\t\t\t...new Set(reducerConfigurations.map((r) => r.action.type)),\n\t\t\t]),\n\t\t\tshareReplay(1),\n\t\t);\n\n\t\tthis.downStreamReducers$ = this.slices$.pipe(\n\t\t\twithLatestFrom(this.sliceReducingActions$),\n\t\t\tswitchMap(([slices, sliceReducingActions]) => {\n\t\t\t\treturn slices.length > 0\n\t\t\t\t\t? combineLatest(slices.map((next) => next.slice.downStreamReducers$)).pipe(\n\t\t\t\t\t\t\tmap((subSliceReducer) => [\n\t\t\t\t\t\t\t\t...sliceReducingActions,\n\t\t\t\t\t\t\t\t...subSliceReducer.flat(),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t)\n\t\t\t\t\t: of(sliceReducingActions);\n\t\t\t}),\n\t\t\tshareReplay(1), // computed from a behaviorSubject and another computed field\n\t\t);\n\n\t\tconst slicesWithDownStreamReducers$ = this.slices$.pipe(\n\t\t\tswitchMap((sliceRegistrations) => {\n\t\t\t\treturn sliceRegistrations.length > 0\n\t\t\t\t\t? combineLatest(\n\t\t\t\t\t\t\tsliceRegistrations.map((sliceRegistration) =>\n\t\t\t\t\t\t\t\tsliceRegistration.slice.downStreamReducers$.pipe(\n\t\t\t\t\t\t\t\t\tmap((downStreamReducers) => ({\n\t\t\t\t\t\t\t\t\t\tdownStreamReducers,\n\t\t\t\t\t\t\t\t\t\tsliceRegistration,\n\t\t\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t)\n\t\t\t\t\t: of([]);\n\t\t\t}),\n\t\t\tshareReplay(1), // computed from behaviorSubjects from a behaviorSubject\n\t\t);\n\n\t\tconst schedulingDispatcher$ = this.scope.schedulingDispatcher$.pipe(\n\t\t\tifLatestFrom(this.downStreamReducers$, (downStreamReducers, actionPacket) =>\n\t\t\t\tdownStreamReducers.includes(actionPacket.type),\n\t\t\t),\n\t\t\ttap((actionPacket) => {\n\t\t\t\tthis.executeMetaPreReducers(actionPacket);\n\t\t\t}),\n\t\t);\n\n\t\tconst dispatchAndSlices$ = schedulingDispatcher$.pipe(\n\t\t\tswitchMap((actionPacket) =>\n\t\t\t\tslicesWithDownStreamReducers$.pipe(\n\t\t\t\t\ttake(1),\n\t\t\t\t\tmap((slicesWithDownStreamReducers) => ({\n\t\t\t\t\t\tactionPacket,\n\t\t\t\t\t\tslicesWithDownStreamReducers,\n\t\t\t\t\t})),\n\t\t\t\t),\n\t\t\t),\n\t\t);\n\n\t\tconst filterSliceRegistrationBasedOnActionTypeSupport = (\n\t\t\tslicesWithDownStreamReducers: {\n\t\t\t\tdownStreamReducers: string[];\n\t\t\t\tsliceRegistration: SliceRegistration<State, unknown, Internals>;\n\t\t\t}[],\n\t\t\tactionType: string,\n\t\t) => {\n\t\t\treturn slicesWithDownStreamReducers\n\t\t\t\t.map(({ sliceRegistration, downStreamReducers }) => {\n\t\t\t\t\treturn downStreamReducers.includes(actionType)\n\t\t\t\t\t\t? sliceRegistration.slice.pipeline.pipe(\n\t\t\t\t\t\t\t\tmap(\n\t\t\t\t\t\t\t\t\t(snapshot) =>\n\t\t\t\t\t\t\t\t\t\t({\n\t\t\t\t\t\t\t\t\t\t\tsnapshot,\n\t\t\t\t\t\t\t\t\t\t\tsliceRegistration,\n\t\t\t\t\t\t\t\t\t\t}) as SliceChange<State>,\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t: undefined;\n\t\t\t\t})\n\t\t\t\t.filter(isNotNullish);\n\t\t};\n\n\t\tconst zippedDispatch = dispatchAndSlices$.pipe(\n\t\t\tswitchMap(({ slicesWithDownStreamReducers, actionPacket }) => {\n\t\t\t\tconst neededChildSlices = filterSliceRegistrationBasedOnActionTypeSupport(\n\t\t\t\t\tslicesWithDownStreamReducers,\n\t\t\t\t\tactionPacket.type,\n\t\t\t\t);\n\t\t\t\treturn neededChildSlices.length > 0\n\t\t\t\t\t? zip(neededChildSlices).pipe(\n\t\t\t\t\t\t\tmap((sliceChanges) => ({ sliceChanges, actionPacket })),\n\t\t\t\t\t\t)\n\t\t\t\t\t: of({ sliceChanges: [], actionPacket });\n\t\t\t}),\n\t\t);\n\n\t\tthis.activePipeline = zippedDispatch.pipe(\n\t\t\twithLatestFrom(this.state$, this.sliceReducer$),\n\t\t\tmap(\n\t\t\t\t([\n\t\t\t\t\t{ actionPacket, sliceChanges },\n\t\t\t\t\tprevState,\n\t\t\t\t\tsliceReducer,\n\t\t\t\t]): ReduceActionSliceSnapshot<State> => {\n\t\t\t\t\tif (this.isRootOrParentStateUndefined()) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tactionPacket,\n\t\t\t\t\t\t\tprevState,\n\t\t\t\t\t\t\tnextState: prevState,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\tconst nextState: State =\n\t\t\t\t\t\tsliceChanges\n\t\t\t\t\t\t\t.filter(\n\t\t\t\t\t\t\t\t(sliceChange) =>\n\t\t\t\t\t\t\t\t\tsliceChange.snapshot.prevState !==\n\t\t\t\t\t\t\t\t\tsliceChange.snapshot.nextState,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t.reduce(\n\t\t\t\t\t\t\t\t(prevState, sliceChange) =>\n\t\t\t\t\t\t\t\t\tsliceChange.sliceRegistration.slicer.merger(\n\t\t\t\t\t\t\t\t\t\tprevState,\n\t\t\t\t\t\t\t\t\t\tsliceChange.snapshot.nextState,\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\tprevState,\n\t\t\t\t\t\t\t) ?? prevState;\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tactionPacket,\n\t\t\t\t\t\tprevState,\n\t\t\t\t\t\tnextState: sliceReducer(nextState, actionPacket),\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t),\n\t\t\ttap((snapshot) => {\n\t\t\t\tif (snapshot.prevState !== snapshot.nextState) {\n\t\t\t\t\tthis.state$.next(snapshot.nextState);\n\t\t\t\t}\n\t\t\t}),\n\t\t\tcatchError((error, pipeline$) => {\n\t\t\t\tconsole.error(`${TINYSLICE_PREFIX} slice pipeline error \\n`, error);\n\t\t\t\treturn this.plugins$.pipe(\n\t\t\t\t\ttake(1),\n\t\t\t\t\ttap((plugins) => {\n\t\t\t\t\t\tfor (const plugin of plugins) {\n\t\t\t\t\t\t\tplugin.onError?.(error);\n\t\t\t\t\t\t}\n\t\t\t\t\t}),\n\t\t\t\t\tswitchMap(() => pipeline$),\n\t\t\t\t);\n\t\t\t}),\n\t\t);\n\n\t\tthis.inactivePipeline = schedulingDispatcher$.pipe(\n\t\t\twithLatestFrom(this.state$),\n\t\t\tmap(([, state]) => {\n\t\t\t\treturn {\n\t\t\t\t\tactionPacket: { type: 'paused', payload: undefined },\n\t\t\t\t\tprevState: state,\n\t\t\t\t\tnextState: state,\n\t\t\t\t} as ReduceActionSliceSnapshot<State>;\n\t\t\t}),\n\t\t);\n\n\t\tthis.pipeline = this.pause$.pipe(\n\t\t\tswitchMap((paused) => (paused ? this.inactivePipeline : this.activePipeline)),\n\t\t\ttap((snapshot) => {\n\t\t\t\tthis.executeMetaPostReducers(snapshot);\n\t\t\t}),\n\t\t\tshare(), // has to be shared because of child listeners\n\t\t);\n\n\t\tthis.plugins$ = new BehaviorSubject<TinySlicePlugin<State>[]>(this.initialPlugins);\n\n\t\t// Listens to the parent for changes to select itself from\n\t\tthis.parentListener = this.parentCoupling?.rawParentState.pipe(\n\t\t\tskip(1),\n\t\t\tfinalize(() => {\n\t\t\t\tthis.complete();\n\t\t\t}),\n\t\t\ttakeWhile((parentState) =>\n\t\t\t\tthis.parentCoupling?.droppable\n\t\t\t\t\t? hasKey(parentState, this.parentCoupling.key)\n\t\t\t\t\t: true,\n\t\t\t),\n\t\t\ttap((parentState) => {\n\t\t\t\tif (isNullish(parentState) && !this.nullishParentPause$.value) {\n\t\t\t\t\tthis.nullishParentPause$.next(true);\n\t\t\t\t} else if (this.nullishParentPause$.value) {\n\t\t\t\t\tthis.nullishParentPause$.next(false);\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfilter(isNotNullish),\n\t\t\tmap((parentState) => this.parentCoupling?.slicer.selector(parentState)),\n\t\t\tdistinctUntilChanged(),\n\t\t\ttap((stateFromParent) => {\n\t\t\t\tthis.state$.next(stateFromParent as State);\n\t\t\t}),\n\t\t);\n\n\t\tthis.autoRegisterPlugins$ = this.plugins$.pipe(\n\t\t\tstartWith([] as TinySlicePlugin<State>[]),\n\t\t\tpairwise(),\n\t\t\ttap(([previous, next]) => {\n\t\t\t\t// Stop whats no longer present\n\t\t\t\tfor (const plugin of previous.filter((plugin) => !next.includes(plugin))) {\n\t\t\t\t\tplugin.stop();\n\t\t\t\t}\n\t\t\t\t// Start what's new\n\t\t\t\tfor (const plugin of next.filter((plugin) => !previous.includes(plugin))) {\n\t\t\t\t\tthis.registerPlugin(plugin);\n\t\t\t\t}\n\t\t\t}),\n\t\t);\n\n\t\tthis.subscribe = this.observableState$\n\t\t\t.pipe(filter(isNotNullish))\n\t\t\t.subscribe.bind(this.observableState$);\n\n\t\tthis.scope.slices.set(this._absolutePath, this);\n\n\t\tif (this.parentCoupling) {\n\t\t\tthis.parentCoupling.parentSlice.registerSlice({\n\t\t\t\tslice: this,\n\t\t\t\tslicer: this.parentCoupling.slicer,\n\t\t\t\tinitialState: this.initialState,\n\t\t\t\tkey: this.parentCoupling.key,\n\t\t\t});\n\n\t\t\tthis.sink.add(this.parentListener?.subscribe());\n\t\t}\n\n\t\tthis.sink.add(this.autoRegisterReducerActions$.subscribe());\n\t\tthis.sink.add(this.autoRegisterPlugins$.subscribe());\n\t\tthis.sink.add(this.pipeline.subscribe()); // Slices are hot!\n\n\t\t// ? defineInternals call has to happen after this slice has been\n\t\t// ? coupled to its parent\n\t\tthis._internals = this.defineInternals?.(this) ?? ({} as Internals);\n\t}\n\n\tprivate executeMetaPreReducers(action: ActionPacket) {\n\t\tfor (const plugin of this.plugins$.value) {\n\t\t\tif (!this.options.parentCoupling) {\n\t\t\t\tplugin.preRootReduce?.(this._absolutePath, this.state$.value, action);\n\t\t\t}\n\t\t\tplugin.preReduce?.(this._absolutePath, this.state$.value, action);\n\t\t}\n\t}\n\n\tprivate executeMetaPostReducers<State>(snapshot: ReduceActionSliceSnapshot<State>) {\n\t\tfor (const plugin of this.plugins$.value) {\n\t\t\tplugin.postReduce?.(this._absolutePath, snapshot);\n\t\t\tif (!this.options.parentCoupling) {\n\t\t\t\tplugin.postRootReduce?.(this._absolutePath, snapshot);\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic loadAndSetPlugins(\n\t\t...pluginImports: (() => Promise<TinySlicePlugin<State>>)[]\n\t): Promise<TinySlicePlugin<State>[]> {\n\t\treturn Promise.all(pluginImports.map((pluginImport) => pluginImport())).then((plugins) => {\n\t\t\tthis.setPlugins(plugins);\n\t\t\treturn plugins;\n\t\t});\n\t}\n\n\tpublic get paused$(): Observable<boolean> {\n\t\treturn this.pause$;\n\t}\n\n\t/**\n\t * Unpauses this slice and every child slice recursively\n\t */\n\tpublic unpause(): void {\n\t\tif (this.manualPause$.value) {\n\t\t\tthis.manualPause$.next(false);\n\t\t}\n\t\tfor (const subSlice of Object.values(this.keyedSlices$.value)) {\n\t\t\tsubSlice.slice.unpause();\n\t\t}\n\t}\n\n\t/**\n\t * Pauses this slice and every child slice recursively\n\t */\n\tpublic pause(): void {\n\t\tif (!this.manualPause$.value) {\n\t\t\tthis.manualPause$.next(true);\n\t\t}\n\t\tfor (const subSlice of Object.values(this.keyedSlices$.value)) {\n\t\t\tsubSlice.slice.pause();\n\t\t}\n\t}\n\n\t/**\n\t * Effects created here will respond to the pause and unpauseEffects functions.\n\t * These effects will also unsubscribe if the slice unsubscribes\n\t */\n\tpublic createEffect<Output>(packet$: Observable<Output | ActionPacket>): Subscription {\n\t\tconst pausablePacket$ = this.paused$.pipe(\n\t\t\tswitchMap((isPaused) => (isPaused ? NEVER : packet$)),\n\t\t);\n\t\tconst effectSubscription = this.scope.createEffect(pausablePacket$);\n\t\tthis.sink.add(effectSubscription);\n\t\treturn effectSubscription;\n\t}\n\n\tpublic setPlugins(plugins: TinySlicePlugin<State>[]): void {\n\t\tthis.plugins$.next([...(this.options.plugins ?? []), ...plugins]);\n\t}\n\n\tpublic getPlugins(): TinySlicePlugin<State>[] {\n\t\treturn this.plugins$.value;\n\t}\n\n\tpublic addPlugin(...plugins: TinySlicePlugin<State>[]): void {\n\t\tthis.plugins$.next([...this.plugins$.value, ...plugins]);\n\t}\n\n\tpublic getReducers(): ReducerConfiguration<State>[] {\n\t\treturn this.reducerConfigurations$.value;\n\t}\n\n\t/**\n\t * This does not disable default redurces.\n\t */\n\tpublic setReducers(reducers: ReducerConfiguration<State>[]): void {\n\t\tthis.reducerConfigurations$.next([...this.defaultReducerConfigurations, ...reducers]);\n\t}\n\n\tpublic addReducers(reducers: ReducerConfiguration<State>[]): void {\n\t\tthis.reducerConfigurations$.next([...this.reducerConfigurations$.value, ...reducers]);\n\t}\n\n\tstatic assembleAbsolutePath(parentAbsolutePath: string, segment: string): string {\n\t\treturn `${parentAbsolutePath}${parentAbsolutePath ? '.' : ''}${segment}`;\n\t}\n\n\tprivate static calculateAbsolutePath<ParentState, State>(\n\t\tparentCoupling: SliceCoupling<ParentState, State> | undefined,\n\t\tpathSegment: string,\n\t): string {\n\t\treturn parentCoupling\n\t\t\t? Slice.assembleAbsolutePath(parentCoupling.parentSlice._absolutePath, pathSegment)\n\t\t\t: pathSegment;\n\t}\n\n\tprivate registerPlugin(plugin: TinySlicePlugin<State>): TinySlicePlugin<State> {\n\t\tplugin.register({\n\t\t\tinitialState: this.state$.value,\n\t\t\tstate$: this.pipeline,\n\t\t\tstateInjector: (state: State) => {\n\t\t\t\tthis.state$.next(state);\n\t\t\t},\n\t\t});\n\t\tplugin.start();\n\t\treturn plugin;\n\t}\n\n\tpublic set(slice: State | undefined): void {\n\t\tthis.setAction.next(slice as State);\n\t}\n\n\tpublic update(slice: Partial<State>): void {\n\t\tthis.updateAction.next(slice);\n\t}\n\n\tset value(value: State) {\n\t\tthis.set(value);\n\t}\n\n\tget value(): State {\n\t\treturn this.state$.value;\n\t}\n\n\tprivate isRootOrParentStateUndefined(): boolean {\n\t\treturn this.parentCoupling\n\t\t\t? isNullish(this.parentCoupling.parentSlice.state$.value)\n\t\t\t: false;\n\t}\n\n\tpublic static createRootSlice<State, Internals>(\n\t\tscope: Scope,\n\t\tinitialState: State,\n\t\tsliceOptions?: RootSliceOptions<State, Internals>,\n\t): RootSlice<State, Internals> {\n\t\treturn new Slice({\n\t\t\t...extractSliceOptions(sliceOptions),\n\t\t\tscope,\n\t\t\tinitialState,\n\t\t\tpathSegment: 'root',\n\t\t});\n\t}\n\n\tpublic createAction<Packet>(name: string, actionOptions?: ActionConfig): Action<Packet> {\n\t\tconst actionName = `${this._absolutePath} ${name}`;\n\t\tconst action = this.scope.createAction<Packet>(actionName, {\n\t\t\t...actionOptions,\n\t\t\tpauseWhile: this.paused$,\n\t\t});\n\t\tthis.scopedActions.push(action as Action<unknown>);\n\t\treturn action;\n\t}\n\n\tprivate sliceInternal<ChildState, ChildInternals>(\n\t\tchildSliceConstructOptions: ChildSliceConstructOptions<State, ChildState, ChildInternals>,\n\t): Slice<State, NonNullable<ChildState>, ChildInternals> {\n\t\tconst path = Slice.assembleAbsolutePath(\n\t\t\tthis._absolutePath,\n\t\t\tchildSliceConstructOptions.pathSegment.toString(),\n\t\t);\n\t\tif (this.scope.slices.has(path)) {\n\t\t\t// ? If this proves to be error prone just throw an error\n\t\t\t// ? Double define should be disallowed anyway\n\t\t\treturn this.scope.slices.get(path) as Slice<\n\t\t\t\tState,\n\t\t\t\tNonNullable<ChildState>,\n\t\t\t\tChildInternals\n\t\t\t>;\n\t\t} else {\n\t\t\tconst initialStateFromParent: ChildState | undefined = this.state$.value\n\t\t\t\t? childSliceConstructOptions.slicer.selector(this.state$.value)\n\t\t\t\t: undefined;\n\n\t\t\tconst initialState: ChildState =\n\t\t\t\tinitialStateFromParent ?? (childSliceConstructOptions.initialState as ChildState);\n\n\t\t\treturn new Slice<State, ChildState, ChildInternals>({\n\t\t\t\t...extractSliceOptions(childSliceConstructOptions),\n\t\t\t\tplugins: [\n\t\t\t\t\t...(this.plugins$.value as unknown as TinySlicePlugin<ChildState>[]).filter(\n\t\t\t\t\t\t(plugin) => plugin.sliceOptions?.().passToChildren ?? false,\n\t\t\t\t\t),\n\t\t\t\t\t...(childSliceConstructOptions.plugins ?? []),\n\t\t\t\t],\n\t\t\t\tscope: this.scope,\n\t\t\t\tinitialState,\n\t\t\t\tparentCoupling: {\n\t\t\t\t\tparentSlice: this as Slice<unknown, State, UnknownObject>,\n\t\t\t\t\trawParentState: this.observableState$,\n\t\t\t\t\tslicer: childSliceConstructOptions.slicer,\n\t\t\t\t\tdroppable: childSliceConstructOptions.droppable,\n\t\t\t\t\tkey: childSliceConstructOptions.key,\n\t\t\t\t},\n\t\t\t\tpathSegment: childSliceConstructOptions.pathSegment,\n\t\t\t}) as Slice<State, NonNullable<ChildState>, ChildInternals>;\n\t\t}\n\t}\n\n\t/**\n\t * @deprecated remove this, too much trouble because of selector.toString(), use dice instead\n\t */\n\tpublic sliceSelect<ChildState extends State[keyof State], ChildInternals = unknown>(\n\t\tselector: Selector<State, ChildState>,\n\t\tmerger: Merger<State, ChildState>,\n\t\tsliceOptions?: SliceOptions<State, ChildState, ChildInternals>,\n\t): Slice<State, NonNullable<ChildState>, ChildInternals> {\n\t\treturn this.sliceInternal({\n\t\t\t...sliceOptions,\n\t\t\tinitialState: undefined,\n\t\t\tdroppable: false,\n\t\t\tslicer: {\n\t\t\t\tselector,\n\t\t\t\tmerger,\n\t\t\t},\n\t\t\tkey: undefined,\n\t\t\tpathSegment: selector.toString(),\n\t\t});\n\t}\n\n\tpublic slice<ChildStateKey extends keyof State, ChildInternals>(\n\t\tkey: ChildStateKey,\n\t\tsliceOptions?: SliceOptions<State, NonNullable<State[ChildStateKey]>, ChildInternals>,\n\t): Slice<State, NonNullable<State[ChildStateKey]>, ChildInternals> {\n\t\tconst slicer = normalizeSliceDirection<State, NonNullable<State[ChildStateKey]>>(key);\n\t\treturn this.sliceInternal({\n\t\t\t...sliceOptions,\n\t\t\tpathSegment: key.toString(),\n\t\t\tslicer,\n\t\t\tkey: key as string,\n\t\t\tdroppable: false,\n\t\t});\n\t}\n\n\t/**\n\t * Adds non-defined \"lazy\" slices to extend this slice\n\t * ? https://github.com/microsoft/TypeScript/issues/42315\n\t * ? key could be restricted to disallow keys of Slice once negated types\n\t * ? are implemented in TypeScript\n\t */\n\tpublic addSlice<ChildState, ChildInternals, AdditionalKey extends ObjectKey = string>(\n\t\tkey: AdditionalKey,\n\t\tinitialState: ChildState,\n\t\tsliceOptions?: SliceOptions<State, ChildState, ChildInternals>,\n\t): Slice<State & Record<AdditionalKey, ChildState>, NonNullable<ChildState>, ChildInternals> {\n\t\tconst slicer = normalizeSliceDirection<State, ChildState>(key);\n\t\treturn this.sliceInternal({\n\t\t\t...sliceOptions,\n\t\t\tinitialState,\n\t\t\tpathSegment: key.toString(),\n\t\t\tslicer,\n\t\t\tkey: key as string,\n\t\t\tdroppable: false,\n\t\t}) as Slice<\n\t\t\tState & Record<AdditionalKey, ChildState>,\n\t\t\tNonNullable<ChildState>,\n\t\t\tChildInternals\n\t\t>;\n\t}\n\n\t/**\n\t * Adds a new lazy slice then dices it with a number type record,\n\t * you can choose between nextKeyStrategies:\n\t * - NEXT_SMALLEST\n\t * - NEXT_LARGEST,\n\t * - CUSTOM\n\t *\n\t * NEXT_LARGEST is the default as thats the simplest.\n\t *\n\t * ! make sure key doesn't exist via generics on State once that can be done in TS\n\t */\n\tpublic addDicedSlice<\n\t\tKey extends ObjectKey,\n\t\tChildState,\n\t\tDicedInternals,\n\t\tChildInternals,\n\t\tDiceState extends Record<number, ChildState>,\n\t>(\n\t\tkey: Key extends keyof State ? never : Key,\n\t\tinitialState: ChildState,\n\t\tdiceConstructOptions: PremadeDiceConstructOptions<\n\t\t\tState,\n\t\t\tDiceState,\n\t\t\tChildState,\n\t\t\tDicedInternals,\n\t\t\tChildInternals\n\t\t>,\n\t): DicedSlice<State, ChildState, DicedInternals, ChildInternals, number> {\n\t\treturn this.addSlice(key, {} as DiceState, diceConstructOptions.dicedSliceOptions).dice(\n\t\t\tinitialState,\n\t\t\t{\n\t\t\t\t...diceConstructOptions,\n\t\t\t\tgetAllKeys: getObjectKeysAsNumbers,\n\t\t\t\tgetNextKey: getNextKeyStrategy(diceConstructOptions.getNextKeyStrategy),\n\t\t\t},\n\t\t);\n\t}\n\n\t/**\n\t * This slice type is created on the fly for N subsclices of the same type\n\t * great for complex entities that spawn on the fly and have their own\n\t * state definition.\n\t *\n\t * This defines two layers of state at once. The middle layer stores the bottom layers\n\t * you can ask for bottom layers lazyly using a selector. You'll then receive the\n\t * slice object and, all the other guts you predefined, like state observers, actions, etc\n\t *\n\t * Actions are automatically scoped to these selected subslices\n\t *\n\t * Nomenclature: Slicing means to take a single piece of state, dicing is multiple\n\t */\n\tpublic dice<ChildState, ChildInternals, DiceKey extends ObjectKey>(\n\t\tinitialState: ChildState,\n\t\tdiceConstructOptions: DiceConstructOptions<State, ChildState, ChildInternals, DiceKey>,\n\t): DicedSlice<State, ChildState, Internals, ChildInternals, DiceKey> {\n\t\tconst sliceOptions = extractSliceOptions(diceConstructOptions);\n\n\t\tconst get = (key: DiceKey) => {\n\t\t\tconst slicer = normalizeSliceDirection<State, ChildState>(key);\n\t\t\treturn this.sliceInternal({\n\t\t\t\t...sliceOptions,\n\t\t\t\tinitialState,\n\t\t\t\tpathSegment: key.toString(),\n\t\t\t\tslicer,\n\t\t\t\tkey,\n\t\t\t\tdroppable: true,\n\t\t\t}) as Slice<\n\t\t\t\tState & Record<DiceKey, ChildState>,\n\t\t\t\tNonNullable<ChildState>,\n\t\t\t\tChildInternals\n\t\t\t>;\n\t\t};\n\n\t\tconst has = (key: DiceKey) =>\n\t\t\tthis.state$.value && typeof this.state$.value === 'object'\n\t\t\t\t? Object.keys(this.state$.value).includes(key as string)\n\t\t\t\t: false;\n\t\tconst set = (key: DiceKey, data: ChildState) => {\n\t\t\tthis.defineKeyAction.next({ key, data });\n\t\t};\n\t\tconst remove = (key: DiceKey) => {\n\t\t\tthis.deleteKeyAction.next(key);\n\t\t};\n\t\tconst keys = () => diceConstructOptions.getAllKeys(this.value);\n\t\tconst getNextKey = () => diceConstructOptions.getNextKey(keys());\n\t\tconst add = (data: ChildState) => {\n\t\t\tthis.defineKeyAction.next({ key: getNextKey(), data });\n\t\t};\n\t\tconst create = () => {\n\t\t\tthis.defineKeyAction.next({ key: getNextKey(), data: undefined });\n\t\t};\n\n\t\tconst keys$ = this.pipe(\n\t\t\tmap((state) => diceConstructOptions.getAllKeys(state)),\n\t\t\tdistinctUntilChanged(fastArrayComparator),\n\t\t);\n\t\tconst items$ = keys$.pipe(\n\t\t\tmap((keys) => keys.map((key) => get(key))),\n\t\t\tswitchMap((slices) => (slices.length > 0 ? combineLatest(slices) : of([]))),\n\t\t);\n\t\tconst count$ = keys$.pipe(map((keys) => keys.length));\n\t\tconst some$ = (predicate: (item: ChildState) => boolean) =>\n\t\t\titems$.pipe(map((items) => items.some(predicate)));\n\t\tconst every$ = (predicate: (item: ChildState) => boolean) =>\n\t\t\titems$.pipe(map((items) => items.every(predicate)));\n\n\t\tconst selectOnceDefined = (key: DiceKey) =>\n\t\t\tfirstValueFrom(\n\t\t\t\tkeys$.pipe(\n\t\t\t\t\tfilter((keys) => keys.includes(key)),\n\t\t\t\t\tmap(\n\t\t\t\t\t\t() =>\n\t\t\t\t\t\t\tthis.slice(\n\t\t\t\t\t\t\t\tkey as unknown as keyof State,\n\t\t\t\t\t\t\t\tsliceOptions as unknown as SliceOptions<\n\t\t\t\t\t\t\t\t\tState,\n\t\t\t\t\t\t\t\t\tNonNullable<State[keyof State]>,\n\t\t\t\t\t\t\t\t\tChildInternals\n\t\t\t\t\t\t\t\t>,\n\t\t\t\t\t\t\t) as unknown as Slice<\n\t\t\t\t\t\t\t\tState & Record<DiceKey, ChildState>,\n\t\t\t\t\t\t\t\tNonNullable<ChildState>,\n\t\t\t\t\t\t\t\tChildInternals\n\t\t\t\t\t\t\t>,\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t);\n\n\t\treturn {\n\t\t\tslice: this as Slice<unknown, State & Record<DiceKey, ChildState>, Internals>,\n\t\t\tselectOnceDefined,\n\t\t\thas,\n\t\t\tget,\n\t\t\tkeys,\n\t\t\tkeys$,\n\t\t\tcount$,\n\t\t\titems$,\n\t\t\tsome$,\n\t\t\tevery$,\n\t\t\tadd,\n\t\t\tset,\n\t\t\tremove,\n\t\t\tcreate,\n\t\t\tgetNextKey,\n\t\t};\n\t}\n\n\tprivate registerSlice<ChildState, ChildInternals>(\n\t\tsliceRegistration: SliceRegistration<State, ChildState, ChildInternals>,\n\t): void {\n\t\tthis.keyedSlices$.next({\n\t\t\t...this.keyedSlices$.value,\n\t\t\t[sliceRegistration.slice._pathSegment]: sliceRegistration as SliceRegistration<\n\t\t\t\tState,\n\t\t\t\tunknown,\n\t\t\t\tnever\n\t\t\t>,\n\t\t});\n\t\t// If the lazily added subslice is not already merged, merge it back\n\t\tif (\n\t\t\t!hasKey(this.value, sliceRegistration.key) ||\n\t\t\tsliceRegistration.initialState !== sliceRegistration.slicer.selector(this.value)\n\t\t) {\n\t\t\tthis.setAction.next(\n\t\t\t\tsliceRegistration.slicer.merger(\n\t\t\t\t\tthis.value,\n\t\t\t\t\tsliceRegistration.initialState as ChildState,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t *\n\t * @param pathSegment single segment, not the entire absolutePath\n\t */\n\tunregisterSlice(pathSegment: string): void {\n\t\tconst nextSlicesSet = {\n\t\t\t...this.keyedSlices$.value,\n\t\t};\n\t\t// eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n\t\tdelete nextSlicesSet[pathSegment];\n\t\tthis.keyedSlices$.next(nextSlicesSet);\n\t}\n\n\t/**\n\t * Tears down itself and anything below\n\t */\n\tpublic complete(): void {\n\t\tthis.manualPause$.complete();\n\t\tthis.state$.complete();\n\t\tthis.keyedSlices$.complete();\n\t\tthis.plugins$.complete();\n\t\tthis.reducerConfigurations$.complete();\n\n\t\tthis.parentCoupling?.parentSlice.unregisterSlice(this.pathSegment);\n\n\t\tfor (const scopedAction of this.scopedActions) {\n\t\t\tscopedAction.complete();\n\t\t}\n\t\tthis.scope.slices.delete(this._absolutePath);\n\t\tthis.sink.unsubscribe();\n\t}\n\n\tpublic asObservable(): Observable<State> {\n\t\treturn this.pipe();\n\t}\n}\n","import {\n\tasapScheduler,\n\tcatchError,\n\tfinalize,\n\tmap,\n\tObservable,\n\tscheduled,\n\tSubject,\n\tSubscription,\n\ttap,\n} from 'rxjs';\nimport type { ActionConfig } from '../action/action-config.interface.js';\nimport { isActionPacket, type ActionPacket } from '../action/action-packet.interface.js';\nimport { Action, type ActionTuple } from '../action/action.class.js';\nimport { TINYSLICE_PREFIX } from '../helper/index.js';\nimport { Slice, type RootSlice, type RootSliceOptions } from './slice.class.js';\n\n/**\n * Defines a state scope on which actions act upon. The state machine is\n * scheduled by the scopes action dispatcher as reducers and plugins only\n * tick when an action is fired.\n */\nexport class Scope {\n\tprivate readonly schedulingDispatcher: Subject<ActionPacket>;\n\tprivate readonly actionMap = new Map<string, Action<unknown>>();\n\tpublic readonly schedulingDispatcher$: Observable<ActionPacket>;\n\tprivate readonly effectSubscriptions: Subscription;\n\tprivate readonly stores: RootSlice<unknown>[];\n\n\tpublic readonly slices: Map<string, unknown>;\n\n\tpublic constructor() {\n\t\tthis.schedulingDispatcher = new Subject<ActionPacket>();\n\t\tthis.schedulingDispatcher$ = this.schedulingDispatcher.asObservable();\n\t\tthis.actionMap = new Map<string, Action<unknown>>();\n\t\tthis.effectSubscriptions = new Subscription();\n\t\tthis.stores = [];\n\t\tthis.slices = new Map<string, unknown>();\n\t}\n\n\tpublic createAction<Payload = void>(\n\t\ttype: string,\n\t\tconfig?: Partial<ActionConfig>,\n\t): Action<Payload> {\n\t\treturn this.actionMap.has(type)\n\t\t\t? (this.actionMap.get(type) as Action<Payload>)\n\t\t\t: new Action<Payload>(type, config).register(this);\n\t}\n\n\tpublic createRootSlice<State, Internals = unknown>(\n\t\tinitialState: State,\n\t\trootSliceOptions?: RootSliceOptions<State, Internals>,\n\t): RootSlice<State, Internals> {\n\t\treturn Slice.createRootSlice(this, initialState, rootSliceOptions);\n\t}\n\n\t/**\n\t * Using this ensures packets returned by effects are reduced on next tick.\n\t * Otherwise the normal reducer could overwrite whatever the effect\n\t * is producing.\n\t * Let's say you'd write a typical useless machine, if the effect notices\n\t * you set a boolean state to true, it sets it back to false immediately.\n\t * Without this scheduling, the effects result could happen before the\n\t * triggering actions reduce and the state would be left as true.\n\t */\n\tpublic createEffect<Output>(action: Observable<Output | ActionPacket>): Subscription {\n\t\tconst source = scheduled(action, asapScheduler).pipe(\n\t\t\ttap((packet) => {\n\t\t\t\tif (isActionPacket(packet, this.actionMap)) {\n\t\t\t\t\t// Passing it directly to the dispatcher as-is instead of\n\t\t\t\t\t// going through the Action itself to avoid infinite loops.\n\t\t\t\t\tthis.schedulingDispatcher.next(packet);\n\t\t\t\t}\n\t\t\t}),\n\t\t\tcatchError((error, pipeline$) => {\n\t\t\t\tconsole.error(\n\t\t\t\t\t`%c${TINYSLICE_PREFIX} error in effect!\\n`,\n\t\t\t\t\t'background: #222, color: #e00;',\n\t\t\t\t\terror,\n\t\t\t\t);\n\t\t\t\treturn pipeline$;\n\t\t\t}),\n\t\t);\n\n\t\tconst effectSubscription = source.subscribe();\n\t\tthis.effectSubscriptions.add(effectSubscription);\n\t\treturn effectSubscription;\n\t}\n\n\t/**\n\t * Only used for cleanup\n\t */\n\tpublic registerRootSlice(store: RootSlice<unknown>): void {\n\t\tthis.stores.push(store);\n\t}\n\n\tpublic registerAction<Payload>(\n\t\taction: Action<Payload>,\n\t\tregisterFromAction = false,\n\t): Subscription | undefined {\n\t\tif (this.actionMap.has(action.type)) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.actionMap.set(action.type, action as Action<unknown>);\n\n\t\tconst subscription = action.listen$\n\t\t\t.pipe(\n\t\t\t\tmap((payload) => action.makePacket(payload)),\n\t\t\t\tfinalize(() => this.actionMap.delete(action.type)),\n\t\t\t\ttap((next) => {\n\t\t\t\t\tthis.schedulingDispatcher.next(next);\n\t\t\t\t}),\n\t\t\t)\n\t\t\t.subscribe();\n\t\taction.registrations.add(subscription);\n\n\t\tif (!registerFromAction) {\n\t\t\taction.register(this);\n\t\t}\n\n\t\treturn subscription;\n\t}\n\n\tpublic listen$<T extends readonly unknown[]>(\n\t\t...actions: [...ActionTuple<T>]\n\t): Observable<ActionPacket<T[number]>> {\n\t\treturn this.schedulingDispatcher.pipe(Action.makeFilter(...actions));\n\t}\n\n\tpublic listenAll$(): Observable<ActionPacket> {\n\t\treturn this.schedulingDispatcher.asObservable();\n\t}\n\n\tpublic isRegistered<Payload>(action?: Action<Payload> | string): boolean {\n\t\tif (!action) {\n\t\t\treturn false;\n\t\t}\n\t\tconst type = typeof action === 'string' ? action : action.type;\n\t\treturn this.actionMap.has(type);\n\t}\n\n\tget closed(): boolean {\n\t\treturn this.schedulingDispatcher.closed;\n\t}\n\n\tpublic complete(): void {\n\t\tfor (const [, action] of this.actionMap) {\n\t\t\taction.complete();\n\t\t}\n\t\tthis.actionMap.clear();\n\t\tthis.effectSubscriptions.unsubscribe();\n\t\tthis.schedulingDispatcher.complete();\n\t\tfor (const store of this.stores) {\n\t\t\tstore.complete();\n\t\t}\n\t}\n}\n"],"mappings":";;;;AAmBA,IAAa,wBAAsC,EAClD,cAAc,KAAA,EACf;;;ACTA,IAAa,kBACZ,cACA,0BACqC;CACrC,OACC,iBAAiB,KAAA,MAAA,GAAA,kBAAA,aAAA,CACH,aAA8B,IAAI,MAC/C,uBAAuB,IAAK,aAA8B,IAAI,KAAK;AAEtE;;;ACnBA,IAAa,2BAA8B,MAAW,SACrD,KAAK,OAAO,UAAU,KAAK,SAAS,KAAK,CAAC;AAE3C,IAAa,uBAA0B,MAAW,SAAc;CAC/D,IAAI,KAAK,WAAW,KAAK,QACxB,OAAO;MACD,IAAI,KAAK,WAAW,GAC1B,O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