import { Observable, Subscription } from 'rxjs'; import { Action, ActionConfig, ActionPacket } from '../action/index.js'; import { GetNext, NextKeyStrategy } from '../helper/index.js'; import { TinySlicePlugin } from '../plugins/index.js'; import { Merger } from './merger.type.js'; import { MetaReducer, ReduceActionSliceSnapshot, ReducerConfiguration } from './reducer.type.js'; import { Scope } from './scope.class.js'; import { Selector } from './selector.type.js'; import { StrictRuntimeChecks } from './strict-runtime-checks.interface.js'; export type ObjectKey = string | number | symbol; export type UnknownObject = Record; export type SliceDetacher = () => void; export interface DicedSlice { slice: Slice, ParentInternals>; keys: () => DiceKey[]; keys$: Observable; count$: Observable; items$: Observable; some$: (predicate: (item: ChildState) => boolean) => Observable; every$: (predicate: (item: ChildState) => boolean) => Observable; add: (data: ChildState) => void; create: () => void; set: (key: DiceKey, data: ChildState) => void; remove: (key: DiceKey) => void; getNextKey: () => DiceKey; has: (key: DiceKey) => boolean; get: (key: DiceKey) => Slice, NonNullable, ChildInternals>; selectOnceDefined: (key: DiceKey) => Promise, NonNullable, ChildInternals>>; } /** * This type can be used to get the Child slice signature of a diced slice * ```ts * const pieDice = pies$.dice({...}); * DicedSliceChild; // Slice<> * ``` */ export type DicedSliceChild> = ReturnType; export interface SliceCoupling { parentSlice: Slice; rawParentState: Observable; /** * Used to check the lifetime of the slice, once the key itself is removed * from the parent object, the subslice is completed. * Most subslices are attached via a key, only custom select baseds are not. */ key: ObjectKey | undefined; slicer: SelectSlicer; droppable: boolean; } export interface SliceRegistration { slice: Slice; slicer: SelectSlicer; key: ObjectKey | undefined; initialState: State | undefined; } export interface SliceOptions { reducers?: ReducerConfiguration[] | undefined; plugins?: TinySlicePlugin[] | undefined; metaReducers?: MetaReducer[] | undefined; /** * ? Setting the passed slices Internal generic to unknown is crucial for * ? type inference to work */ defineInternals?: ((slice: Slice) => Internals) | undefined; } export interface RootSliceOptions extends SliceOptions { /** * Runtime checks can slow the store down, turn them off in production, * they are all on by default. */ runtimeChecks?: StrictRuntimeChecks; } export type RootSlice = Slice; export interface SliceConstructOptions extends SliceOptions { scope: Scope; initialState: State; parentCoupling?: SliceCoupling; pathSegment: string; } export interface DiceConstructOptions extends SliceOptions { getAllKeys: (state: State) => DiceKey[]; getNextKey: GetNext; } export interface PremadeDiceConstructOptions extends SliceOptions { getNextKeyStrategy?: NextKeyStrategy; dicedSliceOptions?: SliceOptions; } export interface ChildSliceConstructOptions extends SliceOptions { initialState?: State | undefined; /** * Marks if a slice should be dropped when its key is dropped from its * parent. It's generally only safe to do with dynamic slices (dices) * that are only accessed through lazy slice accessors */ droppable: boolean; pathSegment: string; slicer: SelectSlicer; key: ObjectKey | undefined; } export interface SelectSlicer { selector: Selector; merger: Merger; } export interface SliceChange { snapshot: ReduceActionSliceSnapshot; sliceRegistration: SliceRegistration; } /** * TODO: Create a variant where the key must not already be part of ParentState * TODO: and State must not already be a value of ParentState */ export type SliceDirection = string | number | symbol | keyof ParentState | SelectSlicer; export declare const normalizeSliceDirection: (sliceDirection: SliceDirection) => SelectSlicer; /** * It's pizza time! */ export declare class Slice extends Observable { private readonly sink; private options; private scope; private initialState; private parentCoupling; private initialReducers; private initialPlugins; private state$; private _pathSegment; private _absolutePath; setAction: Action; updateAction: Action>; deleteKeyAction: Action; defineKeyAction: Action<{ key: ObjectKey; data: unknown; }>; private observableState$; private defaultReducerConfigurations; private reducerConfigurations$; private autoRegisterReducerActions$; private downStreamReducers$; private sliceReducer$; private sliceReducingActions$; private plugins$; private autoRegisterPlugins$; private nullishParentPause$; private manualPause$; private pause$; private keyedSlices$; private slices$; subscribe: { (observerOrNext?: Partial>> | ((value: NonNullable) => void) | undefined): Subscription; (next?: ((value: NonNullable) => void) | null | undefined, error?: ((error: any) => void) | null, complete?: (() => void) | null): Subscription; }; private parentListener; private inactivePipeline; private activePipeline; private pipeline; private defineInternals; private _internals; private scopedActions; get internals(): Internals; get absolutePath(): string; get pathSegment(): string; /** * For debugging purposes */ printSliceStructure(indentationLevel?: number): void; /** * * @param initialState * @param sliceSegment a string that represents this slice, has to be * unique on it's parent. */ private constructor(); private executeMetaPreReducers; private executeMetaPostReducers; loadAndSetPlugins(...pluginImports: (() => Promise>)[]): Promise[]>; get paused$(): Observable; /** * Unpauses this slice and every child slice recursively */ unpause(): void; /** * Pauses this slice and every child slice recursively */ pause(): void; /** * Effects created here will respond to the pause and unpauseEffects functions. * These effects will also unsubscribe if the slice unsubscribes */ createEffect(packet$: Observable): Subscription; setPlugins(plugins: TinySlicePlugin[]): void; getPlugins(): TinySlicePlugin[]; addPlugin(...plugins: TinySlicePlugin[]): void; getReducers(): ReducerConfiguration[]; /** * This does not disable default redurces. */ setReducers(reducers: ReducerConfiguration[]): void; addReducers(reducers: ReducerConfiguration[]): void; static assembleAbsolutePath(parentAbsolutePath: string, segment: string): string; private static calculateAbsolutePath; private registerPlugin; set(slice: State | undefined): void; update(slice: Partial): void; set value(value: State); get value(): State; private isRootOrParentStateUndefined; static createRootSlice(scope: Scope, initialState: State, sliceOptions?: RootSliceOptions): RootSlice; createAction(name: string, actionOptions?: ActionConfig): Action; private sliceInternal; /** * @deprecated remove this, too much trouble because of selector.toString(), use dice instead */ sliceSelect(selector: Selector, merger: Merger, sliceOptions?: SliceOptions): Slice, ChildInternals>; slice(key: ChildStateKey, sliceOptions?: SliceOptions, ChildInternals>): Slice, ChildInternals>; /** * Adds non-defined "lazy" slices to extend this slice * ? https://github.com/microsoft/TypeScript/issues/42315 * ? key could be restricted to disallow keys of Slice once negated types * ? are implemented in TypeScript */ addSlice(key: AdditionalKey, initialState: ChildState, sliceOptions?: SliceOptions): Slice, NonNullable, ChildInternals>; /** * Adds a new lazy slice then dices it with a number type record, * you can choose between nextKeyStrategies: * - NEXT_SMALLEST * - NEXT_LARGEST, * - CUSTOM * * NEXT_LARGEST is the default as thats the simplest. * * ! make sure key doesn't exist via generics on State once that can be done in TS */ addDicedSlice>(key: Key extends keyof State ? never : Key, initialState: ChildState, diceConstructOptions: PremadeDiceConstructOptions): DicedSlice; /** * This slice type is created on the fly for N subsclices of the same type * great for complex entities that spawn on the fly and have their own * state definition. * * This defines two layers of state at once. The middle layer stores the bottom layers * you can ask for bottom layers lazyly using a selector. You'll then receive the * slice object and, all the other guts you predefined, like state observers, actions, etc * * Actions are automatically scoped to these selected subslices * * Nomenclature: Slicing means to take a single piece of state, dicing is multiple */ dice(initialState: ChildState, diceConstructOptions: DiceConstructOptions): DicedSlice; private registerSlice; /** * * @param pathSegment single segment, not the entire absolutePath */ unregisterSlice(pathSegment: string): void; /** * Tears down itself and anything below */ complete(): void; asObservable(): Observable; } //# sourceMappingURL=slice.class.d.ts.map