UNPKG

@rx-angular/state

Version:

@rx-angular/state is a light-weight, flexible, strongly typed and tested tool dedicated to reduce the complexity of managing component state and side effects in angular

33 lines 1.68 kB
import { Observable, OperatorFunction, Subject, Subscription } from 'rxjs'; export type ValuesOf<O> = O[keyof O]; export type KeysOf<O> = keyof O; type InstanceOrType<T> = T extends abstract new (...args: any) => infer R ? R : T; type InferArguments<T> = T extends (...args: infer R) => any ? R : never; type Select<U, K> = K extends keyof U ? U[K] : never; type ExtractString<T extends object> = Extract<keyof T, string>; type FunctionParamsOrValueType<U, K, F> = InferArguments<Select<U, K>> extends never ? [F] : InferArguments<Select<U, K>>; export type Actions = object; export type SubjectMap<T> = { [K in keyof T]: Subject<T[K]>; }; export type EffectMap<T> = { [K in keyof T]: Subscription; }; export type ActionTransforms<T extends object> = Partial<{ [K in keyof T]: (...args: any[]) => T[K]; }>; export type ActionDispatchFn<O extends unknown[]> = (...value: InstanceOrType<O>) => void; export type ActionDispatchers<T extends Actions, U extends object> = { [K in keyof T]: ActionDispatchFn<FunctionParamsOrValueType<U, K, Select<T, K>>>; }; export type ActionObservables<T extends Actions> = { [K in ExtractString<T> as `${K}$`]: Observable<InstanceOrType<T[K]>>; }; export type ActionEffects<T extends Actions, O = T> = { [K in ExtractString<T> as `on${Capitalize<string & K>}`]: <R>(fn: OperatorFunction<T[K], R>, sideEffectFn?: (value: R) => void) => () => void; }; export type RxActions<T extends Actions, U extends object = T> = ActionDispatchers<T, U> & ActionObservables<T> & ActionEffects<T> & ((slice: Partial<T>) => void) & { $: (props: (keyof T)[]) => Observable<ValuesOf<T>>; }; export {}; //# sourceMappingURL=types.d.ts.map