import { Context } from 'react'; import { Dispatch } from 'react'; import { MutableRefObject } from 'react'; import { Pxth } from 'pxth'; import { default as React_2 } from 'react'; import { SetStateAction } from 'react'; export declare const areProxyMapsEqual: (map1: ProxyMapSource, map2: ProxyMapSource) => boolean; /** Object, in which "stocked" calls observers */ declare type BatchUpdate = { /** which paths should be updated */ paths: Pxth[]; /** path, which triggered subtree update */ origin: Pxth; /** all values, which should be sent to observers */ values: T; }; export { BatchUpdate } export { BatchUpdate as BatchUpdate_alias_1 } export { BatchUpdate as BatchUpdate_alias_2 } export declare const createProxyMap: (mapSource: ProxyMapSource) => PxthMap; export declare const getInnerPaths: (path: Pxth, proxyMap: PxthMap>) => [key: any, value: any][]; export declare const hashPxth: (pxth: Pxth) => string; export declare const hasMappedParentPaths: (path: Pxth, proxyMap: PxthMap>) => boolean; /** * Helper function. Calls `standardCallback` if `proxy` is undefined, or if `path` isn't inner path of `proxy.path` variable. * Otherwise, calls `proxiedCallback`. * Passes args into function. */ declare const intercept: any>(proxy: StockProxy | undefined, path: Pxth, standardCallback: T, proxiedCallback: T, args: Parameters) => ReturnType; export { intercept } export { intercept as intercept_alias_1 } /** * Simple example of StockProxy. * Proxies values by map. Map is built by this method: * { * a: { * b: { * c: "" * }, * } * } */ declare class MappingProxy extends StockProxy { private readonly proxyMap; constructor(mapSource: ProxyMapSource, path: Pxth); setValue: (path: Pxth, value: SetStateAction, defaultSetValue: (path: Pxth, value: SetStateAction) => void, defaultGetValue: (path: Pxth) => U) => void; watch: (path: Pxth, observer: Observer, defaultWatch: (path: Pxth, observer: Observer) => () => void) => () => void; watchEffect: (path: Pxth, observer: Observer, defaultWatchEffect: (path: Pxth, observer: Observer) => () => void) => () => void; getValue: (path: Pxth, defaultGetValue: (path: Pxth) => U) => V; private mapValue; getProxiedPath: (path: Pxth) => Pxth; getNormalPath: (path: Pxth) => Pxth; } export { MappingProxy } export { MappingProxy as MappingProxy_alias_1 } export { MappingProxy as MappingProxy_alias_2 } declare type ObjectMappingType = { [P in keyof T]: ProxyMapSource; }; declare type Observer = (message: V) => void; export { Observer } export { Observer as Observer_alias_1 } export { Observer as Observer_alias_2 } declare class ObserverArray { private readonly observers; private counter; /** * Calls all observers in the array. * @param message - message, which would be sent to all observers */ call(message: V): void; /** * Registers new observer and returns key, which will be used for removing observer. * @param observer - registers new observer */ add(observer: Observer): ObserverKey; /** * Removes observer from array. Throws an error, if observer with that key not exists. * @param key - key to observer */ remove(key: ObserverKey): void; /** * Does array include at least one observer or not. */ isEmpty: () => boolean; } export { ObserverArray } export { ObserverArray as ObserverArray_alias_1 } declare type ObserverKey = number; export { ObserverKey } export { ObserverKey as ObserverKey_alias_1 } declare type ObserversControl = { /** * Watch stock value. Returns cleanup function. * @deprecated - use watchEffect instead */ watch: (path: Pxth, observer: Observer) => () => void; /** * Watch all stock values. Returns cleanup function. * @deprecated - use watchEffect instead */ watchAll: (observer: Observer) => () => void; /** Watch stock value. Returns cleanup function. Calls observer instantly. */ watchEffect: (path: Pxth, observer: Observer) => () => void; /** Check if value is observed or not. */ isObserved: (path: Pxth) => boolean; /** Notify all observers, which are children of specified path */ notifySubTree: (path: Pxth, values: T) => void; /** Notify all observers */ notifyAll: (values: T) => void; /** "stocked" updates values in batches, so you can subscribe to batch updates. Returns cleanup. */ watchBatchUpdates: (observer: Observer>) => () => void; }; export { ObserversControl } export { ObserversControl as ObserversControl_alias_1 } export { ObserversControl as ObserversControl_alias_2 } declare type Primitive = string | number | boolean | bigint | symbol | null | undefined; declare const ProxyContext: Context | undefined>; export { ProxyContext } export { ProxyContext as ProxyContext_alias_1 } export { ProxyContext as ProxyContext_alias_2 } declare type ProxyMapSource = T extends Primitive ? Pxth : ObjectMappingType | Pxth; export { ProxyMapSource } export { ProxyMapSource as ProxyMapSource_alias_1 } export { ProxyMapSource as ProxyMapSource_alias_2 } declare const ProxyProvider: ({ proxy, children }: ProxyProviderProps) => React_2.JSX.Element; export { ProxyProvider } export { ProxyProvider as ProxyProvider_alias_1 } export { ProxyProvider as ProxyProvider_alias_2 } declare type ProxyProviderProps = { proxy: StockProxy; children: React_2.ReactNode | ((path: Pxth) => React_2.ReactNode); }; export { ProxyProviderProps } export { ProxyProviderProps as ProxyProviderProps_alias_1 } export { ProxyProviderProps as ProxyProviderProps_alias_2 } declare class PxthMap { private _values; private _keys; get: (key: Pxth) => Value | undefined; set: (key: Pxth, value: Value) => void; remove: (key: Pxth) => void; has: (key: Pxth) => boolean; keys: () => Pxth[]; entries: () => Array<[key: Pxth, value: Value]>; } export { PxthMap } export { PxthMap as PxthMap_alias_1 } export { PxthMap as PxthMap_alias_2 } declare type Stock = { /** Function for setting value. Deeply sets value, using path to variable. @see https://lodash.com/docs/4.17.15#set */ setValue: (path: Pxth, value: SetStateAction) => void; /** Function for setting all values. */ setValues: (values: T) => void; /** Get actual value from stock. */ getValue: (path: Pxth) => V; /** Get all values from stock */ getValues: () => T; /** Function for resetting values to initial state */ resetValues: () => void; /** Paths to all variables */ paths: Pxth; /** Name, which appears in stocked devtools */ debugName?: string; } & Omit, 'notifyAll' | 'notifySubTree'>; export { Stock } export { Stock as Stock_alias_1 } export { Stock as Stock_alias_2 } declare type StockConfig = { initialValues: T; debugName?: string; }; export { StockConfig } export { StockConfig as StockConfig_alias_1 } export { StockConfig as StockConfig_alias_2 } declare const StockContext: Context | undefined>; export { StockContext } export { StockContext as StockContext_alias_1 } export { StockContext as StockContext_alias_2 } /** * Abstract class of "stocked" proxy * By inheriting this class, you can provide custom logic for proxing (casting) values. */ declare abstract class StockProxy { /** Path to variable, where proxy is attached. */ readonly path: Pxth; constructor(path: Pxth); /** Function, which sets proxied value. It will be callen only if proxied value is changing. */ abstract setValue: (path: Pxth, value: SetStateAction, defaultSetValue: (path: Pxth, value: SetStateAction) => void, defaultGetValue: (path: Pxth) => U) => void; /** * Function for watching proxied value. Should return cleanup. * @deprecated */ abstract watch: (path: Pxth, observer: Observer, defaultWatch: (path: Pxth, observer: Observer) => () => void) => () => void; /** Function for watching proxied value. Should return cleanup. Calls observer instantly. */ abstract watchEffect: (path: Pxth, observer: Observer, defaultWatchEffect: (path: Pxth, observer: Observer) => () => void) => () => void; /** Function to access proxied value. */ abstract getValue: (path: Pxth, defaultGetValue: (path: Pxth) => U) => V; /** Function for getting proxied path from normal path. */ abstract getProxiedPath: (path: Pxth) => Pxth; /** Function for getting normal path from proxied path */ abstract getNormalPath: (path: Pxth) => Pxth; /** Activate proxy. After activation, you cannot modify proxy. */ activate: () => Readonly; /** Returns boolean, is proxy active and ready for use or not. */ isActive: () => boolean; } export { StockProxy } export { StockProxy as StockProxy_alias_1 } export { StockProxy as StockProxy_alias_2 } /** * The main component, which should wrap all code, which uses stock values. * Creates stock and puts it in `StockContext`. */ declare const StockRoot: ({ children, ...stockConfig }: StockRootProps) => React_2.JSX.Element; export { StockRoot } export { StockRoot as StockRoot_alias_1 } export { StockRoot as StockRoot_alias_2 } declare type StockRootProps = StockConfig & { children: React_2.ReactNode; }; export { StockRootProps } export { StockRootProps as StockRootProps_alias_1 } export { StockRootProps as StockRootProps_alias_2 } declare const useAllStockValues: (customStock?: Stock, proxy?: StockProxy) => T; export { useAllStockValues } export { useAllStockValues as useAllStockValues_alias_1 } export { useAllStockValues as useAllStockValues_alias_2 } export declare const useDebugStock: (stock: Stock) => void; /** Intercepts stock's `observe`, `stopObserving` and `setValue` functions, if proxy is provided. */ export declare const useInterceptors: (stock: Stock, proxy?: StockProxy) => Stock; /** * Same as `React.useRef` but with lazy initialization. * @param initializer - function, which initializes value. Called once. */ export declare const useLazyRef: (initializer: () => T) => MutableRefObject; declare const useMappingProxy: (mapSource: ProxyMapSource, path: Pxth) => MappingProxy; export { useMappingProxy } export { useMappingProxy as useMappingProxy_alias_1 } export { useMappingProxy as useMappingProxy_alias_2 } /** Hook, wraps functionality of observers storage (add, remove, notify tree of observers, etc.) */ declare const useObservers: (values: MutableRefObject) => ObserversControl; export { useObservers } export { useObservers as useObservers_alias_1 } export { useObservers as useObservers_alias_2 } /** * Creates stock. * * Use it only if you want to use several Stock's at the same time. * * Instead, use `` component * * @param config - configuration of Stock. */ declare const useStock: ({ initialValues, debugName }: StockConfig) => Stock; export { useStock } export { useStock as useStock_alias_1 } export { useStock as useStock_alias_2 } /** * Function to access stock, with automatically applying proxy. By default, will pick stock and proxy from context. * @param stock - optional argument. Pass it if you don't want to use stock from context. * @param proxy - optional argument. Pass it if you don't want to use proxy from context. */ declare const useStockContext: (stock?: Stock, proxy?: StockProxy) => Stock; export { useStockContext } export { useStockContext as useStockContext_alias_1 } export { useStockContext as useStockContext_alias_2 } /** * Hook, returns tuple of value and value set action. * Returns *actual* value. * This means, this hook fires re-render each time value in stock was changed. * Similar to standard React's `useState` hook. * @param path - path to variable in stock, deeply gets value. @see https://lodash.com/docs/4.17.15#get * @param customStock - optional parameter, if you want to work with custom stock, not received from context. @see useStockContext * @param proxy - optional parameter, if you want to pass custom proxy, not receive it from context. @see useStockContext */ declare const useStockState: (path: Pxth, customStock?: Stock, proxy?: StockProxy) => [V, Dispatch>]; export { useStockState } export { useStockState as useStockState_alias_1 } export { useStockState as useStockState_alias_2 } /** * Hook, which returns *actual* stock value. * This means, it will update component each time when value in stock changes. * @param path - path to variable in stock, deeply gets value. @see https://lodash.com/docs/4.17.15#get * @param customStock - optional parameter, if you want to work with custom stock, not received from context. @see useStockContext * @param proxy - optional parameter, if you want to pass custom proxy, not receive it from context. @see useStockContext */ declare const useStockValue: (path: Pxth, customStock?: Stock, proxy?: StockProxy) => V; export { useStockValue } export { useStockValue as useStockValue_alias_1 } export { useStockValue as useStockValue_alias_2 } export { }