cross-state 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +63 -0
- package/dist/cjs/hash.cjs +632 -0
- package/dist/cjs/hash.cjs.map +1 -0
- package/dist/cjs/immer.cjs +10 -0
- package/dist/cjs/immer.cjs.map +1 -0
- package/dist/cjs/index.cjs +286 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/react.cjs +220 -0
- package/dist/cjs/react.cjs.map +1 -0
- package/dist/es/hash.mjs +633 -0
- package/dist/es/hash.mjs.map +1 -0
- package/dist/es/immer.mjs +10 -0
- package/dist/es/immer.mjs.map +1 -0
- package/dist/es/index.mjs +287 -0
- package/dist/es/index.mjs.map +1 -0
- package/dist/es/react.mjs +220 -0
- package/dist/es/react.mjs.map +1 -0
- package/dist/types/core/commonTypes.d.ts +51 -0
- package/dist/types/core/derivedStore.d.ts +39 -0
- package/dist/types/core/fetchStore.d.ts +76 -0
- package/dist/types/core/index.d.ts +10 -0
- package/dist/types/core/once.d.ts +13 -0
- package/dist/types/core/resourceGroup.d.ts +9 -0
- package/dist/types/core/store.d.ts +58 -0
- package/dist/types/core/storeScope.d.ts +4 -0
- package/dist/types/immer/immerActions.d.ts +5 -0
- package/dist/types/immer/index.d.ts +1 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/lib/bind.d.ts +1 -0
- package/dist/types/lib/cache.d.ts +17 -0
- package/dist/types/lib/calcDuration.d.ts +2 -0
- package/dist/types/lib/calculationHelper.d.ts +22 -0
- package/dist/types/lib/diff.d.ts +7 -0
- package/dist/types/lib/equals.d.ts +3 -0
- package/dist/types/lib/forwardError.d.ts +1 -0
- package/dist/types/lib/hash.d.ts +1 -0
- package/dist/types/lib/makeSelector.d.ts +1 -0
- package/dist/types/lib/maybePromise.d.ts +1 -0
- package/dist/types/lib/propAccess.d.ts +13 -0
- package/dist/types/lib/queue.d.ts +9 -0
- package/dist/types/lib/storeActions.d.ts +26 -0
- package/dist/types/lib/throttle.d.ts +1 -0
- package/dist/types/lib/trackingProxy.d.ts +2 -0
- package/dist/types/lib/unwrapPromise.d.ts +1 -0
- package/dist/types/react/index.d.ts +5 -0
- package/dist/types/react/read.d.ts +4 -0
- package/dist/types/react/storeScope.d.ts +12 -0
- package/dist/types/react/useProp.d.ts +4 -0
- package/dist/types/react/useStore.d.ts +4 -0
- package/package.json +112 -0
- package/react.d.ts +1 -0
- package/react.js +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.mjs","sources":["../../src/react/storeScope.tsx","../../node_modules/.pnpm/use-sync-external-store@1.2.0_react@18.2.0/node_modules/use-sync-external-store/cjs/use-sync-external-store-with-selector.production.min.js","../../node_modules/.pnpm/use-sync-external-store@1.2.0_react@18.2.0/node_modules/use-sync-external-store/cjs/use-sync-external-store-with-selector.development.js","../../node_modules/.pnpm/use-sync-external-store@1.2.0_react@18.2.0/node_modules/use-sync-external-store/with-selector.js","../../src/react/useStore.ts","../../src/react/useProp.ts"],"sourcesContent":["import type { Store } from '@core/store';\nimport { store } from '@core/store';\nimport type { StoreScope } from '@core/storeScope';\nimport type { Context, ReactNode } from 'react';\nimport { createContext, useContext, useMemo } from 'react';\n\nexport type StoreScopeProps<T> = { scope: StoreScope<T>; store?: Store<T>; children?: ReactNode };\n\nexport const contextMap = new WeakMap<StoreScope<any>, Context<Store<any>>>();\n\nexport function getStoreScopeContext<T>(scope: StoreScope<T>): Context<Store<T>> {\n let context = contextMap.get(scope);\n\n if (!context) {\n context = createContext<Store<T>>(store(scope.defaultValue));\n contextMap.set(scope, context);\n }\n\n return context;\n}\n\nexport function StoreScopeProvider<T>({ scope, store: inputStore, children }: StoreScopeProps<T>) {\n const context = getStoreScopeContext(scope);\n const currentStore = useMemo(() => inputStore ?? store(scope.defaultValue), [scope, inputStore]);\n\n return <context.Provider value={currentStore}>{children}</context.Provider>;\n}\n\nexport function useStoreScope<T>(scope: StoreScope<T>): Store<T> {\n const context = getStoreScopeContext(scope);\n return useContext(context);\n}\n","/**\n * @license React\n * use-sync-external-store-with-selector.production.min.js\n *\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n'use strict';var g=require(\"react\");function n(a,b){return a===b&&(0!==a||1/a===1/b)||a!==a&&b!==b}var p=\"function\"===typeof Object.is?Object.is:n,q=g.useSyncExternalStore,r=g.useRef,t=g.useEffect,u=g.useMemo,v=g.useDebugValue;\nexports.useSyncExternalStoreWithSelector=function(a,b,e,l,h){var c=r(null);if(null===c.current){var f={hasValue:!1,value:null};c.current=f}else f=c.current;c=u(function(){function a(a){if(!c){c=!0;d=a;a=l(a);if(void 0!==h&&f.hasValue){var b=f.value;if(h(b,a))return k=b}return k=a}b=k;if(p(d,a))return b;var e=l(a);if(void 0!==h&&h(b,e))return b;d=a;return k=e}var c=!1,d,k,m=void 0===e?null:e;return[function(){return a(b())},null===m?void 0:function(){return a(m())}]},[b,e,l,h]);var d=q(a,c[0],c[1]);\nt(function(){f.hasValue=!0;f.value=d},[d]);v(d);return d};\n","/**\n * @license React\n * use-sync-external-store-with-selector.development.js\n *\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n'use strict';\n\nif (process.env.NODE_ENV !== \"production\") {\n (function() {\n\n 'use strict';\n\n/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */\nif (\n typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&\n typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart ===\n 'function'\n) {\n __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());\n}\n var React = require('react');\n\n/**\n * inlined Object.is polyfill to avoid requiring consumers ship their own\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is\n */\nfunction is(x, y) {\n return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare\n ;\n}\n\nvar objectIs = typeof Object.is === 'function' ? Object.is : is;\n\nvar useSyncExternalStore = React.useSyncExternalStore;\n\n// for CommonJS interop.\n\nvar useRef = React.useRef,\n useEffect = React.useEffect,\n useMemo = React.useMemo,\n useDebugValue = React.useDebugValue; // Same as useSyncExternalStore, but supports selector and isEqual arguments.\n\nfunction useSyncExternalStoreWithSelector(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) {\n // Use this to track the rendered snapshot.\n var instRef = useRef(null);\n var inst;\n\n if (instRef.current === null) {\n inst = {\n hasValue: false,\n value: null\n };\n instRef.current = inst;\n } else {\n inst = instRef.current;\n }\n\n var _useMemo = useMemo(function () {\n // Track the memoized state using closure variables that are local to this\n // memoized instance of a getSnapshot function. Intentionally not using a\n // useRef hook, because that state would be shared across all concurrent\n // copies of the hook/component.\n var hasMemo = false;\n var memoizedSnapshot;\n var memoizedSelection;\n\n var memoizedSelector = function (nextSnapshot) {\n if (!hasMemo) {\n // The first time the hook is called, there is no memoized result.\n hasMemo = true;\n memoizedSnapshot = nextSnapshot;\n\n var _nextSelection = selector(nextSnapshot);\n\n if (isEqual !== undefined) {\n // Even if the selector has changed, the currently rendered selection\n // may be equal to the new selection. We should attempt to reuse the\n // current value if possible, to preserve downstream memoizations.\n if (inst.hasValue) {\n var currentSelection = inst.value;\n\n if (isEqual(currentSelection, _nextSelection)) {\n memoizedSelection = currentSelection;\n return currentSelection;\n }\n }\n }\n\n memoizedSelection = _nextSelection;\n return _nextSelection;\n } // We may be able to reuse the previous invocation's result.\n\n\n // We may be able to reuse the previous invocation's result.\n var prevSnapshot = memoizedSnapshot;\n var prevSelection = memoizedSelection;\n\n if (objectIs(prevSnapshot, nextSnapshot)) {\n // The snapshot is the same as last time. Reuse the previous selection.\n return prevSelection;\n } // The snapshot has changed, so we need to compute a new selection.\n\n\n // The snapshot has changed, so we need to compute a new selection.\n var nextSelection = selector(nextSnapshot); // If a custom isEqual function is provided, use that to check if the data\n // has changed. If it hasn't, return the previous selection. That signals\n // to React that the selections are conceptually equal, and we can bail\n // out of rendering.\n\n // If a custom isEqual function is provided, use that to check if the data\n // has changed. If it hasn't, return the previous selection. That signals\n // to React that the selections are conceptually equal, and we can bail\n // out of rendering.\n if (isEqual !== undefined && isEqual(prevSelection, nextSelection)) {\n return prevSelection;\n }\n\n memoizedSnapshot = nextSnapshot;\n memoizedSelection = nextSelection;\n return nextSelection;\n }; // Assigning this to a constant so that Flow knows it can't change.\n\n\n // Assigning this to a constant so that Flow knows it can't change.\n var maybeGetServerSnapshot = getServerSnapshot === undefined ? null : getServerSnapshot;\n\n var getSnapshotWithSelector = function () {\n return memoizedSelector(getSnapshot());\n };\n\n var getServerSnapshotWithSelector = maybeGetServerSnapshot === null ? undefined : function () {\n return memoizedSelector(maybeGetServerSnapshot());\n };\n return [getSnapshotWithSelector, getServerSnapshotWithSelector];\n }, [getSnapshot, getServerSnapshot, selector, isEqual]),\n getSelection = _useMemo[0],\n getServerSelection = _useMemo[1];\n\n var value = useSyncExternalStore(subscribe, getSelection, getServerSelection);\n useEffect(function () {\n inst.hasValue = true;\n inst.value = value;\n }, [value]);\n useDebugValue(value);\n return value;\n}\n\nexports.useSyncExternalStoreWithSelector = useSyncExternalStoreWithSelector;\n /* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */\nif (\n typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&\n typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop ===\n 'function'\n) {\n __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());\n}\n \n })();\n}\n","'use strict';\n\nif (process.env.NODE_ENV === 'production') {\n module.exports = require('./cjs/use-sync-external-store-with-selector.production.min.js');\n} else {\n module.exports = require('./cjs/use-sync-external-store-with-selector.development.js');\n}\n","import type { SubscribeOptions } from '@core/commonTypes';\nimport type { Store } from '@core/store';\nimport { hash } from '@lib/hash';\nimport { trackingProxy } from '@lib/trackingProxy';\nimport { useCallback, useDebugValue, useLayoutEffect, useRef } from 'react';\nimport { useSyncExternalStoreWithSelector } from 'use-sync-external-store/with-selector';\n\nexport type UseStoreOptions = Omit<SubscribeOptions, 'runNow'>;\n\nexport function useStore<T>(store: Store<T>, options?: UseStoreOptions): T {\n const lastEqualsRef = useRef<(newValue: T) => boolean>();\n\n const subOptions = { ...options, runNow: false, equals: undefined };\n\n const subscribe = useCallback(\n (listener: () => void) => {\n return store.sub(listener, subOptions);\n },\n [store, hash(subOptions)]\n );\n\n const value = useSyncExternalStoreWithSelector(\n //\n subscribe,\n store.get,\n undefined,\n (x) => x,\n options?.equals ?? ((_v, newValue) => lastEqualsRef.current?.(newValue) ?? false)\n );\n const [proxiedValue, equals] = trackingProxy(value);\n\n useLayoutEffect(() => {\n lastEqualsRef.current = equals;\n });\n\n useDebugValue(value);\n return proxiedValue;\n}\n","import type { Store } from '@core/store';\nimport type { UpdateFn } from '@core/commonTypes';\nimport type { UseStoreOptions } from './useStore';\nimport { useStore } from './useStore';\n\nexport function useProp<T>(store: Store<T>, options?: UseStoreOptions): [value: T, setValue: UpdateFn<T>] {\n const value = useStore(store, options);\n\n return [value, store.update];\n}\n"],"names":["a","c","d","b","e","useRef","useMemo","useDebugValue","require$$0","require$$1","store","useSyncExternalStoreWithSelector"],"mappings":";;;AAQa,MAAA,iCAAiB;AAEvB,SAAS,qBAAwB,OAAyC;AAC3E,MAAA,UAAU,WAAW,IAAI,KAAK;AAElC,MAAI,CAAC,SAAS;AACZ,cAAU,cAAwB,MAAM,MAAM,YAAY,CAAC;AAChD,eAAA,IAAI,OAAO,OAAO;AAAA,EAC/B;AAEO,SAAA;AACT;AAEO,SAAS,mBAAsB,EAAE,OAAO,OAAO,YAAY,YAAgC;AAC1F,QAAA,UAAU,qBAAqB,KAAK;AACpC,QAAA,eAAe,QAAQ,MAAM,cAAc,MAAM,MAAM,YAAY,GAAG,CAAC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C,YACF;AACA,uCAA+B,2BAA2B,IAAI,MAAK,CAAE;AAAA,MACtE;AAAA,IAED;EACA;;;;ACjKA,MAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,WAAA,UAAiBC;EACnB,OAAO;AACL,WAAA,UAAiBC;EACnB;;ACGgB,SAAA,SAAYC,QAAiB,SAA8B;AACzE,QAAM,gBAAgB;AAEtB,QAAM,aAAa,EAAE,GAAG,SAAS,QAAQ,OAAO,QAAQ;AAExD,QAAM,YAAY;AAAA,IAChB,CAAC,aAAyB;AACjB,aAAAA,OAAM,IAAI,UAAU,UAAU;AAAA,IACvC;AAAA,IACA,CAACA,QAAO,KAAK,UAAU,CAAC;AAAA,EAAA;AAG1B,QAAM,QAAQC,oBAAA;AAAA,IAEZ;AAAA,IACAD,OAAM;AAAA,IACN;AAAA,IACA,CAAC,MAAM;AAAA,KACP,mCAAS,YAAW,CAAC,IAAI,aAAa;;AAAA,kCAAc,YAAd,uCAAwB,cAAa;AAAA;AAAA,EAAA;AAE7E,QAAM,CAAC,cAAc,MAAM,IAAI,cAAc,KAAK;AAElD,kBAAgB,MAAM;AACpB,kBAAc,UAAU;AAAA,EAAA,CACzB;AAED,gBAAc,KAAK;AACZ,SAAA;AACT;AChCgB,SAAA,QAAWA,QAAiB,SAA8D;AAClG,QAAA,QAAQ,SAASA,QAAO,OAAO;AAE9B,SAAA,CAAC,OAAOA,OAAM,MAAM;AAC7B;"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { FetchStore } from './fetchStore';
|
|
2
|
+
import type { Store } from './store';
|
|
3
|
+
export interface Listener<T = void> {
|
|
4
|
+
(value: T, previouseValue?: T): void;
|
|
5
|
+
}
|
|
6
|
+
export interface Selector<T, S> {
|
|
7
|
+
(value: T): S;
|
|
8
|
+
}
|
|
9
|
+
export interface Effect {
|
|
10
|
+
(): void | Cancel;
|
|
11
|
+
}
|
|
12
|
+
export interface SubscribeOptions {
|
|
13
|
+
/** Whether to execute the callback immediately with the current store value.
|
|
14
|
+
* @default true
|
|
15
|
+
*/
|
|
16
|
+
runNow?: boolean;
|
|
17
|
+
/** If set, throttle how often the callback can be executed.
|
|
18
|
+
* The values says how much time needs to pass between to calls.
|
|
19
|
+
* @example
|
|
20
|
+
* subscribe(callback, { throttle: { seconds: 10 } }); // Will execute immediately and then at least 10 seconds havbe to pass. If the store changed during those 10 seconds, the callback will be executed again.
|
|
21
|
+
*/
|
|
22
|
+
throttle?: Duration;
|
|
23
|
+
/** Provide a custom equality function. By default a strict equals (===) will be used.
|
|
24
|
+
*/
|
|
25
|
+
equals?: (a: any, b: any) => boolean;
|
|
26
|
+
tag?: any;
|
|
27
|
+
}
|
|
28
|
+
export interface Cancel {
|
|
29
|
+
(): void;
|
|
30
|
+
}
|
|
31
|
+
export type Duration = number | {
|
|
32
|
+
milliseconds?: number;
|
|
33
|
+
seconds?: number;
|
|
34
|
+
minutes?: number;
|
|
35
|
+
hours?: number;
|
|
36
|
+
days?: number;
|
|
37
|
+
};
|
|
38
|
+
export type UpdateFrom<Value, From extends any[]> = Value | ((...args: From) => Value);
|
|
39
|
+
export type Update<Value> = UpdateFrom<Value, [Value]>;
|
|
40
|
+
export interface UpdateFn<Value> {
|
|
41
|
+
(update: Update<Value>): void;
|
|
42
|
+
}
|
|
43
|
+
export interface UseOptions {
|
|
44
|
+
disableProxy?: boolean;
|
|
45
|
+
}
|
|
46
|
+
export interface Use {
|
|
47
|
+
<T>(store: Store<T>, options?: UseOptions): T;
|
|
48
|
+
}
|
|
49
|
+
export interface UseFetch {
|
|
50
|
+
<T>(fetchStore: FetchStore<T>): Promise<T>;
|
|
51
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { CalculationHelper } from '../lib/calculationHelper';
|
|
2
|
+
import type { Path, Value } from '../lib/propAccess';
|
|
3
|
+
import type { Cancel, Selector, Update, Use } from './commonTypes';
|
|
4
|
+
import { Store } from './store';
|
|
5
|
+
export declare class DerivedStore<T> extends Store<T> {
|
|
6
|
+
protected calculate: (this: {
|
|
7
|
+
use: Use;
|
|
8
|
+
}, fns: {
|
|
9
|
+
use: Use;
|
|
10
|
+
}) => T;
|
|
11
|
+
protected derivedFrom?: {
|
|
12
|
+
store: Store<any>;
|
|
13
|
+
selectors: (Selector<any, any> | string)[];
|
|
14
|
+
} | undefined;
|
|
15
|
+
calculationHelper: CalculationHelper<T>;
|
|
16
|
+
protected valid: boolean;
|
|
17
|
+
protected check?: () => void;
|
|
18
|
+
protected cancel?: Cancel;
|
|
19
|
+
constructor(calculate: (this: {
|
|
20
|
+
use: Use;
|
|
21
|
+
}, fns: {
|
|
22
|
+
use: Use;
|
|
23
|
+
}) => T, derivedFrom?: {
|
|
24
|
+
store: Store<any>;
|
|
25
|
+
selectors: (Selector<any, any> | string)[];
|
|
26
|
+
} | undefined);
|
|
27
|
+
get(): T;
|
|
28
|
+
update(update: Update<T>): void;
|
|
29
|
+
map<S>(selector: Selector<T, S>): DerivedStore<S>;
|
|
30
|
+
map<P extends Path<T>>(selector: P): DerivedStore<Value<T, P>>;
|
|
31
|
+
protected invalidate(): void;
|
|
32
|
+
}
|
|
33
|
+
declare function _derivedStore<T>(calculate: (this: {
|
|
34
|
+
use: Use;
|
|
35
|
+
}, fns: {
|
|
36
|
+
use: Use;
|
|
37
|
+
}) => T): DerivedStore<T>;
|
|
38
|
+
export declare const derivedStore: typeof _derivedStore;
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { CalculationHelper } from '../lib/calculationHelper';
|
|
2
|
+
import type { Path, Value } from '../lib/propAccess';
|
|
3
|
+
import type { Cancel, Duration, Listener, Selector, SubscribeOptions, Update, Use, UseFetch } from './commonTypes';
|
|
4
|
+
import type { ResourceGroup } from './resourceGroup';
|
|
5
|
+
import { Store } from './store';
|
|
6
|
+
type Common<T> = {
|
|
7
|
+
isUpdating: false;
|
|
8
|
+
update?: undefined;
|
|
9
|
+
ref: unknown;
|
|
10
|
+
} | {
|
|
11
|
+
isUpdating: true;
|
|
12
|
+
update: Promise<T>;
|
|
13
|
+
ref: unknown;
|
|
14
|
+
};
|
|
15
|
+
type WithValue<T> = {
|
|
16
|
+
status: 'value';
|
|
17
|
+
value: T;
|
|
18
|
+
error?: undefined;
|
|
19
|
+
isStale: boolean;
|
|
20
|
+
} & Common<T>;
|
|
21
|
+
type WithError<T> = {
|
|
22
|
+
status: 'error';
|
|
23
|
+
value?: undefined;
|
|
24
|
+
error: unknown;
|
|
25
|
+
isStale: boolean;
|
|
26
|
+
} & Common<T>;
|
|
27
|
+
type Pending<T> = {
|
|
28
|
+
status: 'pending';
|
|
29
|
+
value?: undefined;
|
|
30
|
+
error?: undefined;
|
|
31
|
+
isStale: true;
|
|
32
|
+
} & Common<T>;
|
|
33
|
+
export type FetchStoreState<T> = WithValue<T> | WithError<T> | Pending<T>;
|
|
34
|
+
export interface FetchOptions {
|
|
35
|
+
cache?: 'updateWhenStale' | 'backgroundUpdate' | 'forceUpdate';
|
|
36
|
+
}
|
|
37
|
+
export interface FetchFn<T, Args extends any[] = []> {
|
|
38
|
+
(this: {
|
|
39
|
+
use: Use;
|
|
40
|
+
useFetch: UseFetch;
|
|
41
|
+
}, ...args: Args): Promise<T>;
|
|
42
|
+
}
|
|
43
|
+
export interface FetchStoreOptions<T> {
|
|
44
|
+
invalidateAfter?: Duration | ((state: FetchStoreState<T>) => Duration);
|
|
45
|
+
clearAfter?: Duration | ((state: FetchStoreState<T>) => Duration);
|
|
46
|
+
resourceGroup?: ResourceGroup | ResourceGroup[];
|
|
47
|
+
retain?: number;
|
|
48
|
+
clearUnusedAfter?: Duration;
|
|
49
|
+
}
|
|
50
|
+
export declare class FetchStore<T> extends Store<FetchStoreState<T>> {
|
|
51
|
+
protected fetchFn: FetchFn<T>;
|
|
52
|
+
protected options: FetchStoreOptions<T>;
|
|
53
|
+
calculationHelper: CalculationHelper<T>;
|
|
54
|
+
constructor(fetchFn: FetchFn<T>, options?: FetchStoreOptions<T>);
|
|
55
|
+
update(value: Update<FetchStoreState<T>>): void;
|
|
56
|
+
fetch(options?: FetchOptions): Promise<T>;
|
|
57
|
+
setValue(value: T | Promise<T>): void;
|
|
58
|
+
protected setPromise(promise: Promise<T>): void;
|
|
59
|
+
setError(error: unknown): void;
|
|
60
|
+
invalidate(): void;
|
|
61
|
+
clear(): void;
|
|
62
|
+
sub(listener: Listener<FetchStoreState<T>>, options?: SubscribeOptions): Cancel;
|
|
63
|
+
mapValue<S>(selector: Selector<T, S>): FetchStore<S>;
|
|
64
|
+
mapValue<P extends Path<T>>(selector: P): FetchStore<Value<T, P>>;
|
|
65
|
+
}
|
|
66
|
+
declare function create<T>(fetch: FetchFn<T>, options?: FetchStoreOptions<T>): FetchStore<T>;
|
|
67
|
+
declare function withArgs<T, Args extends any[]>(fetch: FetchFn<T, Args>, options?: FetchStoreOptions<T>): {
|
|
68
|
+
(...args: Args): FetchStore<T>;
|
|
69
|
+
invalidate: () => void;
|
|
70
|
+
clear: () => void;
|
|
71
|
+
};
|
|
72
|
+
export declare const fetchStore: typeof create & {
|
|
73
|
+
withArgs: typeof withArgs;
|
|
74
|
+
defaultOptions: FetchStoreOptions<unknown>;
|
|
75
|
+
};
|
|
76
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type { Cancel, Duration, Effect, Listener, SubscribeOptions } from './commonTypes';
|
|
2
|
+
export { derivedStore } from './derivedStore';
|
|
3
|
+
export type { DerivedStore } from './derivedStore';
|
|
4
|
+
export { fetchStore } from './fetchStore';
|
|
5
|
+
export type { FetchFn, FetchOptions, FetchStore, FetchStoreOptions, FetchStoreState } from './fetchStore';
|
|
6
|
+
export { once } from './once';
|
|
7
|
+
export { allResources, ResourceGroup } from './resourceGroup';
|
|
8
|
+
export type { Resource } from './resourceGroup';
|
|
9
|
+
export { store } from './store';
|
|
10
|
+
export type { BoundStoreActions, Store, StoreActions, StoreOptions, StoreOptionsWithActions } from './store';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Cancel, Listener } from './commonTypes';
|
|
2
|
+
interface Subscribe<T> {
|
|
3
|
+
(listener: Listener<T>, options?: {
|
|
4
|
+
runNow?: boolean;
|
|
5
|
+
}): Cancel;
|
|
6
|
+
}
|
|
7
|
+
export declare function once<T, S extends T>(subscribe: Subscribe<T>, condition: (value: T) => value is S): Promise<S>;
|
|
8
|
+
export declare function once<T>(subscribe: Subscribe<T>, condition?: (value: T) => boolean): Promise<T>;
|
|
9
|
+
export declare function onceValue<T>(subscribe: Subscribe<{
|
|
10
|
+
value?: T;
|
|
11
|
+
error?: unknown;
|
|
12
|
+
}>): Promise<T>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { Path, Value } from '../lib/propAccess';
|
|
2
|
+
import { arrayActions, mapActions, recordActions, setActions } from '../lib/storeActions';
|
|
3
|
+
import type { Cancel, Duration, Effect, Listener, Selector, SubscribeOptions, Update, Use, UseOptions } from './commonTypes';
|
|
4
|
+
import { DerivedStore } from './derivedStore';
|
|
5
|
+
export type StoreActions = Record<string, (...args: any[]) => any>;
|
|
6
|
+
export type BoundStoreActions<T, Actions extends StoreActions> = Actions & ThisType<Store<T> & Actions>;
|
|
7
|
+
export interface StoreOptions {
|
|
8
|
+
retain?: number;
|
|
9
|
+
}
|
|
10
|
+
export interface StoreOptionsWithActions<T, Actions extends StoreActions> extends StoreOptions {
|
|
11
|
+
methods?: Actions & ThisType<Store<T> & Actions & StandardActions<T>>;
|
|
12
|
+
}
|
|
13
|
+
type StandardActions<T> = T extends Map<any, any> ? typeof mapActions : T extends Set<any> ? typeof setActions : T extends Array<any> ? typeof arrayActions : T extends Record<any, any> ? typeof recordActions : Record<string, never>;
|
|
14
|
+
type StoreWithActions<T, Actions extends StoreActions> = Store<T> & Omit<BoundStoreActions<T, Actions>, keyof Store<T>> & StandardActions<T>;
|
|
15
|
+
export declare class Store<T> {
|
|
16
|
+
protected readonly initialValue: T;
|
|
17
|
+
protected readonly options: StoreOptions;
|
|
18
|
+
protected value: T;
|
|
19
|
+
protected listeners: Set<Listener<void>>;
|
|
20
|
+
protected effects: Map<Effect, {
|
|
21
|
+
handle?: Cancel | undefined;
|
|
22
|
+
retain?: number | undefined;
|
|
23
|
+
timeout?: number | undefined;
|
|
24
|
+
}>;
|
|
25
|
+
protected notifyId: {};
|
|
26
|
+
constructor(initialValue: T, options?: StoreOptions);
|
|
27
|
+
get(): T;
|
|
28
|
+
update(update: Update<T>): void;
|
|
29
|
+
sub(listener: Listener<T>, options?: SubscribeOptions): Cancel;
|
|
30
|
+
map<S>(selector: Selector<T, S>, options?: UseOptions): DerivedStore<S>;
|
|
31
|
+
map<P extends Path<T>>(selector: P, options?: UseOptions): DerivedStore<Value<T, P>>;
|
|
32
|
+
/** Add an effect that will be executed when the store becomes active, which means when it has at least one subscriber.
|
|
33
|
+
* @param effect
|
|
34
|
+
* If there is already a subscriber, the effect will be executed immediately.
|
|
35
|
+
* Otherweise it will be executed as soon as the first subscription is created.
|
|
36
|
+
* Every time all subscriptions are removed and the first is created again, the effect will be executed again.
|
|
37
|
+
* @param retain
|
|
38
|
+
* If provided, delay tearing down effects when the last subscriber is removed. This is useful if a short gap in subscriber coverage is supposed to be ignored. E.g. when switching pages, the old page might unsubscribe, while the new page subscribes immediately after.
|
|
39
|
+
* @returns
|
|
40
|
+
* The effect can return a teardown callback, which will be executed when the last subscription is removed and potentially the ratain time has passed.
|
|
41
|
+
*/
|
|
42
|
+
addEffect(effect: Effect, retain?: Duration): () => void;
|
|
43
|
+
/** Return whether the store is currently active, which means whether it has at least one subscriber. */
|
|
44
|
+
get isActive(): boolean;
|
|
45
|
+
protected onSubscribe(): void;
|
|
46
|
+
protected onUnsubscribe(): void;
|
|
47
|
+
protected notify(): void;
|
|
48
|
+
}
|
|
49
|
+
declare function _store<T>(calculate: (this: {
|
|
50
|
+
use: Use;
|
|
51
|
+
}, fns: {
|
|
52
|
+
use: Use;
|
|
53
|
+
}) => T, options?: StoreOptions): DerivedStore<T>;
|
|
54
|
+
declare function _store<T, Actions extends StoreActions = {}>(initialState: T, options?: StoreOptionsWithActions<T, Actions>): StoreWithActions<T, Actions>;
|
|
55
|
+
export declare const store: typeof _store & {
|
|
56
|
+
defaultOptions: StoreOptions;
|
|
57
|
+
};
|
|
58
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Store } from '../core/store';
|
|
2
|
+
import type { Draft, nothing } from '../immer';
|
|
3
|
+
export declare const immerActions: {
|
|
4
|
+
immerUpdate<T>(this: Store<T>, recipe: (draft: Draft<T>) => void | Draft<T> | (Draft<T> extends undefined ? import("immer/dist/internal").Nothing : never) | undefined): void;
|
|
5
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { immerActions } from './immerActions';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function bind(self: any): void;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare class Cache<Args extends any[], T extends object> {
|
|
2
|
+
private factory;
|
|
3
|
+
private cacheTime?;
|
|
4
|
+
private cache;
|
|
5
|
+
private interval;
|
|
6
|
+
constructor(factory: (...args: Args) => T, cacheTime?: number | undefined);
|
|
7
|
+
cleanup(): void;
|
|
8
|
+
get(...args: Args): T;
|
|
9
|
+
values(): T[];
|
|
10
|
+
stop(): void;
|
|
11
|
+
stats(): {
|
|
12
|
+
count: number;
|
|
13
|
+
withRef: number;
|
|
14
|
+
withWeakRef: number;
|
|
15
|
+
};
|
|
16
|
+
private now;
|
|
17
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Cancel, UpdateFrom, Use, UseFetch } from '../core/commonTypes';
|
|
2
|
+
import type { MaybePromise } from './maybePromise';
|
|
3
|
+
export declare class CalculationHelper<T> {
|
|
4
|
+
private options;
|
|
5
|
+
private current?;
|
|
6
|
+
constructor(options: {
|
|
7
|
+
calculate: (fns: {
|
|
8
|
+
use: Use;
|
|
9
|
+
useFetch: UseFetch;
|
|
10
|
+
updateValue: (update: UpdateFrom<MaybePromise<T>, [T | undefined]>) => void;
|
|
11
|
+
updateError: (error: unknown) => void;
|
|
12
|
+
}) => Cancel | void;
|
|
13
|
+
addEffect: (effect: () => Cancel | void) => Cancel;
|
|
14
|
+
getValue: () => T | undefined;
|
|
15
|
+
setValue?: (value: T) => void;
|
|
16
|
+
setError?: (error: unknown) => void;
|
|
17
|
+
onInvalidate?: () => void;
|
|
18
|
+
});
|
|
19
|
+
execute(): void;
|
|
20
|
+
stop(): void;
|
|
21
|
+
check(): void;
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function forwardError(error: unknown): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function hash(value: unknown): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function makeSelector<T, S>(selector?: ((value: T) => S) | string): (value: T) => S;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type MaybePromise<T> = T | Promise<T>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Update } from '../core/commonTypes';
|
|
2
|
+
type FilterKey<T> = T extends string | number ? T : never;
|
|
3
|
+
type FilterString<T> = T extends string ? T : never;
|
|
4
|
+
export type Obj = Record<string | number, unknown>;
|
|
5
|
+
export type Arr = readonly unknown[];
|
|
6
|
+
type GetKeys<T> = T extends Arr ? T extends readonly [] ? never : '0' extends keyof T ? keyof T & `${number}` : number : keyof T;
|
|
7
|
+
export type Path<T> = 0 extends 1 & T ? string : T extends never ? never : T extends Obj | Arr ? FilterString<keyof {
|
|
8
|
+
[K in FilterKey<GetKeys<T>> as `${K}` | (T[K] extends Obj | Arr | undefined | null ? `${K}.${Path<NonNullable<T[K]>>}` : never)]: 0;
|
|
9
|
+
}> : never;
|
|
10
|
+
export type Value<T, P extends string> = P extends `${infer K}.${infer Rest}` ? T[K & keyof T] extends Obj | Arr ? Value<T[K & keyof T], Rest> : T[K & keyof T] extends Obj | Arr | undefined | null ? Value<NonNullable<T[K & keyof T]>, Rest> | undefined : never : T[P & keyof T];
|
|
11
|
+
export declare function get<T, P extends Path<T>>(obj: T, path: P): Value<T, P>;
|
|
12
|
+
export declare function set<T, P extends Path<T>>(obj: T, path: P, value: Update<Value<T, P>>, rootPath?: P): T;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { MaybePromise } from './maybePromise';
|
|
2
|
+
type Action<T> = () => MaybePromise<T>;
|
|
3
|
+
export interface Queue {
|
|
4
|
+
<T>(action: Action<T>): Promise<T>;
|
|
5
|
+
clear: () => void;
|
|
6
|
+
whenDone: Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
export declare function queue(): Queue;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Update } from '../core/commonTypes';
|
|
2
|
+
import type { Store } from '../core/store';
|
|
3
|
+
export declare const arrayActions: {
|
|
4
|
+
splice: <V>(this: Store<V[]>, start: number, deleteCount: number, ...items: V[]) => V[];
|
|
5
|
+
push: <V_1>(this: Store<V_1[]>, ...args: V_1[]) => number;
|
|
6
|
+
pop: <V_2>(this: Store<V_2[]>) => V_2 | undefined;
|
|
7
|
+
shift: <V_3>(this: Store<V_3[]>) => V_3 | undefined;
|
|
8
|
+
unshift: <V_4>(this: Store<V_4[]>, ...args: V_4[]) => number;
|
|
9
|
+
reverse: <V_5>(this: Store<V_5[]>) => V_5[];
|
|
10
|
+
sort: <V_6>(this: Store<V_6[]>, compareFn?: ((a: V_6, b: V_6) => number) | undefined) => V_6[];
|
|
11
|
+
};
|
|
12
|
+
export declare const recordActions: {
|
|
13
|
+
set<K extends string | number | symbol, V>(this: Store<Record<K, V>>, key: K, value: Update<V>): Store<Record<K, V>>;
|
|
14
|
+
delete<K_1 extends string | number | symbol, V_1>(this: Store<Record<K_1, V_1>>, key: K_1): void;
|
|
15
|
+
clear<K_2 extends string | number | symbol, V_2>(this: Store<Record<K_2, V_2>>): void;
|
|
16
|
+
};
|
|
17
|
+
export declare const mapActions: {
|
|
18
|
+
set<K, V>(this: Store<Map<K, V>>, key: K, value: V): Store<Map<K, V>>;
|
|
19
|
+
delete<K_1, V_1>(this: Store<Map<K_1, V_1>>, key: K_1): boolean;
|
|
20
|
+
clear<K_2, V_2>(this: Store<Map<K_2, V_2>>): void;
|
|
21
|
+
};
|
|
22
|
+
export declare const setActions: {
|
|
23
|
+
add<T>(this: Store<Set<T>>, value: T): void;
|
|
24
|
+
delete<T_1>(this: Store<Set<T_1>>, value: T_1): void;
|
|
25
|
+
clear<T_2>(this: Store<Set<T_2>>): void;
|
|
26
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function throttle<Args extends any[]>(fn: (...args: Args) => void, ms: number): (...args: Args) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type UnwrapPromise<T> = T extends Promise<infer S> ? UnwrapPromise<S> : T;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Store } from '../core/store';
|
|
2
|
+
import type { StoreScope } from '../core/storeScope';
|
|
3
|
+
import type { Context, ReactNode } from '../react';
|
|
4
|
+
export type StoreScopeProps<T> = {
|
|
5
|
+
scope: StoreScope<T>;
|
|
6
|
+
store?: Store<T>;
|
|
7
|
+
children?: ReactNode;
|
|
8
|
+
};
|
|
9
|
+
export declare const contextMap: WeakMap<StoreScope<any>, Context<Store<any>>>;
|
|
10
|
+
export declare function getStoreScopeContext<T>(scope: StoreScope<T>): Context<Store<T>>;
|
|
11
|
+
export declare function StoreScopeProvider<T>({ scope, store: inputStore, children }: StoreScopeProps<T>): JSX.Element;
|
|
12
|
+
export declare function useStoreScope<T>(scope: StoreScope<T>): Store<T>;
|
package/package.json
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "cross-state",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"repository": "schummar/schummar-state",
|
|
5
|
+
"version": "0.6.0",
|
|
6
|
+
"description": "(React) state library",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"main": "dist/cjs/index.cjs",
|
|
9
|
+
"module": "dist/es/index.mjs",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": "./dist/es/index.mjs",
|
|
13
|
+
"require": "./dist/cjs/index.cjs",
|
|
14
|
+
"default": "./dist/es/index.mjs"
|
|
15
|
+
},
|
|
16
|
+
"./react": {
|
|
17
|
+
"import": "./dist/es/react.mjs",
|
|
18
|
+
"require": "./dist/cjs/react.cjs",
|
|
19
|
+
"default": "./dist/es/react.mjs"
|
|
20
|
+
},
|
|
21
|
+
"./immer": {
|
|
22
|
+
"import": "./dist/es/immer.mjs",
|
|
23
|
+
"require": "./dist/cjs/immer.cjs",
|
|
24
|
+
"default": "./dist/es/immer.mjs"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"types": "dist/types/index.d.ts",
|
|
28
|
+
"typesVersions": {
|
|
29
|
+
"*": {
|
|
30
|
+
"*": [
|
|
31
|
+
"dist/types/index.d.ts"
|
|
32
|
+
],
|
|
33
|
+
"react": [
|
|
34
|
+
"dist/types/react/index.d.ts"
|
|
35
|
+
],
|
|
36
|
+
"immer": [
|
|
37
|
+
"dist/types/immer/index.d.ts"
|
|
38
|
+
]
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"author": {
|
|
42
|
+
"name": "Marco Schumacher",
|
|
43
|
+
"email": "marco@schumacher.dev"
|
|
44
|
+
},
|
|
45
|
+
"license": "ISC",
|
|
46
|
+
"scripts": {
|
|
47
|
+
"start": "tsc --watch",
|
|
48
|
+
"build": "runp -k build:clean :p build:compile:*",
|
|
49
|
+
"build:clean": "rimraf dist",
|
|
50
|
+
"build:compile:js": "vite build",
|
|
51
|
+
"build:compile:types": "tsc && tsc-alias",
|
|
52
|
+
"lint": "runp lint:*",
|
|
53
|
+
"lint:eslint": "eslint src",
|
|
54
|
+
"lint:tsc": "tsc --noEmit --emitDeclarationOnly false",
|
|
55
|
+
"lint:tsc:tests": "tsc --noEmit --emitDeclarationOnly false -p test/tsconfig.json",
|
|
56
|
+
"prepublishOnly": "runp lint test build",
|
|
57
|
+
"test": "pnpm test:watch run --coverage",
|
|
58
|
+
"test:watch": "node --expose-gc node_modules/vitest/vitest.mjs",
|
|
59
|
+
"test:export": "pnpm test:watch run --coverage --reporter=verbose --reporter=junit --outputFile=test/testResults.xml"
|
|
60
|
+
},
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"@schummar/runp": "1.8.2",
|
|
63
|
+
"@testing-library/react": "13.4.0",
|
|
64
|
+
"@types/react": "18.0.26",
|
|
65
|
+
"@types/react-dom": "18.0.10",
|
|
66
|
+
"@types/use-sync-external-store": "0.0.3",
|
|
67
|
+
"@typescript-eslint/eslint-plugin": "5.48.1",
|
|
68
|
+
"@typescript-eslint/parser": "5.48.1",
|
|
69
|
+
"@vitejs/plugin-react": "3.0.1",
|
|
70
|
+
"@vitest/coverage-c8": "0.27.1",
|
|
71
|
+
"eslint": "8.32.0",
|
|
72
|
+
"eslint-plugin-import": "2.27.4",
|
|
73
|
+
"fast-equals": "4.0.3",
|
|
74
|
+
"happy-dom": "8.1.4",
|
|
75
|
+
"immer": "9.0.18",
|
|
76
|
+
"prettier": "2.8.3",
|
|
77
|
+
"react": "18.2.0",
|
|
78
|
+
"react-dom": "18.2.0",
|
|
79
|
+
"rimraf": "4.0.7",
|
|
80
|
+
"semantic-release": "20.0.2",
|
|
81
|
+
"tsc-alias": "^1.8.2",
|
|
82
|
+
"typescript": "4.9.4",
|
|
83
|
+
"use-sync-external-store": "1.2.0",
|
|
84
|
+
"vite": "4.0.4",
|
|
85
|
+
"vite-tsconfig-paths": "4.0.3",
|
|
86
|
+
"vitest": "0.27.1"
|
|
87
|
+
},
|
|
88
|
+
"peerDependencies": {
|
|
89
|
+
"@types/react": ">=16.8.0",
|
|
90
|
+
"immer": ">=9.0.0",
|
|
91
|
+
"react": ">=16.8.0"
|
|
92
|
+
},
|
|
93
|
+
"peerDependenciesMeta": {
|
|
94
|
+
"@types/react": {
|
|
95
|
+
"optional": true
|
|
96
|
+
},
|
|
97
|
+
"immer": {
|
|
98
|
+
"optional": true
|
|
99
|
+
},
|
|
100
|
+
"react": {
|
|
101
|
+
"optional": true
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
"files": [
|
|
105
|
+
"dist",
|
|
106
|
+
"react.js",
|
|
107
|
+
"react.d.ts"
|
|
108
|
+
],
|
|
109
|
+
"volta": {
|
|
110
|
+
"node": "18.9.0"
|
|
111
|
+
}
|
|
112
|
+
}
|
package/react.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/types/react';
|
package/react.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/cjs/react.cjs');
|