UNPKG

@turbox3d/reactivity

Version:

Large-scale reactive state management library

69 lines (68 loc) 2.68 kB
import { ReactorConfig } from '../decorators/reactor'; import { ComputedOption } from '../decorators/computed'; export declare enum KeyPathType { property = "property", index = "index" } export declare const proxyCache: WeakMap<any, any>; export declare const rawCache: WeakMap<any, any>; export declare const keyPathCache: WeakMap<any, { type: KeyPathType; value: string; }[]>; export declare const collectionTypes: (WeakMapConstructor | WeakSetConstructor)[]; interface DomainContext { isNeedRecord: boolean; } export type NormalCollection = Map<any, any> | Set<any>; export type WeakCollection = WeakMap<any, any> | WeakSet<any>; export type Collection = NormalCollection | WeakCollection; export type MapType = Map<any, any> | WeakMap<any, any>; export type SetType = Set<any> | WeakSet<any>; /** * Framework base class 'Domain', class must be extends this base class which is need to be observable. */ export declare class Domain<S extends object = {}> { $$turboxProperties: { [key in keyof this]?: this[key]; }; private reactorConfigMap; private context; private computedProperties; private currentTarget?; private originalArrayLength?; constructor(); initDomainContext(): DomainContext; propertyGet(key: string, config: ReactorConfig, hasInitializer?: boolean, defaultValue?: any): any; propertySet(key: string, v: any, config: ReactorConfig): void; computedPropertyGet<T>(key: string, options?: ComputedOption, descriptor?: PropertyDescriptor): T; computedPropertySet<T>(key: string, original: any): void; /** * the syntax sweet of updating state out of mutation */ $update<K extends keyof S>(obj: Pick<S, K> | S, actionName?: string, displayName?: string, forceSaveHistory?: boolean, isNeedRecord?: boolean, immediately?: boolean): void; private proxySet; private proxyGet; private proxyDeleteProperty; private proxyOwnKeys; /** * proxy value could be * boolean, string, number, undefined, null, custom instance, array[], plainObject{}, Map, Set, WeakMap, WeakSet */ private proxyReactive; private getCollectionHandlerMap; private collectionProxyHandler; /** * observed value could be assigned value to @reactor only in @mutation/$update, otherwise throw error. */ private illegalAssignmentCheck; private dispatch; } interface DomainConfig<R, M, C, A> { reactor: R; mutation: M; computed?: C; action?: A; } export declare function createDomain<R extends object, M extends object, C extends object = {}, A extends object = {}>(domainConfig: DomainConfig<R, M, C, A>): Domain<R>; export {};