cross-state 0.6.3 → 0.6.6
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 +3 -3
- package/dist/cjs/hash.cjs +368 -283
- package/dist/cjs/hash.cjs.map +1 -1
- package/dist/cjs/immer.cjs +1 -1
- package/dist/cjs/immer.cjs.map +1 -1
- package/dist/cjs/index.cjs +186 -174
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/react.cjs +73 -12
- package/dist/cjs/react.cjs.map +1 -1
- package/dist/es/hash.mjs +369 -284
- package/dist/es/hash.mjs.map +1 -1
- package/dist/es/immer.mjs +1 -1
- package/dist/es/immer.mjs.map +1 -1
- package/dist/es/index.mjs +189 -177
- package/dist/es/index.mjs.map +1 -1
- package/dist/es/react.mjs +79 -18
- package/dist/es/react.mjs.map +1 -1
- package/dist/types/core/cache.d.ts +60 -0
- package/dist/types/core/commonTypes.d.ts +5 -5
- package/dist/types/core/index.d.ts +5 -8
- package/dist/types/core/resourceGroup.d.ts +9 -6
- package/dist/types/core/store.d.ts +40 -21
- package/dist/types/immer/immerActions.d.ts +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/lib/applyPatches.d.ts +2 -0
- package/dist/types/lib/cacheState.d.ts +19 -0
- package/dist/types/lib/calculationHelper.d.ts +3 -3
- package/dist/types/lib/clone.d.ts +1 -0
- package/dist/types/lib/debounce.d.ts +6 -0
- package/dist/types/lib/diff.d.ts +14 -7
- package/dist/types/lib/{cache.d.ts → instanceCache.d.ts} +1 -1
- package/dist/types/lib/makeSelector.d.ts +2 -1
- package/dist/types/lib/maybeAsync.d.ts +3 -0
- package/dist/types/lib/path.d.ts +14 -0
- package/dist/types/lib/propAccess.d.ts +5 -12
- package/dist/types/lib/queue.d.ts +4 -2
- package/dist/types/lib/standardMethods.d.ts +25 -0
- package/dist/types/lib/throttle.d.ts +2 -1
- package/dist/types/lib/typeHelpers.d.ts +8 -0
- package/dist/types/persist/index.d.ts +3 -0
- package/dist/types/persist/persist.d.ts +33 -0
- package/dist/types/persist/persistPathHelpers.d.ts +6 -0
- package/dist/types/persist/persistStorage.d.ts +14 -0
- package/dist/types/react/index.d.ts +3 -4
- package/dist/types/react/read.d.ts +3 -4
- package/dist/types/react/storeScope.d.ts +1 -1
- package/dist/types/react/useCache.d.ts +14 -0
- package/dist/types/react/useProp.d.ts +3 -3
- package/dist/types/react/useStore.d.ts +1 -1
- package/package.json +53 -44
- package/dist/types/core/derivedStore.d.ts +0 -38
- package/dist/types/core/fetchStore.d.ts +0 -76
- package/dist/types/core/once.d.ts +0 -13
- package/dist/types/lib/storeActions.d.ts +0 -28
- package/react.d.ts +0 -1
- package/react.js +0 -1
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/lib/cache.ts","../../src/core/resourceGroup.ts","../../src/core/fetchStore.ts","../../src/core/once.ts"],"sourcesContent":["import { hash } from './hash';\n\nexport class Cache<Args extends any[], T extends object> {\n private cache = new Map<string, { t: number; ref?: T; weakRef?: WeakRef<T> }>();\n private interval = this.cacheTime ? setInterval(() => this.cleanup(), Math.max(this.cacheTime / 10, 1)) : undefined;\n\n constructor(private factory: (...args: Args) => T, private cacheTime?: number) {}\n\n cleanup() {\n const cutoff = this.now() - (this.cacheTime ?? 0);\n\n for (const [key, entry] of [...this.cache.entries()]) {\n if (entry.ref && entry.t <= cutoff) {\n delete entry.ref;\n }\n\n if (!entry.ref && !entry.weakRef?.deref()) {\n this.cache.delete(key);\n }\n }\n }\n\n get(...args: Args) {\n const key = hash(args);\n let entry = this.cache.get(key);\n let value = entry?.ref ?? entry?.weakRef?.deref();\n\n if (!entry || !value) {\n value = this.factory(...args);\n entry = {\n t: this.now(),\n ref: value,\n weakRef: typeof WeakRef !== 'undefined' ? new WeakRef(value) : undefined,\n };\n\n this.cache.set(key, entry);\n } else {\n entry.t = this.now();\n entry.ref ?? value;\n }\n\n return value;\n }\n\n values() {\n return [...this.cache.values()].map((entry) => entry.ref ?? entry.weakRef?.deref()).filter((value): value is T => !!value);\n }\n\n stop() {\n if (this.interval) {\n clearInterval(this.interval);\n }\n }\n\n stats() {\n return {\n count: this.cache.size,\n withRef: [...this.cache.values()].filter((x) => !!x.ref).length,\n withWeakRef: [...this.cache.values()].filter((x) => !!x.weakRef?.deref()).length,\n };\n }\n\n private now() {\n return performance.now();\n }\n}\n","export interface Resource {\n invalidate(): void;\n clear(): void;\n}\n\nexport class ResourceGroup extends Set<Resource> {\n invalidateAll() {\n for (const resource of this) {\n resource.invalidate();\n }\n }\n\n clearAll() {\n for (const resource of this) {\n resource.clear();\n }\n }\n}\n\nexport const _allResources = new ResourceGroup();\nexport const allResources = {\n invalidateAll: _allResources.invalidateAll.bind(_allResources),\n clearAll: _allResources.clearAll.bind(_allResources),\n};\n","import { Cache } from '@lib/cache';\nimport { calcDuration } from '@lib/calcDuration';\nimport { CalculationHelper } from '@lib/calculationHelper';\nimport { defaultEquals, simpleShallowEquals } from '@lib/equals';\nimport { makeSelector } from '@lib/makeSelector';\nimport type { Path, Value } from '@lib/propAccess';\nimport type { Cancel, Duration, Listener, Selector, SubscribeOptions, Update, Use, UseFetch } from './commonTypes';\nimport type { ResourceGroup } from './resourceGroup';\nimport { _allResources } from './resourceGroup';\nimport { Store } from './store';\n\ntype Common<T> = { isUpdating: false; update?: undefined; ref: unknown } | { isUpdating: true; update: Promise<T>; ref: unknown };\ntype WithValue<T> = { status: 'value'; value: T; error?: undefined; isStale: boolean } & Common<T>;\ntype WithError<T> = { status: 'error'; value?: undefined; error: unknown; isStale: boolean } & Common<T>;\ntype Pending<T> = { status: 'pending'; value?: undefined; error?: undefined; isStale: true } & Common<T>;\nexport type FetchStoreState<T> = WithValue<T> | WithError<T> | Pending<T>;\n\nexport interface FetchOptions {\n cache?: 'updateWhenStale' | 'backgroundUpdate' | 'forceUpdate';\n}\n\nexport interface FetchFn<T, Args extends any[] = []> {\n (this: { use: Use; useFetch: UseFetch }, ...args: Args): Promise<T>;\n}\n\nexport interface FetchStoreOptions<T> {\n invalidateAfter?: Duration | ((state: FetchStoreState<T>) => Duration);\n clearAfter?: Duration | ((state: FetchStoreState<T>) => Duration);\n resourceGroup?: ResourceGroup | ResourceGroup[];\n retain?: number;\n clearUnusedAfter?: Duration;\n // parentStore?: { store: Store<any>; selectors: (Selector<any, any> | string)[] };\n}\n\nconst fetchStoreStateEquals =\n (equals = defaultEquals) =>\n (a: FetchStoreState<any>, b: FetchStoreState<any>) => {\n const { value: av, ...ar } = a;\n const { value: bv, ...br } = b;\n return simpleShallowEquals(ar, br) && (ar.status !== 'value' || equals(av, bv));\n };\n\nconst createRef = () => Math.random().toString(36).slice(2);\n\nexport class FetchStore<T> extends Store<FetchStoreState<T>> {\n calculationHelper = new CalculationHelper({\n calculate: ({ use, useFetch }) => {\n const promise = this.fetchFn.apply({ use, useFetch });\n this.setPromise(promise);\n },\n\n addEffect: this.addEffect,\n getValue: () => this.value.value,\n setValue: this.setValue,\n setError: this.setError,\n onInvalidate: this.invalidate,\n });\n\n constructor(protected fetchFn: FetchFn<T>, protected options: FetchStoreOptions<T> = {}) {\n super({\n status: 'pending',\n isStale: true,\n isUpdating: false,\n ref: createRef(),\n });\n }\n\n update(value: Update<FetchStoreState<T>>): void {\n this.calculationHelper.stop();\n super.update(value);\n }\n\n async fetch(options?: FetchOptions): Promise<T> {\n this.calculationHelper.check();\n\n const { cache = 'updateWhenStale' } = options ?? {};\n const { status, value, error, update, isStale } = this.value;\n\n if (((status === 'pending' || isStale) && !update) || cache === 'forceUpdate') {\n this.calculationHelper.execute();\n\n if (status === 'pending' || cache !== 'backgroundUpdate') {\n return this.value.update!;\n }\n }\n\n if (status === 'value') {\n return value;\n }\n\n if (status === 'error') {\n throw error;\n }\n\n return update;\n }\n\n setValue(value: T | Promise<T>): void {\n if (value instanceof Promise) {\n this.calculationHelper.stop();\n this.setPromise(value);\n } else {\n this.update({\n status: 'value',\n value,\n isStale: false,\n isUpdating: false,\n ref: createRef(),\n });\n }\n }\n\n protected setPromise(promise: Promise<T>) {\n const ref = createRef();\n\n super.update({\n ...this.value,\n isUpdating: true,\n update: promise,\n ref,\n });\n\n promise\n .then((value) => {\n if (promise === this.value.update) {\n super.update({\n status: 'value',\n value,\n isStale: false,\n isUpdating: false,\n ref,\n });\n }\n })\n .catch((error) => {\n if (promise === this.value.update) {\n super.update({\n status: 'error',\n error,\n isStale: false,\n isUpdating: false,\n ref,\n });\n }\n });\n }\n\n setError(error: unknown): void {\n this.update({\n status: 'error',\n error,\n isStale: false,\n isUpdating: false,\n ref: createRef(),\n });\n }\n\n invalidate(): void {\n this.update({\n ...this.value,\n isStale: true,\n isUpdating: false,\n update: undefined,\n });\n\n if (this.isActive) {\n this.calculationHelper.execute();\n }\n }\n\n clear(): void {\n this.update({\n status: 'pending',\n isStale: true,\n isUpdating: false,\n ref: createRef(),\n });\n\n if (this.isActive) {\n this.calculationHelper.execute();\n }\n }\n\n sub(listener: Listener<FetchStoreState<T>>, options?: SubscribeOptions): Cancel {\n return super.sub(listener, {\n ...options,\n equals: fetchStoreStateEquals(options?.equals),\n });\n }\n\n mapValue<S>(selector: Selector<T, S>): FetchStore<S>;\n mapValue<P extends Path<T>>(selector: P): FetchStore<Value<T, P>>;\n mapValue<S>(_selector: Selector<T, S> | string): FetchStore<S> {\n const selector = makeSelector(_selector);\n const that = this;\n\n return new FetchStore(async function () {\n const value: T = await this.useFetch(that);\n return selector(value);\n });\n }\n}\n\nconst defaultOptions: FetchStoreOptions<unknown> = {};\n\nfunction create<T>(fetch: FetchFn<T>, options?: FetchStoreOptions<T>): FetchStore<T> {\n return withArgs(fetch, options)();\n}\n\nfunction withArgs<T, Args extends any[]>(\n fetch: FetchFn<T, Args>,\n options?: FetchStoreOptions<T>\n): {\n (...args: Args): FetchStore<T>;\n invalidate: () => void;\n clear: () => void;\n} {\n const { clearUnusedAfter = defaultOptions.clearUnusedAfter ?? 0, resourceGroup } = options ?? {};\n\n const cache = new Cache(\n (...args: Args) =>\n new FetchStore(function () {\n return fetch.apply(this, args);\n }, options),\n calcDuration(clearUnusedAfter)\n );\n\n const get = (...args: Args) => {\n return cache.get(...args);\n };\n\n const invalidate = () => {\n for (const instance of cache.values()) {\n instance.invalidate();\n }\n };\n\n const clear = () => {\n for (const instance of cache.values()) {\n instance.clear();\n }\n };\n\n const resource = { invalidate, clear };\n const groups = Array.isArray(resourceGroup) ? resourceGroup : resourceGroup ? [resourceGroup] : [];\n for (const group of groups.concat(_allResources)) {\n group.add(resource);\n }\n\n return Object.assign(get, resource);\n}\n\nexport const fetchStore = Object.assign(create, {\n withArgs,\n defaultOptions,\n});\n","import type { Cancel, Listener } from './commonTypes';\n\ninterface Subscribe<T> {\n (listener: Listener<T>, options?: { runNow?: boolean }): Cancel;\n}\n\nexport function once<T, S extends T>(subscribe: Subscribe<T>, condition: (value: T) => value is S): Promise<S>;\nexport function once<T>(subscribe: Subscribe<T>, condition?: (value: T) => boolean): Promise<T>;\nexport function once<T>(subscribe: Subscribe<T>, condition?: (value: T) => boolean) {\n return new Promise<T>((resolve) => {\n let stopped = false;\n const cancel = subscribe(\n (value) => {\n if (stopped || (condition && !condition(value))) {\n return;\n }\n\n resolve(value);\n stopped = true;\n setTimeout(() => cancel());\n },\n {\n runNow: !!condition,\n }\n );\n });\n}\n\nexport function onceValue<T>(subscribe: Subscribe<{ value?: T; error?: unknown }>): Promise<T> {\n return new Promise<T>((resolve, reject) => {\n let stopped = false;\n const cancel = subscribe(({ value, error }) => {\n if (stopped || (value === undefined && error === undefined)) {\n return;\n }\n\n if (value !== undefined) {\n resolve(value);\n } else {\n reject(error);\n }\n\n stopped = true;\n setTimeout(() => cancel());\n });\n });\n}\n"],"names":["hash","defaultEquals","simpleShallowEquals","Store","CalculationHelper","makeSelector","calcDuration"],"mappings":";;;AAEO,MAAM,MAA4C;AAAA,EAIvD,YAAoB,SAAuC,WAAoB;AAA3D,SAAA,UAAA;AAAuC,SAAA,YA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AU,KAAK,GAAI;AAC/C;AAAA,QACF;AAEA,gBAAQ,KAAK;AACH,kBAAA;AACC,mBAAA,MAAM,QAAQ;AAAA,MAC3B;AAAA,MACA;AAAA,QACE,QAAQ,CAAC,CAAC;AAAA,MACZ;AAAA,IAAA;AAAA,EACF,CACD;AACH;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/core/resourceGroup.ts","../../src/lib/instanceCache.ts","../../src/core/cache.ts"],"sourcesContent":["import { bind } from '@lib/bind';\n\nexport interface Resource {\n invalidate(): void;\n clear(): void;\n}\n\nexport class ResourceGroup {\n private refMap = new WeakMap<Resource, WeakRef<Resource>>();\n\n private refSet = new Set<WeakRef<Resource>>();\n\n constructor(public readonly name?: string) {\n bind(this);\n }\n\n add(resource: Resource) {\n const ref = new WeakRef(resource);\n this.refMap.set(resource, ref);\n this.refSet.add(ref);\n }\n\n delete(resource: Resource) {\n const ref = this.refMap.get(resource);\n if (ref) {\n this.refMap.delete(resource);\n this.refSet.delete(ref);\n }\n }\n\n invalidateAll() {\n for (const ref of this.refSet) {\n const resource = ref.deref();\n if (resource) {\n resource.invalidate();\n } else {\n this.refSet.delete(ref);\n }\n }\n }\n\n clearAll() {\n for (const ref of this.refSet) {\n const resource = ref.deref();\n if (resource) {\n resource.clear();\n } else {\n this.refSet.delete(ref);\n }\n }\n }\n}\n\nexport const allResources = new ResourceGroup();\n\nexport function createResourceGroup(name?: string) {\n return new ResourceGroup(name);\n}\n","import { hash } from './hash';\n\nexport class InstanceCache<Args extends any[], T extends object> {\n private cache = new Map<string, { t: number; ref?: T; weakRef: WeakRef<T> }>();\n\n private interval = this.cacheTime\n ? setInterval(() => this.cleanup(), Math.max(this.cacheTime / 10, 1))\n : undefined;\n\n constructor(private factory: (...args: Args) => T, private cacheTime?: number) {}\n\n cleanup() {\n const cutoff = this.now() - (this.cacheTime ?? 0);\n\n for (const [key, entry] of this.cache.entries()) {\n if (entry.ref && entry.t <= cutoff) {\n delete entry.ref;\n }\n\n if (!entry.ref && !entry.weakRef?.deref()) {\n this.cache.delete(key);\n }\n }\n }\n\n get(...args: Args) {\n const key = hash(args);\n let entry = this.cache.get(key);\n let value = entry?.ref ?? entry?.weakRef?.deref();\n\n if (!entry || !value) {\n value = this.factory(...args);\n entry = {\n t: this.now(),\n ref: value,\n weakRef: new WeakRef(value),\n };\n\n this.cache.set(key, entry);\n } else {\n entry.t = this.now();\n entry.ref ??= value;\n }\n\n return value;\n }\n\n values() {\n return [...this.cache.values()]\n .map((entry) => entry.ref ?? entry.weakRef?.deref())\n .filter((value): value is T => !!value);\n }\n\n stop() {\n if (this.interval) {\n clearInterval(this.interval);\n }\n }\n\n stats() {\n return {\n count: this.cache.size,\n withRef: [...this.cache.values()].filter((x) => !!x.ref).length,\n withWeakRef: [...this.cache.values()].filter((x) => !!x.weakRef?.deref()).length,\n };\n }\n\n private now() {\n return performance.now();\n }\n}\n","import type { Duration, Selector, Use } from './commonTypes';\nimport { allResources, type ResourceGroup } from './resourceGroup';\nimport { createStore, Store } from './store';\nimport type { CacheState, ErrorState, ValueState } from '@lib/cacheState';\nimport { calcDuration } from '@lib/calcDuration';\nimport { InstanceCache } from '@lib/instanceCache';\nimport { makeSelector } from '@lib/makeSelector';\nimport type { Path, Value } from '@lib/path';\n\nexport interface CacheGetOptions {\n update?: 'whenMissing' | 'whenStale' | 'force';\n backgroundUpdate?: boolean;\n}\n\nexport interface CacheFunction<T, Args extends any[] = []> {\n (this: { use: Use }, ...args: Args): Promise<T>;\n}\n\nexport interface CacheOptions<T> {\n invalidateAfter?: Duration | ((state: ValueState<T> | ErrorState) => Duration | undefined);\n clearAfter?: Duration | ((state: ValueState<T> | ErrorState) => Duration | undefined);\n resourceGroup?: ResourceGroup | ResourceGroup[];\n retain?: number;\n clearUnusedAfter?: Duration;\n}\n\nexport class Cache<T> extends Store<Promise<T>> {\n readonly state = createStore<CacheState<T>>({\n status: 'pending',\n isStale: true,\n isUpdating: false,\n });\n\n protected stalePromise?: Promise<T>;\n\n protected timers = new Set<ReturnType<typeof setTimeout>>();\n\n constructor(\n getter: CacheFunction<T>,\n public readonly options: CacheOptions<T> = {},\n public readonly derivedFromCache?: {\n cache: Cache<any>;\n selectors: (Selector<any, any> | Path<any>)[];\n },\n ) {\n super(getter, options);\n this.watchPromise();\n }\n\n get({ update = 'whenStale', backgroundUpdate = false }: CacheGetOptions = {}) {\n const promise = this._value?.v;\n const stalePromise = this.stalePromise;\n\n if (\n (update === 'whenMissing' && !promise && !stalePromise) ||\n (update === 'whenStale' && !promise) ||\n update === 'force'\n ) {\n this.calculationHelper.execute();\n\n if ((!promise && !stalePromise) || !backgroundUpdate) {\n return super.get();\n }\n }\n\n if (!promise || (stalePromise && backgroundUpdate)) {\n return stalePromise!;\n }\n\n return promise;\n }\n\n invalidate({ invalidateDependencies = true }: { invalidateDependencies?: boolean } = {}) {\n if (invalidateDependencies) {\n this.calculationHelper.invalidateDependencies();\n }\n\n const { status, isStale, isUpdating } = this.state.get();\n if (status !== 'pending' && !isStale && !isUpdating) {\n this.stalePromise = this._value?.v;\n }\n\n this.state.set((state) => ({\n ...state,\n isStale: true,\n isUpdating: false,\n }));\n\n super.reset();\n }\n\n clear({ invalidateDependencies = true }: { invalidateDependencies?: boolean } = {}): void {\n if (invalidateDependencies) {\n this.calculationHelper.invalidateDependencies();\n }\n\n this.state.set({\n status: 'pending',\n isStale: true,\n isUpdating: false,\n });\n delete this.stalePromise;\n super.reset();\n }\n\n mapValue<S>(selector: Selector<T, S>): Cache<S>;\n\n mapValue<P extends Path<T>>(selector: P): Cache<Value<T, P>>;\n\n mapValue<S>(_selector: Selector<T, S> | Path<any>): Cache<S> {\n const selector = makeSelector(_selector);\n const derivedFromCache = {\n cache: this.derivedFromCache ? this.derivedFromCache.cache : this,\n selectors: this.derivedFromCache\n ? [...this.derivedFromCache.selectors, _selector]\n : [_selector],\n };\n const that = this;\n\n return new Cache(\n async function () {\n const value = await this.use(that);\n return selector(value);\n },\n {},\n derivedFromCache,\n );\n }\n\n protected watchPromise() {\n this.sub(\n async (promise) => {\n this.state.set((state) => ({\n ...state,\n isUpdating: true,\n }));\n\n this.setTimers();\n\n try {\n const value = await promise;\n\n if (promise !== this._value?.v) {\n return;\n }\n\n this.state.set({\n status: 'value',\n value,\n isStale: false,\n isUpdating: false,\n });\n delete this.stalePromise;\n this.setTimers();\n } catch (error) {\n if (promise !== this._value?.v) {\n return;\n }\n\n this.state.set({\n status: 'error',\n error,\n isStale: false,\n isUpdating: false,\n });\n delete this.stalePromise;\n this.setTimers();\n }\n },\n { passive: true },\n );\n }\n\n protected setTimers() {\n for (const timer of this.timers) {\n clearTimeout(timer);\n }\n this.timers.clear();\n\n const state = this.state.get();\n let { invalidateAfter, clearAfter } = this.options;\n const ref = new WeakRef(this);\n\n if (state.status === 'pending') {\n return;\n }\n\n if (invalidateAfter instanceof Function) {\n invalidateAfter = invalidateAfter(state);\n }\n\n if (invalidateAfter) {\n this.timers.add(setTimeout(() => ref?.deref()?.invalidate(), calcDuration(invalidateAfter)));\n }\n\n if (clearAfter instanceof Function) {\n clearAfter = clearAfter(state);\n }\n\n if (clearAfter) {\n this.timers.add(setTimeout(() => ref?.deref()?.clear(), calcDuration(clearAfter)));\n }\n }\n}\n\nconst defaultOptions: CacheOptions<unknown> = {};\n\nfunction create<T>(cacheFunction: CacheFunction<T>, options?: CacheOptions<T>): Cache<T> {\n return withArgs(cacheFunction, options)();\n}\n\nfunction withArgs<T, Args extends any[]>(\n cacheFunction: CacheFunction<T, Args>,\n options?: CacheOptions<T>,\n): {\n (...args: Args): Cache<T>;\n invalidate: () => void;\n clear: () => void;\n} {\n const { clearUnusedAfter = defaultOptions.clearUnusedAfter ?? 0, resourceGroup } = options ?? {};\n\n const cache = new InstanceCache(\n (...args: Args) =>\n new Cache(function () {\n return cacheFunction.apply(this, args);\n }, options),\n calcDuration(clearUnusedAfter),\n );\n\n const get = (...args: Args) => {\n return cache.get(...args);\n };\n\n const invalidate = () => {\n for (const instance of cache.values()) {\n instance.invalidate();\n }\n };\n\n const clear = () => {\n for (const instance of cache.values()) {\n instance.clear();\n }\n };\n\n const resource = { invalidate, clear };\n const groups = Array.isArray(resourceGroup)\n ? resourceGroup\n : resourceGroup\n ? [resourceGroup]\n : [];\n for (const group of groups.concat(allResources)) {\n group.add(resource);\n }\n\n return Object.assign(get, resource);\n}\n\nexport const createCache = Object.assign(create, {\n withArgs,\n defaultOptions,\n});\n"],"names":["bind","hash","Store","createStore","makeSelector","calcDuration"],"mappings":";;;AAOO,MAAM,cAAc;AAAA,EAKzB,YAA4B,MAAe;AAAf,SAAA,OAAA;AAJpB,SAAA,6BAAa;AAEb,SAAA,6BAAa;AAGnBA,SAAA,KAAK,IAAI;AAAA,EACX;AAAA,EAEA,IAAI,UAAoB;AAChB,UAAA,MAAM,IAAI,QAAQ,QAAQ;AAC3B,SAAA,OAAO,IAAI,UAAU,GAAG;AACxB,SAAA,OAAO,IAAI,GAAG;AAAA,EACrB;AAAA,EAEA,OAAO,UAAoB;AACzB,UAAM,MAAM,KAAK,OAAO,IAAI,QAAQ;AACpC,QAAI,KAAK;AACF,WAAA,OAAO,OAAO,QAAQ;AACtB,WAAA,OAAO,OAAO,GAAG;AAAA,IACxB;AAAA,EACF;AAAA,EAEA,gBAAgB;AACH,eAAA,OAAO,KAAK,QAAQ;AACvB,YAAA,WAAW,IAAI;AACrB,UAAI,UAAU;AACZ,iBAAS,WAAW;AAAA,MAAA,OACf;AACA,aAAA,OAAO,OAAO,GAAG;AAAA,MACxB;AAAA,IACF;AAAA,EACF;AAAA,EAEA,WAAW;AACE,eAAA,OAAO,KAAK,QAAQ;AACvB,YAAA,WAAW,IAAI;AACrB,UAAI,UAAU;AACZ,iBAAS,MAAM;AAAA,MAAA,OACV;AACA,aAAA,OAAO,OAAO,GAAG;AAAA,MACxB;AAAA,IACF;AAAA,EACF;AACF;AAEa,MAAA,eAAe,IAAI,cAAc;AAEvC,SAAS,oBAAoB,MAAe;AAC1C,SAA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C;AAChF,SAAA,SAAS,eAAe,OAAO;AACxC;AAEA,SAAS,SACP,eACA,SAKA;AACM,QAAA,EAAE,mBAAmB,eAAe,oBAAoB,GAAG,cAAc,IAAI,WAAW;AAE9F,QAAM,QAAQ,IAAI;AAAA,IAChB,IAAI,SACF,IAAI,MAAM,WAAY;AACb,aAAA,cAAc,MAAM,MAAM,IAAI;AAAA,OACpC,OAAO;AAAA,IACZA,KAAAA,aAAa,gBAAgB;AAAA,EAAA;AAGzB,QAAA,MAAM,IAAI,SAAe;AACtB,WAAA,MAAM,IAAI,GAAG,IAAI;AAAA,EAAA;AAG1B,QAAM,aAAa,MAAM;AACZ,eAAA,YAAY,MAAM,UAAU;AACrC,eAAS,WAAW;AAAA,IACtB;AAAA,EAAA;AAGF,QAAM,QAAQ,MAAM;AACP,eAAA,YAAY,MAAM,UAAU;AACrC,eAAS,MAAM;AAAA,IACjB;AAAA,EAAA;AAGI,QAAA,WAAW,EAAE,YAAY;AACzB,QAAA,SAAS,MAAM,QAAQ,aAAa,IACtC,gBACA,gBACA,CAAC,aAAa,IACd;AACJ,aAAW,SAAS,OAAO,OAAO,YAAY,GAAG;AAC/C,UAAM,IAAI,QAAQ;AAAA,EACpB;AAEO,SAAA,OAAO,OAAO,KAAK,QAAQ;AACpC;AAEa,MAAA,cAAc,OAAO,OAAO,QAAQ;AAAA,EAC/C;AAAA,EACA;AACF,CAAC;;;;;;;;;;;;;;"}
|
package/dist/cjs/react.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const hash = require("./hash.cjs");
|
|
4
3
|
const require$$0 = require("react");
|
|
4
|
+
const hash = require("./hash.cjs");
|
|
5
5
|
const jsxRuntime = require("react/jsx-runtime");
|
|
6
6
|
var withSelectorExports = {};
|
|
7
7
|
var withSelector = {
|
|
@@ -13,6 +13,15 @@ var withSelector = {
|
|
|
13
13
|
}
|
|
14
14
|
};
|
|
15
15
|
var useSyncExternalStoreWithSelector_production_min = {};
|
|
16
|
+
/**
|
|
17
|
+
* @license React
|
|
18
|
+
* use-sync-external-store-with-selector.production.min.js
|
|
19
|
+
*
|
|
20
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
21
|
+
*
|
|
22
|
+
* This source code is licensed under the MIT license found in the
|
|
23
|
+
* LICENSE file in the root directory of this source tree.
|
|
24
|
+
*/
|
|
16
25
|
var hasRequiredUseSyncExternalStoreWithSelector_production_min;
|
|
17
26
|
function requireUseSyncExternalStoreWithSelector_production_min() {
|
|
18
27
|
if (hasRequiredUseSyncExternalStoreWithSelector_production_min)
|
|
@@ -70,6 +79,15 @@ function requireUseSyncExternalStoreWithSelector_production_min() {
|
|
|
70
79
|
return useSyncExternalStoreWithSelector_production_min;
|
|
71
80
|
}
|
|
72
81
|
var useSyncExternalStoreWithSelector_development = {};
|
|
82
|
+
/**
|
|
83
|
+
* @license React
|
|
84
|
+
* use-sync-external-store-with-selector.development.js
|
|
85
|
+
*
|
|
86
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
87
|
+
*
|
|
88
|
+
* This source code is licensed under the MIT license found in the
|
|
89
|
+
* LICENSE file in the root directory of this source tree.
|
|
90
|
+
*/
|
|
73
91
|
var hasRequiredUseSyncExternalStoreWithSelector_development;
|
|
74
92
|
function requireUseSyncExternalStoreWithSelector_development() {
|
|
75
93
|
if (hasRequiredUseSyncExternalStoreWithSelector_development)
|
|
@@ -167,18 +185,33 @@ function requireUseSyncExternalStoreWithSelector_development() {
|
|
|
167
185
|
})(withSelector);
|
|
168
186
|
function useStore(store, options) {
|
|
169
187
|
const lastEqualsRef = require$$0.useRef();
|
|
170
|
-
const
|
|
188
|
+
const { rootStore, selector } = require$$0.useMemo(() => {
|
|
189
|
+
var _a;
|
|
190
|
+
const rootStore2 = ((_a = store.derivedFrom) == null ? void 0 : _a.store) ?? store;
|
|
191
|
+
let selector2 = (x) => x;
|
|
192
|
+
if (store.derivedFrom) {
|
|
193
|
+
selector2 = (value2) => {
|
|
194
|
+
for (const s of store.derivedFrom.selectors) {
|
|
195
|
+
value2 = hash.makeSelector(s)(value2);
|
|
196
|
+
}
|
|
197
|
+
return value2;
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
return { rootStore: rootStore2, selector: selector2 };
|
|
201
|
+
}, [store]);
|
|
202
|
+
const subOptions = { ...options, runNow: false, equals: void 0, passive: false };
|
|
171
203
|
const subscribe = require$$0.useCallback(
|
|
172
204
|
(listener) => {
|
|
173
|
-
return
|
|
205
|
+
return rootStore.sub(listener, subOptions);
|
|
174
206
|
},
|
|
175
|
-
[
|
|
207
|
+
[rootStore, hash.hash(subOptions)]
|
|
176
208
|
);
|
|
177
209
|
const value = withSelectorExports.useSyncExternalStoreWithSelector(
|
|
210
|
+
//
|
|
178
211
|
subscribe,
|
|
179
|
-
|
|
212
|
+
rootStore.get,
|
|
180
213
|
void 0,
|
|
181
|
-
|
|
214
|
+
selector,
|
|
182
215
|
(options == null ? void 0 : options.equals) ?? ((_v, newValue) => {
|
|
183
216
|
var _a;
|
|
184
217
|
return ((_a = lastEqualsRef.current) == null ? void 0 : _a.call(lastEqualsRef, newValue)) ?? false;
|
|
@@ -191,28 +224,55 @@ function useStore(store, options) {
|
|
|
191
224
|
require$$0.useDebugValue(value);
|
|
192
225
|
return proxiedValue;
|
|
193
226
|
}
|
|
194
|
-
function
|
|
195
|
-
const
|
|
227
|
+
function useCache(cache, { passive, ...options } = {}) {
|
|
228
|
+
const mappedState = require$$0.useMemo(() => {
|
|
229
|
+
var _a;
|
|
230
|
+
const rootCache = ((_a = cache.derivedFromCache) == null ? void 0 : _a.cache) ?? cache;
|
|
231
|
+
let selector = (x) => x;
|
|
232
|
+
if (cache.derivedFromCache) {
|
|
233
|
+
selector = (value) => {
|
|
234
|
+
for (const s of cache.derivedFromCache.selectors) {
|
|
235
|
+
value = hash.makeSelector(s)(value);
|
|
236
|
+
}
|
|
237
|
+
return value;
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
return rootCache.state.map((state) => {
|
|
241
|
+
const value = state.status === "value" ? selector(state.value) : void 0;
|
|
242
|
+
return Object.assign(
|
|
243
|
+
[value, state.error, state.isUpdating, state.isStale],
|
|
244
|
+
{ ...state, value }
|
|
245
|
+
);
|
|
246
|
+
});
|
|
247
|
+
}, [cache]);
|
|
248
|
+
require$$0.useEffect(() => !passive ? cache.sub(() => void 0) : void 0, [cache, passive]);
|
|
249
|
+
return useStore(mappedState, options);
|
|
250
|
+
}
|
|
251
|
+
function read(cache, options) {
|
|
252
|
+
const { status, value, error } = useCache(cache, options);
|
|
196
253
|
if (status === "value") {
|
|
197
254
|
return value;
|
|
198
255
|
}
|
|
199
256
|
if (status === "error") {
|
|
200
257
|
throw error;
|
|
201
258
|
}
|
|
202
|
-
throw
|
|
259
|
+
throw cache.state.once((state) => state.status !== "pending");
|
|
203
260
|
}
|
|
204
261
|
const contextMap = /* @__PURE__ */ new WeakMap();
|
|
205
262
|
function getStoreScopeContext(scope) {
|
|
206
263
|
let context = contextMap.get(scope);
|
|
207
264
|
if (!context) {
|
|
208
|
-
context = require$$0.createContext(hash.
|
|
265
|
+
context = require$$0.createContext(hash.createStore(scope.defaultValue));
|
|
209
266
|
contextMap.set(scope, context);
|
|
210
267
|
}
|
|
211
268
|
return context;
|
|
212
269
|
}
|
|
213
270
|
function StoreScopeProvider({ scope, store: inputStore, children }) {
|
|
214
271
|
const context = getStoreScopeContext(scope);
|
|
215
|
-
const currentStore = require$$0.useMemo(
|
|
272
|
+
const currentStore = require$$0.useMemo(
|
|
273
|
+
() => inputStore ?? hash.createStore(scope.defaultValue),
|
|
274
|
+
[scope, inputStore]
|
|
275
|
+
);
|
|
216
276
|
return /* @__PURE__ */ jsxRuntime.jsx(context.Provider, { value: currentStore, children });
|
|
217
277
|
}
|
|
218
278
|
function useStoreScope(scope) {
|
|
@@ -221,10 +281,11 @@ function useStoreScope(scope) {
|
|
|
221
281
|
}
|
|
222
282
|
function useProp(store, options) {
|
|
223
283
|
const value = useStore(store, options);
|
|
224
|
-
return [value, store.
|
|
284
|
+
return [value, store.set];
|
|
225
285
|
}
|
|
226
286
|
exports.StoreScopeProvider = StoreScopeProvider;
|
|
227
287
|
exports.read = read;
|
|
288
|
+
exports.useCache = useCache;
|
|
228
289
|
exports.useProp = useProp;
|
|
229
290
|
exports.useStore = useStore;
|
|
230
291
|
exports.useStoreScope = useStoreScope;
|
package/dist/cjs/react.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.cjs","sources":["../../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/read.ts","../../src/react/storeScope.tsx","../../src/react/useProp.ts"],"sourcesContent":["/**\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 { FetchStore } from '@core/fetchStore';\nimport type { SubscribeOptions } from '@core/commonTypes';\nimport { useStore } from './useStore';\n\nexport type UseStoreOptions = Omit<SubscribeOptions, 'runNow'>;\n\nexport function read<T>(store: FetchStore<T>, options?: UseStoreOptions): T {\n const { status, value, error } = useStore(store, options);\n\n if (status === 'value') {\n return value;\n }\n\n if (status === 'error') {\n throw error;\n }\n\n throw store.fetch();\n}\n","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","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","module","require$$0","require$$1","useRef","useCallback","hash","useSyncExternalStoreWithSelector","trackingProxy","useLayoutEffect","useDebugValue","createContext","store","useMemo","useContext"],"mappings":";;;;;;;;;;;;;;;;;;;;AAS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/F,wCAAQ,QAAQ,UAAR,EAAiB,OAAO,cAAe,SAAS,CAAA;AAC1D;AAEO,SAAS,cAAiB,OAAgC;AACzD,QAAA,UAAU,qBAAqB,KAAK;AAC1C,SAAOE,WAAAA,WAAW,OAAO;AAC3B;AC1BgB,SAAA,QAAW,OAAiB,SAA8D;AAClG,QAAA,QAAQ,SAAS,OAAO,OAAO;AAE9B,SAAA,CAAC,OAAO,MAAM,MAAM;AAC7B;;;;;;"}
|
|
1
|
+
{"version":3,"file":"react.cjs","sources":["../../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/useCache.ts","../../src/react/read.ts","../../src/react/storeScope.tsx","../../src/react/useProp.ts"],"sourcesContent":["/**\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 { useCallback, useDebugValue, useLayoutEffect, useMemo, useRef } from 'react';\nimport { useSyncExternalStoreWithSelector } from 'use-sync-external-store/with-selector.js';\nimport type { SubscribeOptions } from '@core/commonTypes';\nimport type { Store } from '@core/store';\nimport { hash } from '@lib/hash';\nimport { makeSelector } from '@lib/makeSelector';\nimport { trackingProxy } from '@lib/trackingProxy';\n\nexport type UseStoreOptions = Omit<SubscribeOptions, 'runNow' | 'passive'>;\n\nexport function useStore<T>(store: Store<T>, options?: UseStoreOptions): T {\n const lastEqualsRef = useRef<(newValue: T) => boolean>();\n\n const { rootStore, selector } = useMemo(() => {\n const rootStore = store.derivedFrom?.store ?? store;\n let selector = (x: any) => x;\n\n if (store.derivedFrom) {\n selector = (value: any) => {\n for (const s of store.derivedFrom!.selectors) {\n value = makeSelector(s)(value);\n }\n return value;\n };\n }\n\n return { rootStore, selector };\n }, [store]);\n\n const subOptions = { ...options, runNow: false, equals: undefined, passive: false };\n const subscribe = useCallback(\n (listener: () => void) => {\n return rootStore.sub(listener, subOptions);\n },\n [rootStore, hash(subOptions)],\n );\n\n const value = useSyncExternalStoreWithSelector<unknown, T>(\n //\n subscribe,\n rootStore.get,\n undefined,\n selector,\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 { useEffect, useMemo } from 'react';\nimport type { UseStoreOptions } from './useStore';\nimport { useStore } from './useStore';\nimport type { Cache } from '@core';\nimport type { CacheState } from '@lib/cacheState';\nimport { makeSelector } from '@lib/makeSelector';\n\nexport type UseCacheArray<T> = [\n value: T | undefined,\n error: unknown | undefined,\n isUpdating: boolean,\n isStale: boolean,\n];\n\nexport type UseCacheValue<T> = UseCacheArray<T> & CacheState<T>;\n\nexport interface UseCacheOptions extends UseStoreOptions {\n passive?: boolean;\n}\n\nexport function useCache<T>(\n cache: Cache<T>,\n { passive, ...options }: UseCacheOptions = {},\n): UseCacheValue<T> {\n const mappedState = useMemo(() => {\n const rootCache: Cache<any> = cache.derivedFromCache?.cache ?? cache;\n let selector = (x: any) => x;\n\n if (cache.derivedFromCache) {\n selector = (value: any) => {\n for (const s of cache.derivedFromCache!.selectors) {\n value = makeSelector(s)(value);\n }\n return value;\n };\n }\n\n return rootCache.state.map((state) => {\n const value = state.status === 'value' ? selector(state.value) : undefined;\n\n return Object.assign<UseCacheArray<T>, CacheState<T>>(\n [value, state.error, state.isUpdating, state.isStale],\n { ...state, value },\n );\n });\n }, [cache]);\n\n useEffect(() => (!passive ? cache.sub(() => undefined) : undefined), [cache, passive]);\n\n return useStore(mappedState, options);\n}\n","import { useCache } from './useCache';\nimport type { UseStoreOptions } from './useStore';\nimport type { Cache } from '@core';\n\nexport function read<T>(cache: Cache<T>, options?: UseStoreOptions): T {\n const { status, value, error } = useCache(cache, options);\n\n if (status === 'value') {\n return value;\n }\n\n if (status === 'error') {\n throw error;\n }\n\n throw cache.state.once((state) => state.status !== 'pending');\n}\n","import type { Context, ReactNode } from 'react';\nimport { createContext, useContext, useMemo } from 'react';\nimport type { Store } from '@core/store';\nimport { createStore } from '@core/store';\nimport type { StoreScope } from '@core/storeScope';\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>>(createStore(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(\n () => inputStore ?? createStore(scope.defaultValue),\n [scope, inputStore],\n );\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","import type { UseStoreOptions } from './useStore';\nimport { useStore } from './useStore';\nimport type { Store } from '@core/store';\nimport type { UpdateFunction } from '@core/commonTypes';\n\nexport function useProp<T>(\n store: Store<T>,\n options?: UseStoreOptions,\n): [value: T, setValue: UpdateFunction<T>] {\n const value = useStore(store, options);\n\n return [value, store.set];\n}\n"],"names":["a","c","d","b","e","module","require$$0","require$$1","useRef","useMemo","rootStore","selector","value","makeSelector","useCallback","hash","useSyncExternalStoreWithSelector","trackingProxy","useLayoutEffect","useDebugValue","useEffect","createContext","createStore","useContext"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASa,MAAI,IAAE;AAAiB,WAAS,EAAE,GAAE,GAAE;AAAC,WAAO,MAAI,MAAI,MAAI,KAAG,IAAE,MAAI,IAAE,MAAI,MAAI,KAAG,MAAI;AAAA,EAAC;AAAC,MAAI,IAAE,eAAa,OAAO,OAAO,KAAG,OAAO,KAAG,GAAE,IAAE,EAAE,sB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