cross-state 0.8.5 → 0.9.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/dist/cjs/cache.cjs +386 -0
- package/dist/cjs/cache.cjs.map +1 -0
- package/dist/cjs/index.cjs +21 -16
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/react/index.cjs +163 -11
- package/dist/cjs/react/index.cjs.map +1 -1
- package/dist/cjs/react/register.cjs +12 -12
- package/dist/cjs/react/register.cjs.map +1 -1
- package/dist/cjs/scope.cjs +11 -379
- package/dist/cjs/scope.cjs.map +1 -1
- package/dist/cjs/store.cjs.map +1 -1
- package/dist/cjs/{scope2.cjs → useCache.cjs} +54 -40
- package/dist/cjs/useCache.cjs.map +1 -0
- package/dist/es/cache.mjs +387 -0
- package/dist/es/cache.mjs.map +1 -0
- package/dist/es/index.mjs +16 -11
- package/dist/es/index.mjs.map +1 -1
- package/dist/es/react/index.mjs +161 -9
- package/dist/es/react/index.mjs.map +1 -1
- package/dist/es/react/register.mjs +4 -4
- package/dist/es/scope.mjs +12 -380
- package/dist/es/scope.mjs.map +1 -1
- package/dist/es/store.mjs +3 -3
- package/dist/es/store.mjs.map +1 -1
- package/dist/es/{scope2.mjs → useCache.mjs} +58 -44
- package/dist/es/useCache.mjs.map +1 -0
- package/dist/types/lib/castArray.d.ts +1 -0
- package/dist/types/lib/path.d.ts +11 -9
- package/dist/types/lib/propAccess.d.ts +1 -1
- package/dist/types/lib/typeHelpers.d.ts +2 -1
- package/dist/types/lib/wildcardMatch.d.ts +3 -0
- package/dist/types/persist/persist.d.ts +6 -4
- package/dist/types/react/form.d.ts +48 -0
- package/dist/types/react/index.d.ts +1 -0
- package/dist/types/react/useProp.d.ts +5 -1
- package/dist/types/react/useStore.d.ts +5 -2
- package/package.json +23 -11
- package/dist/cjs/hash.cjs +0 -18
- package/dist/cjs/hash.cjs.map +0 -1
- package/dist/cjs/scope2.cjs.map +0 -1
- package/dist/es/hash.mjs +0 -19
- package/dist/es/hash.mjs.map +0 -1
- package/dist/es/scope2.mjs.map +0 -1
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/core/subscriptionCache.ts","../../src/core/urlStore.ts","../../src/lib/updateHelpers.ts","../../src/persist/persistPathHelpers.ts","../../src/lib/maybeAsync.ts","../../src/persist/persistStorage.ts","../../src/lib/diff.ts","../../src/persist/persist.ts"],"sourcesContent":["import {\n type CalculationHelpers,\n type Cancel,\n type ConnectionState,\n type Duration,\n type Selector,\n} from './commonTypes';\nimport { allResources, type ResourceGroup } from './resourceGroup';\nimport { createStore, Store } from './store';\nimport { calcDuration } from '@lib/calcDuration';\nimport { InstanceCache } from '@lib/instanceCache';\nimport { type Path } from '@lib/path';\n\nexport interface SubscriptionCacheFunction<T, Args extends any[] = []> {\n (this: CalculationHelpers<T | undefined>, ...args: Args):\n | Cancel\n | void\n | ((cache: CalculationHelpers<T | undefined>) => Cancel | void);\n}\n\nexport interface SubstriptionCacheOptions {\n clearOnInvalidate?: boolean;\n clearUnusedAfter?: Duration | null;\n resourceGroup?: ResourceGroup | ResourceGroup[];\n retain?: Duration;\n}\n\nexport class SubstriptionCache<T> extends Store<T | undefined> {\n readonly state = createStore({\n connectionState: 'closed' as ConnectionState,\n error: undefined as unknown | undefined,\n });\n\n constructor(\n public readonly connectFunction: SubscriptionCacheFunction<T>,\n public readonly options: SubstriptionCacheOptions = {},\n public readonly derivedFromSubscriptionCache?: {\n subscriptionCache: SubstriptionCache<any>;\n selectors: (Selector<any, any> | Path<any>)[];\n },\n _call?: (...args: any[]) => any,\n ) {\n super(undefined, options, undefined, _call);\n\n this.calculationHelper.options = {\n ...this.calculationHelper.options,\n calculate: (helpers) => {\n let result = connectFunction.apply(helpers);\n\n if (result instanceof Function && result.length > 0) {\n result = result(helpers);\n }\n\n return result as Cancel | void;\n },\n onValue: (value) => {\n this.set(value);\n },\n onError: (error) => {\n this.state.set('error', error);\n },\n onConnectionState: (state) => {\n this.state.set('connectionState', state);\n },\n onInvalidate: () => {\n this.invalidate();\n },\n };\n }\n\n invalidate({ invalidateDependencies = true }: { invalidateDependencies?: boolean } = {}) {\n const { clearOnInvalidate = defaultOptions.clearOnInvalidate } = this.options;\n\n if (clearOnInvalidate) {\n return this.clear({ invalidateDependencies });\n }\n\n if (invalidateDependencies) {\n this.calculationHelper.invalidateDependencies();\n }\n\n this.calculationHelper.stop();\n\n if (this.isActive()) {\n this.calculationHelper.execute();\n }\n }\n\n clear({ invalidateDependencies = true }: { invalidateDependencies?: boolean } = {}): void {\n if (invalidateDependencies) {\n this.calculationHelper.invalidateDependencies();\n }\n\n this.calculationHelper.stop();\n\n if (this.isActive()) {\n this.calculationHelper.execute();\n }\n }\n}\n\nconst defaultOptions: SubstriptionCacheOptions = {\n clearUnusedAfter: { days: 1 },\n retain: { seconds: 1 },\n};\n\ntype CreateReturnType<T, Args extends any[]> = {\n (...args: Args): SubstriptionCache<T>;\n invalidateAll: () => void;\n clearAll: () => void;\n} & ([] extends Args ? SubstriptionCache<T> : {});\n\nfunction create<T, Args extends any[] = []>(\n cacheFunction: SubscriptionCacheFunction<T, Args>,\n options?: SubstriptionCacheOptions,\n): CreateReturnType<T, Args> {\n const { clearUnusedAfter = defaultOptions.clearUnusedAfter, resourceGroup } = options ?? {};\n\n let baseInstance: CreateReturnType<T, Args> & SubstriptionCache<T>;\n\n const instanceCache = new InstanceCache<Args, SubstriptionCache<T>>(\n (...args: Args): SubstriptionCache<T> => {\n if (args.length === 0 && baseInstance) {\n return baseInstance;\n }\n\n return new SubstriptionCache(function () {\n return cacheFunction.apply(this, args);\n }, options);\n },\n clearUnusedAfter ? calcDuration(clearUnusedAfter) : undefined,\n );\n\n const get = (...args: Args) => {\n return instanceCache.get(...args);\n };\n\n const invalidateAll = () => {\n for (const instance of instanceCache.values()) {\n instance.invalidate();\n }\n };\n\n const clearAll = () => {\n for (const instance of instanceCache.values()) {\n instance.clear();\n }\n };\n\n baseInstance = Object.assign(\n new SubstriptionCache<T>(\n function () {\n return cacheFunction.apply(this);\n },\n options,\n undefined,\n get,\n ),\n {\n invalidateAll,\n clearAll,\n },\n ) as CreateReturnType<T, Args> & SubstriptionCache<T>;\n\n const groups = Array.isArray(resourceGroup)\n ? resourceGroup\n : resourceGroup\n ? [resourceGroup]\n : [];\n for (const group of groups.concat(allResources)) {\n group.add(baseInstance);\n }\n\n get(...([] as any));\n\n return baseInstance;\n}\n\nexport const createSubscriptionCache = /* @__PURE__ */ Object.assign(create, {\n defaultOptions,\n});\n","import { type Update } from './commonTypes';\nimport { Store, type StoreOptions } from './store';\nimport { type Path, type Value } from '@lib/path';\n\nexport interface UrlStoreOptions<T> extends StoreOptions {\n key: string;\n type?: 'search' | 'hash';\n serialize?: (value: T) => string;\n deserialize?: (value: string) => T;\n defaultValue?: T;\n onCommit?: (value: T | undefined) => void;\n}\n\nexport interface UrlStoreOptionsWithDefaults<T> extends UrlStoreOptions<T> {\n defaultValue: T;\n}\n\nexport type UrlStoreOptionsRequired<T> = UrlStoreOptions<T> &\n Required<Pick<UrlStoreOptions<T>, 'type' | 'serialize' | 'deserialize' | 'defaultValue'>>;\n\nexport class UrlStore<T> extends Store<T> {\n private serializedDefaultValue = this.options.serialize(this.options.defaultValue);\n\n constructor(public readonly options: UrlStoreOptionsRequired<T>) {\n super(() => {\n const url = new URL(window.location.href);\n const parameters = new URLSearchParams(url[options.type].slice(1));\n const urlValue = parameters.get(options.key);\n const deserialize: (value: string) => T = options.deserialize ?? defaultDeserializer;\n return urlValue !== null ? deserialize(urlValue) : options.defaultValue;\n });\n\n this.addEffect(() => this.watchUrl());\n }\n\n override set(update: Update<T>): void;\n\n override set<P extends Path<T>>(path: P, update: Update<Value<T, P>>): void;\n\n override set(...args: any): void {\n super.set.apply(this, args);\n this.updateUrl(super.get());\n }\n\n protected watchUrl() {\n const originalPushState = window.history.pushState;\n const originalReplaceState = window.history.replaceState;\n\n window.history.pushState = (...args) => {\n originalPushState.apply(window.history, args);\n this.reset();\n };\n\n window.history.replaceState = (...args) => {\n originalReplaceState.apply(window.history, args);\n this.reset();\n };\n\n window.addEventListener('popstate', this.reset);\n\n return () => {\n window.history.pushState = originalPushState;\n window.history.replaceState = originalReplaceState;\n window.removeEventListener('popstate', this.reset);\n };\n }\n\n protected updateUrl(value: T | undefined) {\n const url = new URL(window.location.href);\n const parameters = new URLSearchParams(url[this.options.type].slice(1));\n const serializedValue = value !== undefined ? this.options.serialize(value) : undefined;\n\n if (serializedValue === undefined || serializedValue === this.serializedDefaultValue) {\n parameters.delete(this.options.key);\n } else {\n parameters.set(this.options.key, serializedValue);\n }\n\n url[this.options.type] = parameters.toString();\n window.history.replaceState(null, '', url.toString());\n\n this.options.onCommit?.(value);\n }\n}\n\nfunction defaultDeserializer(value: string): any {\n if (value === undefined) {\n return undefined;\n }\n\n try {\n return JSON.parse(value, (_k, v) => {\n if (typeof v === 'object' && v !== null && '__set' in v) {\n return new Set(v.__set);\n }\n if (typeof v === 'object' && v !== null && '__map' in v) {\n return new Map(v.__map);\n }\n return v;\n });\n } catch {\n return undefined;\n }\n}\n\nfunction defaultSerializer(value: any): string {\n return JSON.stringify(value, (_k, v) => {\n if (v instanceof Set) {\n return { __set: Array.from(v) };\n }\n if (v instanceof Map) {\n return { __map: Array.from(v) };\n }\n return v;\n });\n}\n\nexport function createUrlStore<T>(options: UrlStoreOptionsWithDefaults<T>): UrlStore<T>;\nexport function createUrlStore<T>(options: UrlStoreOptions<T>): UrlStore<T | undefined>;\nexport function createUrlStore<T>(options: UrlStoreOptions<T>) {\n return new UrlStore({\n ...options,\n type: options.type ?? 'search',\n serialize: options.serialize ?? defaultSerializer,\n deserialize: options.deserialize ?? defaultDeserializer,\n defaultValue: options.defaultValue ?? (undefined as T),\n });\n}\n","export function findOrDefault<T>(\n array: T[],\n predicate: (item: T) => boolean,\n defaultValue: T | (() => T),\n): T {\n const index = array.findIndex(predicate);\n\n if (index >= 0) {\n return array[index]!;\n }\n\n const value = defaultValue instanceof Function ? defaultValue() : defaultValue;\n array.push(value);\n return value;\n}\n","import type { KeyType } from '@lib/path';\n\nexport const isAncestor = (ancestor: KeyType[], path: KeyType[]): boolean => {\n return (\n ancestor.length <= path.length &&\n ancestor.every((v, i) => v === '*' || path[i] === '*' || v === path[i])\n );\n};\n\nexport const split = (\n value: any,\n path: KeyType[],\n): [value: unknown, subValues: { path: KeyType[]; value: unknown }[]] => {\n const [first, ...rest] = path;\n if (first === undefined) return [value, []];\n\n if (rest.length === 0) {\n if (first === '*')\n return [{}, Object.entries(value).map(([k, v]) => ({ path: [k], value: v }))];\n if (!(first in value)) return [value, []];\n const { [first]: subValue, ...newValue } = value;\n return [newValue, [{ path: [first], value: subValue }]];\n }\n\n const newValue = { ...value };\n const subValues = new Array<{ path: KeyType[]; value: unknown }>();\n for (const key of first === '*' ? Object.keys(value) : [first]) {\n if (!(newValue[key] instanceof Object)) return [value, []];\n const result = split(newValue[key], rest);\n newValue[key] = result[0];\n subValues.push(...result[1].map((s) => ({ path: [key, ...s.path], value: s.value })));\n }\n return [newValue, subValues];\n};\n","import type { MaybePromise } from './maybePromise';\n\nexport function maybeAsync<T, R>(\n value: MaybePromise<T>,\n action: (value: T) => MaybePromise<R>,\n): MaybePromise<R> {\n if (value instanceof Promise) {\n return value.then(action);\n }\n return action(value);\n}\n\nexport function maybeAsyncArray<T>(values: (() => MaybePromise<T>)[]): MaybePromise<T[]> {\n const run = (remainingValues: (() => MaybePromise<T>)[], results: T[]): MaybePromise<T[]> => {\n const [first, ...rest] = remainingValues;\n if (!first) {\n return results;\n }\n\n return maybeAsync(first(), (result) => run(rest, results.concat(result)));\n };\n\n return run(values, []);\n}\n","import { maybeAsync, maybeAsyncArray } from '@lib/maybeAsync';\n\nexport interface PersistStorageBase {\n getItem: (key: string) => string | null | Promise<string | null>;\n setItem: (key: string, value: string) => unknown | Promise<unknown>;\n removeItem: (key: string) => unknown | Promise<unknown>;\n}\n\nexport interface PersistStorageWithKeys extends PersistStorageBase {\n keys: () => string[] | Promise<string[]>;\n}\n\nexport interface PersistStorageWithLength extends PersistStorageBase {\n length: number | (() => number | Promise<number>);\n key: (keyIndex: number) => string | null | Promise<string | null>;\n}\n\nexport type PersistStorage = PersistStorageBase &\n (PersistStorageWithKeys | PersistStorageWithLength);\n\nexport function normalizeStorage(storage: PersistStorage): PersistStorageWithKeys {\n return {\n getItem: storage.getItem.bind(storage),\n setItem: storage.setItem.bind(storage),\n removeItem: storage.removeItem.bind(storage),\n\n keys(): string[] | Promise<string[]> {\n if ('keys' in storage) {\n return storage.keys();\n }\n\n return maybeAsync(\n storage.length instanceof Function ? storage.length() : storage.length,\n (length) => {\n const keyPromises = maybeAsyncArray(\n Array.from({ length }, (_, index) => () => storage.key(index)),\n );\n\n return maybeAsync(keyPromises, (keys) =>\n keys.filter((key): key is string => typeof key === 'string'),\n );\n },\n );\n },\n };\n}\n","import type { KeyType } from './path';\n\nexport type Patch =\n | { op: 'add'; path: KeyType[]; value: any }\n | { op: 'remove'; path: KeyType[] }\n | { op: 'replace'; path: KeyType[]; value: any };\n\nexport function diff(a: any, b: any): [patches: Patch[], reversePatches: Patch[]] {\n const result = [..._diff(a, b)];\n const patches = result.map(([patch]) => patch);\n const reversePatches = result.map(([, reversePatch]) => reversePatch);\n\n return [patches, reversePatches];\n}\n\nfunction* _diff(\n a: any,\n b: any,\n prefix: KeyType[] = [],\n): Iterable<[patch: Patch, reversePatch: Patch]> {\n if (a === b) {\n return;\n }\n\n if (a instanceof Map && b instanceof Map) {\n return yield* mapDiff(a, b, prefix);\n }\n\n if (a instanceof Set && b instanceof Set) {\n a = [...a];\n b = [...b];\n }\n\n if (a instanceof Object && b instanceof Object && Array.isArray(a) === Array.isArray(b)) {\n return yield* objectDiff(a, b, prefix);\n }\n\n yield [\n { op: 'replace', path: prefix, value: b },\n { op: 'replace', path: prefix, value: a },\n ];\n}\n\nfunction* mapDiff(\n a: Map<any, any>,\n b: Map<any, any>,\n prefix: KeyType[],\n): Iterable<[patch: Patch, reversePatch: Patch]> {\n for (const [key, value] of a) {\n if (!b.has(key)) {\n yield [\n { op: 'remove', path: [...prefix, key] },\n { op: 'add', path: [...prefix, key], value },\n ];\n } else {\n yield* _diff(value, b.get(key), [...prefix, key]);\n }\n }\n\n for (const [key, value] of b) {\n if (!a.has(key)) {\n yield [\n { op: 'add', path: [...prefix, key], value },\n { op: 'remove', path: [...prefix, key] },\n ];\n }\n }\n}\n\nfunction* objectDiff(\n a: any,\n b: any,\n prefix: KeyType[],\n): Iterable<[patch: Patch, reversePatch: Patch]> {\n const castKey = (key: string) => (Array.isArray(a) ? Number(key) : key);\n\n for (const [key, value] of Object.entries(a)) {\n if (!(key in b)) {\n yield [\n { op: 'remove', path: [...prefix, castKey(key)] },\n { op: 'add', path: [...prefix, castKey(key)], value },\n ];\n } else {\n yield* _diff(value, b[key], [...prefix, castKey(key)]);\n }\n }\n\n for (const [key, value] of Object.entries(b)) {\n if (!(key in a)) {\n yield [\n { op: 'add', path: [...prefix, castKey(key)], value },\n { op: 'remove', path: [...prefix, castKey(key)] },\n ];\n }\n }\n}\n","import { isAncestor } from './persistPathHelpers';\nimport {\n normalizeStorage,\n type PersistStorage,\n type PersistStorageWithKeys,\n} from './persistStorage';\nimport { type Cancel, type Store } from '@core';\nimport { diff } from '@lib/diff';\nimport { shallowEqual } from '@lib/equals';\nimport { maybeAsync, maybeAsyncArray } from '@lib/maybeAsync';\nimport type { KeyType, WildcardPath } from '@lib/path';\nimport { castArrayPath, get, set } from '@lib/propAccess';\nimport { queue } from '@lib/queue';\n\nexport interface PersistOptions<T> {\n id: string;\n storage: PersistStorage;\n paths?:\n | WildcardPath<T>[]\n | {\n path: WildcardPath<T>;\n throttleMs?: number;\n }[];\n throttleMs?: number;\n}\n\nexport class Persist<T> {\n storage: PersistStorageWithKeys;\n\n paths: {\n path: KeyType[];\n throttleMs?: number;\n }[];\n\n channel: BroadcastChannel;\n\n queue = queue();\n\n handles = new Set<Cancel>();\n\n stopped = false;\n\n updateInProgress?: [any, any];\n\n constructor(public readonly store: Store<T>, public readonly options: PersistOptions<T>) {\n this.storage = normalizeStorage(options.storage);\n this.channel = new BroadcastChannel(`cross-state-persist_${options.id}`);\n\n this.paths = (options.paths ?? [])\n .map<{\n path: KeyType[];\n throttleMs?: number;\n }>((p) =>\n typeof p === 'string' || Array.isArray(p)\n ? {\n path: castArrayPath(p as any),\n }\n : {\n path: castArrayPath(p.path as any),\n throttleMs: p.throttleMs,\n },\n )\n .sort((a, b) => b.path.length - a.path.length);\n\n if (this.paths.length === 0) {\n this.paths.push({ path: ['*'] });\n }\n\n this.watchStore();\n this.watchStorage();\n }\n\n watchStore() {\n let committed = this.store.get();\n\n const cancel = this.store.subscribe(\n (value) => {\n const [patches] = diff(committed, value);\n committed = value;\n\n for (const patch of patches) {\n if (\n this.updateInProgress &&\n shallowEqual(this.updateInProgress[0], patch.path) &&\n this.updateInProgress[1] === (patch.op === 'remove' ? undefined : patch.value)\n ) {\n continue;\n }\n\n const ancestor = this.paths.find((p) => isAncestor(p.path, patch.path));\n\n if (!ancestor) {\n continue;\n }\n\n const pathToSave = patch.path.slice(0, ancestor.path.length);\n this.queue(() => this.save(pathToSave), pathToSave);\n }\n },\n { runNow: false },\n );\n\n this.handles.add(cancel);\n }\n\n async watchStorage() {\n let keys = this.storage.keys();\n if (keys instanceof Promise) {\n keys = await keys;\n }\n\n if (this.stopped) {\n return;\n }\n\n for (const key of keys) {\n const path = JSON.parse(key);\n this.queue(() => this.load(path));\n }\n\n const listener = (event: MessageEvent) => {\n this.queue(() => this.load(event.data));\n };\n\n this.channel.addEventListener('message', listener);\n this.handles.add(() => this.channel.removeEventListener('message', listener));\n }\n\n load(path: KeyType[]) {\n const matchingPath = this.paths.find(\n (p) => p.path.length === path.length && isAncestor(p.path, path),\n );\n if (!matchingPath) {\n return;\n }\n\n const key = JSON.stringify(path);\n\n return maybeAsync(this.storage.getItem(key), (value) => {\n if (this.stopped || !value) {\n return;\n }\n\n const inSaveQueue = this.queue\n .getRefs()\n .find((ref) => isAncestor(ref, path) || isAncestor(path, ref));\n if (inSaveQueue) {\n return;\n }\n\n const parsedValue = value === 'undefined' ? undefined : JSON.parse(value);\n\n this.updateInProgress = [path, parsedValue];\n this.store.set((state) => set(state, path as any, parsedValue));\n this.updateInProgress = undefined;\n });\n }\n\n save(path: KeyType[]) {\n const key = JSON.stringify(path);\n const value = get(this.store.get(), path as any);\n const serializedValue = value === undefined ? 'undefined' : JSON.stringify(value);\n\n return maybeAsync(this.storage.setItem(key, serializedValue), () => {\n this.channel.postMessage(path);\n\n return maybeAsync(this.storage.keys(), (keys) => {\n const toRemove = keys.filter((k) => {\n const parsedKey = JSON.parse(k);\n return (\n parsedKey.length > path.length && isAncestor(path, parsedKey)\n // !this.queue.getRefs().find((ref) => isAncestor(ref, parsedKey))\n );\n });\n\n return maybeAsyncArray(toRemove.map((k) => () => this.storage.removeItem(k)));\n });\n });\n }\n\n async stop() {\n this.stopped = true;\n\n for (const handle of this.handles) {\n handle();\n }\n\n await this.queue.whenDone();\n this.channel.close();\n }\n}\n\nexport function persist<T>(store: Store<T>, options: PersistOptions<T>): Persist<T> {\n return new Persist<T>(store, options);\n}\n"],"names":["Store","createStore","InstanceCache","calcDuration","allResources","store","queue","castArrayPath","shallowEqual","set","get"],"mappings":";;;;;AA2BO,MAAM,0BAA6BA,MAAAA,MAAqB;AAAA,EAM7D,YACkB,iBACA,UAAoC,CAAA,GACpC,8BAIhB,OACA;AACM,UAAA,QAAW,SAAS,QAAW,KAAK;AAR1B,SAAA,kBAAA;AACA,SAAA,UAAA;AACA,SAAA,+BAAA;AARlB,SAAS,QAAQC,kBAAY;AAAA,MAC3B,iBAAiB;AAAA,MACjB,OAAO;AAAA,IAAA,CACR;AAaC,SAAK,kBAAkB,UAAU;AAAA,MAC/B,GAAG,KAAK,kBAAkB;AAAA,MAC1B,WAAW,CAAC,YAAY;AAClB,YAAA,SAAS,gBAAgB,MAAM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AAM,KAAK,UAAU,IAAI;AAC/B,UAAM,QAAQC,MAAAA,IAAI,KAAK,MAAM,IAAA,GAAO,IAAW;AAC/C,UAAM,kBAAkB,UAAU,SAAY,cAAc,KAAK,UAAU,KAAK;AAEhF,WAAO,WAAW,KAAK,QAAQ,QAAQ,KAAK,eAAe,GAAG,MAAM;AAC7D,WAAA,QAAQ,YAAY,IAAI;AAE7B,aAAO,WAAW,KAAK,QAAQ,KAAK,GAAG,CAAC,SAAS;AAC/C,cAAM,WAAW,KAAK,OAAO,CAAC,MAAM;AAC5B,gBAAA,YAAY,KAAK,MAAM,CAAC;AAC9B,iBACE,UAAU,SAAS,KAAK,UAAU,WAAW,MAAM,SAAS;AAAA,QAAA,CAG/D;AAEM,eAAA,gBAAgB,SAAS,IAAI,CAAC,MAAM,MAAM,KAAK,QAAQ,WAAW,CAAC,CAAC,CAAC;AAAA,MAAA,CAC7E;AAAA,IAAA,CACF;AAAA,EACH;AAAA,EAEA,MAAM,OAAO;AACX,SAAK,UAAU;AAEJ,eAAA,UAAU,KAAK,SAAS;AAC1B;IACT;AAEM,UAAA,KAAK,MAAM;AACjB,SAAK,QAAQ;EACf;AACF;AAEgB,SAAA,QAAWL,QAAiB,SAAwC;AAC3E,SAAA,IAAI,QAAWA,QAAO,OAAO;AACtC;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/core/subscriptionCache.ts","../../src/core/urlStore.ts","../../src/lib/updateHelpers.ts","../../src/persist/persistPathHelpers.ts","../../src/lib/maybeAsync.ts","../../src/persist/persistStorage.ts","../../src/lib/diff.ts","../../src/persist/persist.ts"],"sourcesContent":["import {\n type CalculationHelpers,\n type Cancel,\n type ConnectionState,\n type Duration,\n type Selector,\n} from './commonTypes';\nimport { allResources, type ResourceGroup } from './resourceGroup';\nimport { createStore, Store } from './store';\nimport { calcDuration } from '@lib/calcDuration';\nimport { InstanceCache } from '@lib/instanceCache';\nimport { type Path } from '@lib/path';\n\nexport interface SubscriptionCacheFunction<T, Args extends any[] = []> {\n (this: CalculationHelpers<T | undefined>, ...args: Args):\n | Cancel\n | void\n | ((cache: CalculationHelpers<T | undefined>) => Cancel | void);\n}\n\nexport interface SubstriptionCacheOptions {\n clearOnInvalidate?: boolean;\n clearUnusedAfter?: Duration | null;\n resourceGroup?: ResourceGroup | ResourceGroup[];\n retain?: Duration;\n}\n\nexport class SubstriptionCache<T> extends Store<T | undefined> {\n readonly state = createStore({\n connectionState: 'closed' as ConnectionState,\n error: undefined as unknown | undefined,\n });\n\n constructor(\n public readonly connectFunction: SubscriptionCacheFunction<T>,\n public readonly options: SubstriptionCacheOptions = {},\n public readonly derivedFromSubscriptionCache?: {\n subscriptionCache: SubstriptionCache<any>;\n selectors: (Selector<any, any> | Path<any>)[];\n },\n _call?: (...args: any[]) => any,\n ) {\n super(undefined, options, undefined, _call);\n\n this.calculationHelper.options = {\n ...this.calculationHelper.options,\n calculate: (helpers) => {\n let result = connectFunction.apply(helpers);\n\n if (result instanceof Function && result.length > 0) {\n result = result(helpers);\n }\n\n return result as Cancel | void;\n },\n onValue: (value) => {\n this.set(value);\n },\n onError: (error) => {\n this.state.set('error', error);\n },\n onConnectionState: (state) => {\n this.state.set('connectionState', state);\n },\n onInvalidate: () => {\n this.invalidate();\n },\n };\n }\n\n invalidate({ invalidateDependencies = true }: { invalidateDependencies?: boolean } = {}) {\n const { clearOnInvalidate = defaultOptions.clearOnInvalidate } = this.options;\n\n if (clearOnInvalidate) {\n return this.clear({ invalidateDependencies });\n }\n\n if (invalidateDependencies) {\n this.calculationHelper.invalidateDependencies();\n }\n\n this.calculationHelper.stop();\n\n if (this.isActive()) {\n this.calculationHelper.execute();\n }\n }\n\n clear({ invalidateDependencies = true }: { invalidateDependencies?: boolean } = {}): void {\n if (invalidateDependencies) {\n this.calculationHelper.invalidateDependencies();\n }\n\n this.calculationHelper.stop();\n\n if (this.isActive()) {\n this.calculationHelper.execute();\n }\n }\n}\n\nconst defaultOptions: SubstriptionCacheOptions = {\n clearUnusedAfter: { days: 1 },\n retain: { seconds: 1 },\n};\n\ntype CreateReturnType<T, Args extends any[]> = {\n (...args: Args): SubstriptionCache<T>;\n invalidateAll: () => void;\n clearAll: () => void;\n} & ([] extends Args ? SubstriptionCache<T> : {});\n\nfunction create<T, Args extends any[] = []>(\n cacheFunction: SubscriptionCacheFunction<T, Args>,\n options?: SubstriptionCacheOptions,\n): CreateReturnType<T, Args> {\n const { clearUnusedAfter = defaultOptions.clearUnusedAfter, resourceGroup } = options ?? {};\n\n let baseInstance: CreateReturnType<T, Args> & SubstriptionCache<T>;\n\n const instanceCache = new InstanceCache<Args, SubstriptionCache<T>>(\n (...args: Args): SubstriptionCache<T> => {\n if (args.length === 0 && baseInstance) {\n return baseInstance;\n }\n\n return new SubstriptionCache(function () {\n return cacheFunction.apply(this, args);\n }, options);\n },\n clearUnusedAfter ? calcDuration(clearUnusedAfter) : undefined,\n );\n\n const get = (...args: Args) => {\n return instanceCache.get(...args);\n };\n\n const invalidateAll = () => {\n for (const instance of instanceCache.values()) {\n instance.invalidate();\n }\n };\n\n const clearAll = () => {\n for (const instance of instanceCache.values()) {\n instance.clear();\n }\n };\n\n baseInstance = Object.assign(\n new SubstriptionCache<T>(\n function () {\n return cacheFunction.apply(this);\n },\n options,\n undefined,\n get,\n ),\n {\n invalidateAll,\n clearAll,\n },\n ) as CreateReturnType<T, Args> & SubstriptionCache<T>;\n\n const groups = Array.isArray(resourceGroup)\n ? resourceGroup\n : resourceGroup\n ? [resourceGroup]\n : [];\n for (const group of groups.concat(allResources)) {\n group.add(baseInstance);\n }\n\n get(...([] as any));\n\n return baseInstance;\n}\n\nexport const createSubscriptionCache = /* @__PURE__ */ Object.assign(create, {\n defaultOptions,\n});\n","import { type Update } from './commonTypes';\nimport { Store, type StoreOptions } from './store';\nimport { type Path, type Value } from '@lib/path';\n\nexport interface UrlStoreOptions<T> extends StoreOptions {\n key: string;\n type?: 'search' | 'hash';\n serialize?: (value: T) => string;\n deserialize?: (value: string) => T;\n defaultValue?: T;\n onCommit?: (value: T | undefined) => void;\n}\n\nexport interface UrlStoreOptionsWithDefaults<T> extends UrlStoreOptions<T> {\n defaultValue: T;\n}\n\nexport type UrlStoreOptionsRequired<T> = UrlStoreOptions<T> &\n Required<Pick<UrlStoreOptions<T>, 'type' | 'serialize' | 'deserialize' | 'defaultValue'>>;\n\nexport class UrlStore<T> extends Store<T> {\n private serializedDefaultValue = this.options.serialize(this.options.defaultValue);\n\n constructor(public readonly options: UrlStoreOptionsRequired<T>) {\n super(() => {\n const url = new URL(window.location.href);\n const parameters = new URLSearchParams(url[options.type].slice(1));\n const urlValue = parameters.get(options.key);\n const deserialize: (value: string) => T = options.deserialize ?? defaultDeserializer;\n return urlValue !== null ? deserialize(urlValue) : options.defaultValue;\n });\n\n this.addEffect(() => this.watchUrl());\n }\n\n override set(update: Update<T>): void;\n\n override set<P extends Path<T>>(path: P, update: Update<Value<T, P>>): void;\n\n override set(...args: any): void {\n super.set.apply(this, args);\n this.updateUrl(super.get());\n }\n\n protected watchUrl() {\n const originalPushState = window.history.pushState;\n const originalReplaceState = window.history.replaceState;\n\n window.history.pushState = (...args) => {\n originalPushState.apply(window.history, args);\n this.reset();\n };\n\n window.history.replaceState = (...args) => {\n originalReplaceState.apply(window.history, args);\n this.reset();\n };\n\n window.addEventListener('popstate', this.reset);\n\n return () => {\n window.history.pushState = originalPushState;\n window.history.replaceState = originalReplaceState;\n window.removeEventListener('popstate', this.reset);\n };\n }\n\n protected updateUrl(value: T | undefined) {\n const url = new URL(window.location.href);\n const parameters = new URLSearchParams(url[this.options.type].slice(1));\n const serializedValue = value !== undefined ? this.options.serialize(value) : undefined;\n\n if (serializedValue === undefined || serializedValue === this.serializedDefaultValue) {\n parameters.delete(this.options.key);\n } else {\n parameters.set(this.options.key, serializedValue);\n }\n\n url[this.options.type] = parameters.toString();\n window.history.replaceState(null, '', url.toString());\n\n this.options.onCommit?.(value);\n }\n}\n\nfunction defaultDeserializer(value: string): any {\n if (value === undefined) {\n return undefined;\n }\n\n try {\n return JSON.parse(value, (_k, v) => {\n if (typeof v === 'object' && v !== null && '__set' in v) {\n return new Set(v.__set);\n }\n if (typeof v === 'object' && v !== null && '__map' in v) {\n return new Map(v.__map);\n }\n return v;\n });\n } catch {\n return undefined;\n }\n}\n\nfunction defaultSerializer(value: any): string {\n return JSON.stringify(value, (_k, v) => {\n if (v instanceof Set) {\n return { __set: Array.from(v) };\n }\n if (v instanceof Map) {\n return { __map: Array.from(v) };\n }\n return v;\n });\n}\n\nexport function createUrlStore<T>(options: UrlStoreOptionsWithDefaults<T>): UrlStore<T>;\nexport function createUrlStore<T>(options: UrlStoreOptions<T>): UrlStore<T | undefined>;\nexport function createUrlStore<T>(options: UrlStoreOptions<T>) {\n return new UrlStore({\n ...options,\n type: options.type ?? 'search',\n serialize: options.serialize ?? defaultSerializer,\n deserialize: options.deserialize ?? defaultDeserializer,\n defaultValue: options.defaultValue ?? (undefined as T),\n });\n}\n","export function findOrDefault<T>(\n array: T[],\n predicate: (item: T) => boolean,\n defaultValue: T | (() => T),\n): T {\n const index = array.findIndex(predicate);\n\n if (index >= 0) {\n return array[index]!;\n }\n\n const value = defaultValue instanceof Function ? defaultValue() : defaultValue;\n array.push(value);\n return value;\n}\n","import type { KeyType } from '@lib/path';\n\nexport const isAncestor = (ancestor: KeyType[], path: KeyType[]): boolean => {\n return (\n ancestor.length <= path.length &&\n ancestor.every((v, i) => v === '*' || path[i] === '*' || v === path[i])\n );\n};\n\nexport const split = (\n value: any,\n path: KeyType[],\n): [value: unknown, subValues: { path: KeyType[]; value: unknown }[]] => {\n const [first, ...rest] = path;\n if (first === undefined) return [value, []];\n\n if (rest.length === 0) {\n if (first === '*')\n return [{}, Object.entries(value).map(([k, v]) => ({ path: [k], value: v }))];\n if (!(first in value)) return [value, []];\n const { [first]: subValue, ...newValue } = value;\n return [newValue, [{ path: [first], value: subValue }]];\n }\n\n const newValue = { ...value };\n const subValues = new Array<{ path: KeyType[]; value: unknown }>();\n for (const key of first === '*' ? Object.keys(value) : [first]) {\n if (!(newValue[key] instanceof Object)) return [value, []];\n const result = split(newValue[key], rest);\n newValue[key] = result[0];\n subValues.push(...result[1].map((s) => ({ path: [key, ...s.path], value: s.value })));\n }\n return [newValue, subValues];\n};\n","import type { MaybePromise } from './maybePromise';\n\nexport function maybeAsync<T, R>(\n value: MaybePromise<T>,\n action: (value: T) => MaybePromise<R>,\n): MaybePromise<R> {\n if (value instanceof Promise) {\n return value.then(action);\n }\n return action(value);\n}\n\nexport function maybeAsyncArray<T>(values: (() => MaybePromise<T>)[]): MaybePromise<T[]> {\n const run = (remainingValues: (() => MaybePromise<T>)[], results: T[]): MaybePromise<T[]> => {\n const [first, ...rest] = remainingValues;\n if (!first) {\n return results;\n }\n\n return maybeAsync(first(), (result) => run(rest, results.concat(result)));\n };\n\n return run(values, []);\n}\n","import { maybeAsync, maybeAsyncArray } from '@lib/maybeAsync';\n\nexport interface PersistStorageBase {\n getItem: (key: string) => string | null | Promise<string | null>;\n setItem: (key: string, value: string) => unknown | Promise<unknown>;\n removeItem: (key: string) => unknown | Promise<unknown>;\n}\n\nexport interface PersistStorageWithKeys extends PersistStorageBase {\n keys: () => string[] | Promise<string[]>;\n}\n\nexport interface PersistStorageWithLength extends PersistStorageBase {\n length: number | (() => number | Promise<number>);\n key: (keyIndex: number) => string | null | Promise<string | null>;\n}\n\nexport type PersistStorage = PersistStorageBase &\n (PersistStorageWithKeys | PersistStorageWithLength);\n\nexport function normalizeStorage(storage: PersistStorage): PersistStorageWithKeys {\n return {\n getItem: storage.getItem.bind(storage),\n setItem: storage.setItem.bind(storage),\n removeItem: storage.removeItem.bind(storage),\n\n keys(): string[] | Promise<string[]> {\n if ('keys' in storage) {\n return storage.keys();\n }\n\n return maybeAsync(\n storage.length instanceof Function ? storage.length() : storage.length,\n (length) => {\n const keyPromises = maybeAsyncArray(\n Array.from({ length }, (_, index) => () => storage.key(index)),\n );\n\n return maybeAsync(keyPromises, (keys) =>\n keys.filter((key): key is string => typeof key === 'string'),\n );\n },\n );\n },\n };\n}\n","import type { KeyType } from './path';\n\nexport type Patch =\n | { op: 'add'; path: KeyType[]; value: any }\n | { op: 'remove'; path: KeyType[] }\n | { op: 'replace'; path: KeyType[]; value: any };\n\nexport function diff(a: any, b: any): [patches: Patch[], reversePatches: Patch[]] {\n const result = [..._diff(a, b)];\n const patches = result.map(([patch]) => patch);\n const reversePatches = result.map(([, reversePatch]) => reversePatch);\n\n return [patches, reversePatches];\n}\n\nfunction* _diff(\n a: any,\n b: any,\n prefix: KeyType[] = [],\n): Iterable<[patch: Patch, reversePatch: Patch]> {\n if (a === b) {\n return;\n }\n\n if (a instanceof Map && b instanceof Map) {\n return yield* mapDiff(a, b, prefix);\n }\n\n if (a instanceof Set && b instanceof Set) {\n a = [...a];\n b = [...b];\n }\n\n if (a instanceof Object && b instanceof Object && Array.isArray(a) === Array.isArray(b)) {\n return yield* objectDiff(a, b, prefix);\n }\n\n yield [\n { op: 'replace', path: prefix, value: b },\n { op: 'replace', path: prefix, value: a },\n ];\n}\n\nfunction* mapDiff(\n a: Map<any, any>,\n b: Map<any, any>,\n prefix: KeyType[],\n): Iterable<[patch: Patch, reversePatch: Patch]> {\n for (const [key, value] of a) {\n if (!b.has(key)) {\n yield [\n { op: 'remove', path: [...prefix, key] },\n { op: 'add', path: [...prefix, key], value },\n ];\n } else {\n yield* _diff(value, b.get(key), [...prefix, key]);\n }\n }\n\n for (const [key, value] of b) {\n if (!a.has(key)) {\n yield [\n { op: 'add', path: [...prefix, key], value },\n { op: 'remove', path: [...prefix, key] },\n ];\n }\n }\n}\n\nfunction* objectDiff(\n a: any,\n b: any,\n prefix: KeyType[],\n): Iterable<[patch: Patch, reversePatch: Patch]> {\n const castKey = (key: string) => (Array.isArray(a) ? Number(key) : key);\n\n for (const [key, value] of Object.entries(a)) {\n if (!(key in b)) {\n yield [\n { op: 'remove', path: [...prefix, castKey(key)] },\n { op: 'add', path: [...prefix, castKey(key)], value },\n ];\n } else {\n yield* _diff(value, b[key], [...prefix, castKey(key)]);\n }\n }\n\n for (const [key, value] of Object.entries(b)) {\n if (!(key in a)) {\n yield [\n { op: 'add', path: [...prefix, castKey(key)], value },\n { op: 'remove', path: [...prefix, castKey(key)] },\n ];\n }\n }\n}\n","import { isAncestor } from './persistPathHelpers';\nimport {\n normalizeStorage,\n type PersistStorage,\n type PersistStorageWithKeys,\n} from './persistStorage';\nimport { type Cancel, type Store } from '@core';\nimport { diff } from '@lib/diff';\nimport { shallowEqual } from '@lib/equals';\nimport { maybeAsync, maybeAsyncArray } from '@lib/maybeAsync';\nimport type { KeyType, WildcardPath } from '@lib/path';\nimport { castArrayPath, get, set } from '@lib/propAccess';\nimport { queue } from '@lib/queue';\n\ntype PathOption<T> =\n | WildcardPath<T>\n | {\n path: WildcardPath<T>;\n throttleMs?: number;\n };\n\nexport interface PersistOptions<T> {\n id: string;\n storage: PersistStorage;\n paths?: PathOption<T>[];\n throttleMs?: number;\n}\n\nexport class Persist<T> {\n storage: PersistStorageWithKeys;\n\n paths: {\n path: KeyType[];\n throttleMs?: number;\n }[];\n\n channel: BroadcastChannel;\n\n queue = queue();\n\n handles = new Set<Cancel>();\n\n stopped = false;\n\n updateInProgress?: [any, any];\n\n constructor(public readonly store: Store<T>, public readonly options: PersistOptions<T>) {\n this.storage = normalizeStorage(options.storage);\n this.channel = new BroadcastChannel(`cross-state-persist_${options.id}`);\n\n this.paths = (options.paths ?? [])\n .map<{\n path: KeyType[];\n throttleMs?: number;\n }>((p) => {\n if (isPlainPath(p)) {\n return { path: castArrayPath(p) };\n }\n\n const _p = p as { path: KeyType[]; throttleMs?: number };\n\n return {\n path: castArrayPath(_p.path),\n throttleMs: _p.throttleMs,\n };\n })\n .sort((a, b) => b.path.length - a.path.length);\n\n if (this.paths.length === 0) {\n this.paths.push({ path: ['*'] });\n }\n\n this.watchStore();\n this.watchStorage();\n }\n\n watchStore() {\n let committed = this.store.get();\n\n const cancel = this.store.subscribe(\n (value) => {\n const [patches] = diff(committed, value);\n committed = value;\n\n for (const patch of patches) {\n if (\n this.updateInProgress &&\n shallowEqual(this.updateInProgress[0], patch.path) &&\n this.updateInProgress[1] === (patch.op === 'remove' ? undefined : patch.value)\n ) {\n continue;\n }\n\n const ancestor = this.paths.find((p) => isAncestor(p.path, patch.path));\n\n if (!ancestor) {\n continue;\n }\n\n const pathToSave = patch.path.slice(0, ancestor.path.length);\n this.queue(() => this.save(pathToSave), pathToSave);\n }\n },\n { runNow: false },\n );\n\n this.handles.add(cancel);\n }\n\n async watchStorage() {\n let keys = this.storage.keys();\n if (keys instanceof Promise) {\n keys = await keys;\n }\n\n if (this.stopped) {\n return;\n }\n\n for (const key of keys) {\n const path = JSON.parse(key);\n this.queue(() => this.load(path));\n }\n\n const listener = (event: MessageEvent) => {\n this.queue(() => this.load(event.data));\n };\n\n this.channel.addEventListener('message', listener);\n this.handles.add(() => this.channel.removeEventListener('message', listener));\n }\n\n load(path: KeyType[]) {\n const matchingPath = this.paths.find(\n (p) => p.path.length === path.length && isAncestor(p.path, path),\n );\n if (!matchingPath) {\n return;\n }\n\n const key = JSON.stringify(path);\n\n return maybeAsync(this.storage.getItem(key), (value) => {\n if (this.stopped || !value) {\n return;\n }\n\n const inSaveQueue = this.queue\n .getRefs()\n .find((ref) => isAncestor(ref, path) || isAncestor(path, ref));\n if (inSaveQueue) {\n return;\n }\n\n const parsedValue = value === 'undefined' ? undefined : JSON.parse(value);\n\n this.updateInProgress = [path, parsedValue];\n this.store.set((state) => set(state, path as any, parsedValue));\n this.updateInProgress = undefined;\n });\n }\n\n save(path: KeyType[]) {\n const key = JSON.stringify(path);\n const value = get(this.store.get(), path as any);\n const serializedValue = value === undefined ? 'undefined' : JSON.stringify(value);\n\n return maybeAsync(this.storage.setItem(key, serializedValue), () => {\n this.channel.postMessage(path);\n\n return maybeAsync(this.storage.keys(), (keys) => {\n const toRemove = keys.filter((k) => {\n const parsedKey = JSON.parse(k);\n return (\n parsedKey.length > path.length && isAncestor(path, parsedKey)\n // !this.queue.getRefs().find((ref) => isAncestor(ref, parsedKey))\n );\n });\n\n return maybeAsyncArray(toRemove.map((k) => () => this.storage.removeItem(k)));\n });\n });\n }\n\n async stop() {\n this.stopped = true;\n\n for (const handle of this.handles) {\n handle();\n }\n\n await this.queue.whenDone();\n this.channel.close();\n }\n}\n\nexport function persist<T>(store: Store<T>, options: PersistOptions<T>): Persist<T> {\n return new Persist<T>(store, options);\n}\n\nfunction isPlainPath<T>(p: PathOption<T>): p is WildcardPath<T> & (KeyType[] | string) {\n return typeof p === 'string' || Array.isArray(p);\n}\n"],"names":["Store","createStore","InstanceCache","calcDuration","allResources","store","queue","castArrayPath","shallowEqual","set","get"],"mappings":";;;;;AA2BO,MAAM,0BAA6BA,MAAAA,MAAqB;AAAA,EAM7D,YACkB,iBACA,UAAoC,CAAA,GACpC,8BAIhB,OACA;AACM,UAAA,QAAW,SAAS,QAAW,KAAK;AAR1B,SAAA,kBAAA;AACA,SAAA,UAAA;AACA,SAAA,+BAAA;AARlB,SAAS,QAAQC,kBAAY;AAAA,MAC3B,iBAAiB;AAAA,MACjB,OAAO;AAAA,IAAA,CACR;AAaC,SAAK,kBAAkB,UAAU;AAAA,MAC/B,GAAG,KAAK,kBAAkB;AAAA,MAC1B,WAAW,CAAC,YAAY;AAClB,YAAA,SAAS,gBAAgB,MAAM,OAAO;AAE1C,YAAI,kBAAkB,YAAY,OAAO,SAAS,GAAG;AACnD,mBAAS,OAAO,OAAO;AAAA,QACzB;AAEO,eAAA;AAAA,MACT;AAAA,MACA,SAAS,CAAC,UAAU;AAClB,aAAK,IAAI,KAAK;AAAA,MAChB;AAAA,MACA,SAAS,CAAC,UAAU;AACb,aAAA,MAAM,IAAI,SAAS,KAAK;AAAA,MAC/B;AAAA,MACA,mBAAmB,CAAC,UAAU;AACvB,aAAA,MAAM,IAAI,mBAAmB,KAAK;AAAA,MACzC;AAAA,MACA,cAAc,MAAM;AAClB,aAAK,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AA,YAAY,KAAK,MAAM,CAAC;AAC9B,iBACE,UAAU,SAAS,KAAK,UAAU,WAAW,MAAM,SAAS;AAAA,QAAA,CAG/D;AAEM,eAAA,gBAAgB,SAAS,IAAI,CAAC,MAAM,MAAM,KAAK,QAAQ,WAAW,CAAC,CAAC,CAAC;AAAA,MAAA,CAC7E;AAAA,IAAA,CACF;AAAA,EACH;AAAA,EAEA,MAAM,OAAO;AACX,SAAK,UAAU;AAEJ,eAAA,UAAU,KAAK,SAAS;AAC1B;IACT;AAEM,UAAA,KAAK,MAAM;AACjB,SAAK,QAAQ;EACf;AACF;AAEgB,SAAA,QAAWL,QAAiB,SAAwC;AAC3E,SAAA,IAAI,QAAWA,QAAO,OAAO;AACtC;AAEA,SAAS,YAAe,GAA+D;AACrF,SAAO,OAAO,MAAM,YAAY,MAAM,QAAQ,CAAC;AACjD;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/cjs/react/index.cjs
CHANGED
|
@@ -1,12 +1,162 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
4
|
const require$$0 = require("react");
|
|
5
|
+
const useCache = require("../useCache.cjs");
|
|
5
6
|
const store = require("../store.cjs");
|
|
6
|
-
const
|
|
7
|
-
|
|
7
|
+
const scope = require("../scope.cjs");
|
|
8
|
+
function wildcardMatch(s, w) {
|
|
9
|
+
if (typeof s === "string") {
|
|
10
|
+
s = store.castArrayPath(s);
|
|
11
|
+
}
|
|
12
|
+
if (typeof w === "string") {
|
|
13
|
+
w = store.castArrayPath(w);
|
|
14
|
+
}
|
|
15
|
+
return s.length === w.length && s.every((s2, i) => w[i] === "*" || s2 === w[i]);
|
|
16
|
+
}
|
|
17
|
+
function getWildCardMatches(object, path) {
|
|
18
|
+
const matches = {};
|
|
19
|
+
const [first, ...rest] = store.castArrayPath(path);
|
|
20
|
+
if (first === void 0) {
|
|
21
|
+
return object;
|
|
22
|
+
}
|
|
23
|
+
if (!(object instanceof Object)) {
|
|
24
|
+
return {};
|
|
25
|
+
}
|
|
26
|
+
if (first === "*") {
|
|
27
|
+
for (const [key, value] of Object.entries(object)) {
|
|
28
|
+
matches[key] = getWildCardMatches(value, rest);
|
|
29
|
+
}
|
|
30
|
+
} else {
|
|
31
|
+
matches[first] = getWildCardMatches(object[first], rest);
|
|
32
|
+
}
|
|
33
|
+
return matches;
|
|
34
|
+
}
|
|
35
|
+
class Form {
|
|
36
|
+
constructor(options) {
|
|
37
|
+
this.options = options;
|
|
38
|
+
this.context = require$$0.createContext({
|
|
39
|
+
original: void 0,
|
|
40
|
+
options: this.options
|
|
41
|
+
});
|
|
42
|
+
this.state = new scope.Scope({});
|
|
43
|
+
this.Provider = this.Provider.bind(this);
|
|
44
|
+
}
|
|
45
|
+
Provider({
|
|
46
|
+
children,
|
|
47
|
+
original,
|
|
48
|
+
defaultValue = this.options.defaultValue,
|
|
49
|
+
validations = this.options.validations
|
|
50
|
+
}) {
|
|
51
|
+
const value = require$$0.useMemo(
|
|
52
|
+
() => ({ original, options: { defaultValue, validations } }),
|
|
53
|
+
[original, defaultValue, validations]
|
|
54
|
+
);
|
|
55
|
+
return /* @__PURE__ */ jsxRuntime.jsx(this.context.Provider, { value, children: /* @__PURE__ */ jsxRuntime.jsx(this.state.Provider, { children }) });
|
|
56
|
+
}
|
|
57
|
+
useForm() {
|
|
58
|
+
const { original, options } = require$$0.useContext(this.context);
|
|
59
|
+
const state = useCache.useScope(this.state);
|
|
60
|
+
return require$$0.useMemo(
|
|
61
|
+
() => ({
|
|
62
|
+
original,
|
|
63
|
+
draft: state.map(
|
|
64
|
+
(state2) => state2.draft ?? original ?? options.defaultValue,
|
|
65
|
+
(draft) => (state2) => ({ ...state2, draft })
|
|
66
|
+
),
|
|
67
|
+
getField(path) {
|
|
68
|
+
const { draft } = this;
|
|
69
|
+
return {
|
|
70
|
+
get originalValue() {
|
|
71
|
+
return original !== void 0 ? store.get(original, path) : void 0;
|
|
72
|
+
},
|
|
73
|
+
get value() {
|
|
74
|
+
return store.get(draft.get(), path);
|
|
75
|
+
},
|
|
76
|
+
setValue(update) {
|
|
77
|
+
draft.set(path, update);
|
|
78
|
+
},
|
|
79
|
+
get isDirty() {
|
|
80
|
+
return state.get().hasTriggeredValidations || !store.deepEqual(this.originalValue, this.value);
|
|
81
|
+
},
|
|
82
|
+
get error() {
|
|
83
|
+
const blocks = Object.entries(
|
|
84
|
+
options.validations ?? {}
|
|
85
|
+
).filter(([key]) => wildcardMatch(path, key)).map(([, value2]) => value2);
|
|
86
|
+
const value = this.value;
|
|
87
|
+
const draftValue = draft.get();
|
|
88
|
+
for (const block of blocks ?? []) {
|
|
89
|
+
for (const [validationName, validate] of Object.entries(block)) {
|
|
90
|
+
if (!validate(value, { draft: draftValue, original, field: path })) {
|
|
91
|
+
return validationName;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return void 0;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
},
|
|
99
|
+
hasChanges() {
|
|
100
|
+
const { draft } = state.get();
|
|
101
|
+
return !!draft && !store.deepEqual(draft, original);
|
|
102
|
+
},
|
|
103
|
+
getErrors() {
|
|
104
|
+
const draft = this.draft.get();
|
|
105
|
+
const errors = /* @__PURE__ */ new Set();
|
|
106
|
+
for (const [path, block] of Object.entries(options.validations ?? {})) {
|
|
107
|
+
for (const [validationName, validate] of Object.entries(
|
|
108
|
+
block
|
|
109
|
+
)) {
|
|
110
|
+
for (const [field, value] of Object.entries(getWildCardMatches(draft, path))) {
|
|
111
|
+
if (!validate(value, { draft, original, field })) {
|
|
112
|
+
errors.add(`${field}.${validationName}`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return [...errors];
|
|
118
|
+
},
|
|
119
|
+
isValid() {
|
|
120
|
+
return this.getErrors().length === 0;
|
|
121
|
+
},
|
|
122
|
+
validate() {
|
|
123
|
+
state.set("hasTriggeredValidations", true);
|
|
124
|
+
return this.isValid();
|
|
125
|
+
},
|
|
126
|
+
reset() {
|
|
127
|
+
state.set("draft", void 0);
|
|
128
|
+
}
|
|
129
|
+
}),
|
|
130
|
+
[original, options, state]
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
useField(path, useStoreOptions) {
|
|
134
|
+
const form = this.useForm();
|
|
135
|
+
const state = useCache.useScope(this.state);
|
|
136
|
+
useCache.useStore(
|
|
137
|
+
form.draft.map((draft) => store.get(draft, path)),
|
|
138
|
+
useStoreOptions
|
|
139
|
+
);
|
|
140
|
+
useCache.useStore(
|
|
141
|
+
state.map((state2) => state2.hasTriggeredValidations),
|
|
142
|
+
useStoreOptions
|
|
143
|
+
);
|
|
144
|
+
return form.getField(path);
|
|
145
|
+
}
|
|
146
|
+
useHasChanges() {
|
|
147
|
+
const form = this.useForm();
|
|
148
|
+
return useCache.useStore(form.draft.map(() => form.hasChanges()));
|
|
149
|
+
}
|
|
150
|
+
useIsValid() {
|
|
151
|
+
const form = this.useForm();
|
|
152
|
+
return useCache.useStore(form.draft.map(() => form.isValid()));
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
function createForm(options) {
|
|
156
|
+
return new Form(options);
|
|
157
|
+
}
|
|
8
158
|
function read(cache, options) {
|
|
9
|
-
const { status, value, error } =
|
|
159
|
+
const { status, value, error } = useCache.useCache(cache, options);
|
|
10
160
|
if (status === "value") {
|
|
11
161
|
return value;
|
|
12
162
|
}
|
|
@@ -40,15 +190,17 @@ function useDecoupledState(value, onChange, options = {}) {
|
|
|
40
190
|
setDirty({ v: value2 });
|
|
41
191
|
delayedUpdate(value2);
|
|
42
192
|
};
|
|
43
|
-
}, [
|
|
193
|
+
}, [scope.hash([options.debounce, options.throttle])]);
|
|
44
194
|
return [dirty ? dirty.v : value, update];
|
|
45
195
|
}
|
|
46
|
-
exports.ScopeProvider =
|
|
47
|
-
exports.reactMethods =
|
|
48
|
-
exports.useCache =
|
|
49
|
-
exports.useProp =
|
|
50
|
-
exports.useScope =
|
|
51
|
-
exports.useStore =
|
|
196
|
+
exports.ScopeProvider = useCache.ScopeProvider;
|
|
197
|
+
exports.reactMethods = useCache.reactMethods;
|
|
198
|
+
exports.useCache = useCache.useCache;
|
|
199
|
+
exports.useProp = useCache.useProp;
|
|
200
|
+
exports.useScope = useCache.useScope;
|
|
201
|
+
exports.useStore = useCache.useStore;
|
|
202
|
+
exports.Form = Form;
|
|
203
|
+
exports.createForm = createForm;
|
|
52
204
|
exports.read = read;
|
|
53
205
|
exports.useDecoupledState = useDecoupledState;
|
|
54
206
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../../src/react/read.ts","../../../src/react/useDecoupledState.ts"],"sourcesContent":["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 { startTransition, useEffect, useMemo, useRef, useState } from 'react';\nimport { type Duration } from '@core';\nimport { debounce } from '@lib/debounce';\nimport { hash } from '@lib/hash';\nimport { throttle } from '@lib/throttle';\n\nexport interface UseDecoupledStateOptions<T> {\n debounce?: Duration;\n throttle?: Duration;\n onCommit?: (value: T) => void;\n}\n\nexport function useDecoupledState<T>(\n value: T,\n onChange: (value: T) => void,\n options: UseDecoupledStateOptions<T> = {},\n): [state: T, setState: (value: T) => void] {\n const [dirty, setDirty] = useState<{ v: T }>();\n const ref = useRef({ onChange, onCommit: options.onCommit });\n\n useEffect(() => {\n ref.current = { onChange, onCommit: options.onCommit };\n }, [onChange]);\n\n const update = useMemo(() => {\n const { onChange, onCommit } = ref.current;\n\n const update = (value: T) => {\n onChange(value);\n setDirty(undefined);\n onCommit?.(value);\n };\n\n let delayedUpdate: (value: T) => void;\n\n if (options.debounce) {\n delayedUpdate = debounce(update, options.debounce);\n } else if (options.throttle) {\n delayedUpdate = throttle(update, options.throttle);\n } else {\n delayedUpdate = (value) => startTransition(() => update(value));\n }\n\n return (value: T) => {\n setDirty({ v: value });\n delayedUpdate(value);\n };\n }, [hash([options.debounce, options.throttle])]);\n\n return [dirty ? dirty.v : value, update];\n}\n"],"names":["useCache","useState","useRef","useEffect","useMemo","onChange","update","value","debounce","throttle","startTransition","hash"],"mappings":";;;;;;;AAIgB,SAAA,KAAQ,OAAiB,SAA8B;AACrE,QAAM,EAAE,QAAQ,OAAO,MAAU,IAAAA,eAAS,OAAO,OAAO;AAExD,MAAI,WAAW,SAAS;AACf,WAAA;AAAA,EACT;AAEA,MAAI,WAAW,SAAS;AAChB,UAAA;AAAA,EACR;AAEA,QAAM,MAAM,MAAM,KAAK,CAAC,UAAU,MAAM,WAAW,SAAS;AAC9D;ACJO,SAAS,kBACd,OACA,UACA,UAAuC,CAAA,GACG;AAC1C,QAAM,CAAC,OAAO,QAAQ,IAAIC,WAAmB,SAAA;AAC7C,QAAM,MAAMC,WAAAA,OAAO,EAAE,UAAU,UAAU,QAAQ,UAAU;AAE3DC,aAAAA,UAAU,MAAM;AACd,QAAI,UAAU,EAAE,UAAU,UAAU,QAAQ;EAAS,GACpD,CAAC,QAAQ,CAAC;AAEP,QAAA,SAASC,WAAAA,QAAQ,MAAM;AAC3B,UAAM,EAAE,UAAAC,WAAU,SAAA,IAAa,IAAI;AAE7BC,UAAAA,UAAS,CAACC,WAAa;AAC3BF,gBAASE,MAAK;AACd,eAAS,MAAS;AAClB,2CAAWA;AAAAA,IAAK;AAGd,QAAA;AAEJ,QAAI,QAAQ,UAAU;AACJ,sBAAAC,MAAAA,SAASF,SAAQ,QAAQ,QAAQ;AAAA,IAAA,WACxC,QAAQ,UAAU;AACX,sBAAAG,MAAAA,SAASH,SAAQ,QAAQ,QAAQ;AAAA,IAAA,OAC5C;AACL,sBAAgB,CAACC,WAAUG,WAAAA,gBAAgB,MAAMJ,QAAOC,MAAK,CAAC;AAAA,IAChE;AAEA,WAAO,CAACA,WAAa;AACV,eAAA,EAAE,GAAGA,OAAAA,CAAO;AACrB,oBAAcA,MAAK;AAAA,IAAA;AAAA,EACrB,GACC,CAACI,KAAAA,KAAK,CAAC,QAAQ,UAAU,QAAQ,QAAQ,CAAC,CAAC,CAAC;AAE/C,SAAO,CAAC,QAAQ,MAAM,IAAI,OAAO,MAAM;AACzC;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../../src/lib/wildcardMatch.ts","../../../src/react/form.tsx","../../../src/react/read.ts","../../../src/react/useDecoupledState.ts"],"sourcesContent":["import { type KeyType } from './path';\nimport { castArrayPath } from './propAccess';\n\nexport function wildcardMatch(s: KeyType[] | string, w: KeyType[] | string): boolean {\n if (typeof s === 'string') {\n s = castArrayPath(s);\n }\n\n if (typeof w === 'string') {\n w = castArrayPath(w);\n }\n\n return s.length === w.length && s.every((s, i) => w[i] === '*' || s === w[i]);\n}\n\nexport function getWildCardMatches(object: any, path: KeyType[] | string): Record<KeyType, any> {\n const matches: Record<KeyType, any> = {};\n const [first, ...rest] = castArrayPath(path);\n\n if (first === undefined) {\n return object;\n }\n\n if (!(object instanceof Object)) {\n return {};\n }\n\n if (first === '*') {\n for (const [key, value] of Object.entries(object)) {\n matches[key] = getWildCardMatches(value, rest);\n }\n } else {\n matches[first] = getWildCardMatches(object[first], rest);\n }\n\n return matches;\n}\n","/* eslint-disable react-hooks/rules-of-hooks */\n\nimport { createContext, useContext, useMemo, type ReactNode } from 'react';\nimport { useScope } from './scope';\nimport { useStore, type UseStoreOptions } from './useStore';\nimport { Scope } from '@core';\nimport { deepEqual } from '@lib/equals';\nimport {\n type PathAsString,\n type Value,\n type WildcardMatch,\n type WildcardPathAsString,\n type WildcardValue,\n} from '@lib/path';\nimport { get } from '@lib/propAccess';\nimport { getWildCardMatches, wildcardMatch } from '@lib/wildcardMatch';\n\nexport interface FormOptions<\n TDraft,\n TOriginal,\n TValidations extends Validations<TDraft, TOriginal>,\n> {\n defaultValue: TDraft;\n validations?: TValidations;\n}\n\nexport type Validation<TValue, TDraft, TOriginal> = (\n value: TValue,\n context: { draft: TDraft; original: TOriginal; field: PathAsString<TDraft> },\n) => boolean;\n\nexport type Validations<TDraft, TOriginal> = {\n [P in WildcardPathAsString<TDraft>]?: Record<\n string,\n Validation<WildcardValue<TDraft, P>, TDraft, TOriginal>\n >;\n};\n\nexport interface Field<\n TDraft,\n TOriginal,\n TPath extends PathAsString<TDraft>,\n TValidations extends Validations<TDraft, TOriginal>,\n> {\n originalValue: Value<TOriginal, TPath> | undefined;\n value: Value<TDraft, TPath>;\n setValue: (\n value: Value<TDraft, TPath> | ((value: Value<TDraft, TPath>) => Value<TDraft, TPath>),\n ) => void;\n isDirty: boolean;\n error?: keyof {\n [P in keyof TValidations as WildcardMatch<TPath, P> extends true\n ? keyof TValidations[P]\n : never]: 1;\n };\n}\n\nexport class Form<\n TDraft,\n TOriginal extends TDraft = TDraft,\n TValidations extends Validations<TDraft, TOriginal> = {},\n> {\n private context = createContext({\n original: undefined as TOriginal | undefined,\n options: this.options,\n });\n\n private state = new Scope<{\n draft?: TDraft;\n hasTriggeredValidations?: boolean;\n }>({});\n\n constructor(public readonly options: FormOptions<TDraft, TOriginal, TValidations>) {\n this.Provider = this.Provider.bind(this);\n }\n\n Provider({\n children,\n original,\n defaultValue = this.options.defaultValue,\n validations = this.options.validations,\n }: { children?: ReactNode; original?: TOriginal } & Partial<\n FormOptions<TDraft, TOriginal, TValidations>\n >) {\n const value = useMemo(\n () => ({ original, options: { defaultValue, validations } }),\n [original, defaultValue, validations],\n );\n\n return (\n <this.context.Provider value={value}>\n <this.state.Provider>{children}</this.state.Provider>\n </this.context.Provider>\n );\n }\n\n useForm() {\n const { original, options } = useContext(this.context);\n const state = useScope(this.state);\n\n return useMemo(\n () => ({\n original,\n\n draft: state.map(\n (state) => state.draft ?? original ?? options.defaultValue,\n (draft) => (state) => ({ ...state, draft }),\n ),\n\n getField<TPath extends PathAsString<TDraft>>(\n path: TPath,\n ): Field<TDraft, TOriginal, TPath, TValidations> {\n const { draft } = this;\n\n return {\n get originalValue() {\n return original !== undefined ? get(original as any, path as any) : undefined;\n },\n\n get value() {\n return get(draft.get(), path);\n },\n\n setValue(update) {\n draft.set(path, update);\n },\n\n get isDirty() {\n return (\n state.get().hasTriggeredValidations || !deepEqual(this.originalValue, this.value)\n );\n },\n\n get error() {\n const blocks: Record<string, Validation<any, any, any>>[] = Object.entries(\n options.validations ?? {},\n )\n .filter(([key]) => wildcardMatch(path, key))\n .map(([, value]) => value);\n\n const value = this.value;\n const draftValue = draft.get();\n\n for (const block of blocks ?? []) {\n for (const [validationName, validate] of Object.entries(block)) {\n if (!validate(value, { draft: draftValue, original, field: path })) {\n return validationName as any;\n }\n }\n }\n\n return undefined;\n },\n };\n },\n\n hasChanges() {\n const { draft } = state.get();\n return !!draft && !deepEqual(draft, original);\n },\n\n getErrors(): (keyof {\n [Field in PathAsString<TDraft> as keyof {\n [Pattern in keyof TValidations as WildcardMatch<Field, Pattern> extends true\n ? `${Field}.${keyof TValidations[Pattern] & string}`\n : never]: 1;\n }]: 1;\n })[] {\n const draft = this.draft.get();\n const errors = new Set<string>();\n\n for (const [path, block] of Object.entries(options.validations ?? {})) {\n for (const [validationName, validate] of Object.entries(\n block as Record<string, Validation<any, any, any>>,\n )) {\n for (const [field, value] of Object.entries(getWildCardMatches(draft, path))) {\n if (!validate(value, { draft, original, field })) {\n errors.add(`${field}.${validationName}`);\n }\n }\n }\n }\n\n return [...errors] as any;\n },\n\n isValid() {\n return this.getErrors().length === 0;\n },\n\n validate() {\n state.set('hasTriggeredValidations', true);\n return this.isValid();\n },\n\n reset() {\n state.set('draft', undefined);\n },\n }),\n [original, options, state],\n );\n }\n\n useField<TPath extends PathAsString<TDraft>>(path: TPath, useStoreOptions?: UseStoreOptions) {\n const form = this.useForm();\n const state = useScope(this.state);\n\n useStore(\n form.draft.map((draft) => get(draft, path)),\n useStoreOptions,\n );\n\n useStore(\n state.map((state) => state.hasTriggeredValidations),\n useStoreOptions,\n );\n\n return form.getField(path);\n }\n\n useHasChanges() {\n const form = this.useForm();\n\n return useStore(form.draft.map(() => form.hasChanges()));\n }\n\n useIsValid() {\n const form = this.useForm();\n\n return useStore(form.draft.map(() => form.isValid()));\n }\n}\n\nexport function createForm<\n TDraft,\n TOriginal extends TDraft = TDraft,\n TValidations extends Validations<TDraft, TOriginal> = {},\n>(options: FormOptions<TDraft, TOriginal, TValidations>) {\n return new Form(options);\n}\n\n/* eslint-enable react-hooks/rules-of-hooks */\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 { startTransition, useEffect, useMemo, useRef, useState } from 'react';\nimport { type Duration } from '@core';\nimport { debounce } from '@lib/debounce';\nimport { hash } from '@lib/hash';\nimport { throttle } from '@lib/throttle';\n\nexport interface UseDecoupledStateOptions<T> {\n debounce?: Duration;\n throttle?: Duration;\n onCommit?: (value: T) => void;\n}\n\nexport function useDecoupledState<T>(\n value: T,\n onChange: (value: T) => void,\n options: UseDecoupledStateOptions<T> = {},\n): [state: T, setState: (value: T) => void] {\n const [dirty, setDirty] = useState<{ v: T }>();\n const ref = useRef({ onChange, onCommit: options.onCommit });\n\n useEffect(() => {\n ref.current = { onChange, onCommit: options.onCommit };\n }, [onChange]);\n\n const update = useMemo(() => {\n const { onChange, onCommit } = ref.current;\n\n const update = (value: T) => {\n onChange(value);\n setDirty(undefined);\n onCommit?.(value);\n };\n\n let delayedUpdate: (value: T) => void;\n\n if (options.debounce) {\n delayedUpdate = debounce(update, options.debounce);\n } else if (options.throttle) {\n delayedUpdate = throttle(update, options.throttle);\n } else {\n delayedUpdate = (value) => startTransition(() => update(value));\n }\n\n return (value: T) => {\n setDirty({ v: value });\n delayedUpdate(value);\n };\n }, [hash([options.debounce, options.throttle])]);\n\n return [dirty ? dirty.v : value, update];\n}\n"],"names":["castArrayPath","s","createContext","Scope","useMemo","jsx","useContext","useScope","state","get","deepEqual","value","useStore","useCache","useState","useRef","useEffect","onChange","update","debounce","throttle","startTransition","hash"],"mappings":";;;;;;;AAGgB,SAAA,cAAc,GAAuB,GAAgC;AAC/E,MAAA,OAAO,MAAM,UAAU;AACzB,QAAIA,MAAAA,cAAc,CAAC;AAAA,EACrB;AAEI,MAAA,OAAO,MAAM,UAAU;AACzB,QAAIA,MAAAA,cAAc,CAAC;AAAA,EACrB;AAEA,SAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,CAACC,IAAG,MAAM,EAAE,CAAC,MAAM,OAAOA,OAAM,EAAE,CAAC,CAAC;AAC9E;AAEgB,SAAA,mBAAmB,QAAa,MAAgD;AAC9F,QAAM,UAAgC,CAAA;AACtC,QAAM,CAAC,OAAO,GAAG,IAAI,IAAID,oBAAc,IAAI;AAE3C,MAAI,UAAU,QAAW;AAChB,WAAA;AAAA,EACT;AAEI,MAAA,EAAE,kBAAkB,SAAS;AAC/B,WAAO;EACT;AAEA,MAAI,UAAU,KAAK;AACjB,eAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,MAAM,GAAG;AACjD,cAAQ,GAAG,IAAI,mBAAmB,OAAO,IAAI;AAAA,IAC/C;AAAA,EAAA,OACK;AACL,YAAQ,KAAK,IAAI,mBAAmB,OAAO,KAAK,GAAG,IAAI;AAAA,EACzD;AAEO,SAAA;AACT;ACqBO,MAAM,KAIX;AAAA,EAWA,YAA4B,SAAuD;AAAvD,SAAA,UAAA;AAV5B,SAAQ,UAAUE,yBAAc;AAAA,MAC9B,UAAU;AAAA,M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uC,CAAA,GACG;AAC1C,QAAM,CAAC,OAAO,QAAQ,IAAIC,WAAmB,SAAA;AAC7C,QAAM,MAAMC,WAAAA,OAAO,EAAE,UAAU,UAAU,QAAQ,UAAU;AAE3DC,aAAAA,UAAU,MAAM;AACd,QAAI,UAAU,EAAE,UAAU,UAAU,QAAQ;EAAS,GACpD,CAAC,QAAQ,CAAC;AAEP,QAAA,SAASZ,WAAAA,QAAQ,MAAM;AAC3B,UAAM,EAAE,UAAAa,WAAU,SAAA,IAAa,IAAI;AAE7BC,UAAAA,UAAS,CAACP,WAAa;AAC3BM,gBAASN,MAAK;AACd,eAAS,MAAS;AAClB,2CAAWA;AAAAA,IAAK;AAGd,QAAA;AAEJ,QAAI,QAAQ,UAAU;AACJ,sBAAAQ,MAAAA,SAASD,SAAQ,QAAQ,QAAQ;AAAA,IAAA,WACxC,QAAQ,UAAU;AACX,sBAAAE,MAAAA,SAASF,SAAQ,QAAQ,QAAQ;AAAA,IAAA,OAC5C;AACL,sBAAgB,CAACP,WAAUU,WAAAA,gBAAgB,MAAMH,QAAOP,MAAK,CAAC;AAAA,IAChE;AAEA,WAAO,CAACA,WAAa;AACV,eAAA,EAAE,GAAGA,OAAAA,CAAO;AACrB,oBAAcA,MAAK;AAAA,IAAA;AAAA,EACrB,GACC,CAACW,MAAAA,KAAK,CAAC,QAAQ,UAAU,QAAQ,QAAQ,CAAC,CAAC,CAAC;AAE/C,SAAO,CAAC,QAAQ,MAAM,IAAI,OAAO,MAAM;AACzC;;;;;;;;;;;"}
|
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const
|
|
2
|
+
const useCache = require("../useCache.cjs");
|
|
3
3
|
const store = require("../store.cjs");
|
|
4
|
-
const
|
|
5
|
-
require("
|
|
4
|
+
const cache = require("../cache.cjs");
|
|
5
|
+
const scope = require("../scope.cjs");
|
|
6
6
|
require("react/jsx-runtime");
|
|
7
|
-
require("
|
|
7
|
+
require("react");
|
|
8
8
|
const cacheMethods = {
|
|
9
9
|
useCache(options) {
|
|
10
|
-
return
|
|
10
|
+
return useCache.useCache(this, options);
|
|
11
11
|
}
|
|
12
12
|
};
|
|
13
13
|
const scopeMethods = {
|
|
14
14
|
useScope() {
|
|
15
|
-
return
|
|
15
|
+
return useCache.useScope(this);
|
|
16
16
|
},
|
|
17
17
|
useStore(options) {
|
|
18
|
-
return
|
|
18
|
+
return useCache.useScopeStore(this, options);
|
|
19
19
|
},
|
|
20
20
|
useProp(options) {
|
|
21
|
-
return
|
|
21
|
+
return useCache.useScopeProp(this, options);
|
|
22
22
|
},
|
|
23
23
|
Provider(props) {
|
|
24
|
-
return
|
|
24
|
+
return useCache.ScopeProvider({ ...props, scope: this });
|
|
25
25
|
}
|
|
26
26
|
};
|
|
27
|
-
Object.assign(store.Store.prototype,
|
|
28
|
-
Object.assign(
|
|
29
|
-
Object.assign(scope
|
|
27
|
+
Object.assign(store.Store.prototype, useCache.reactMethods);
|
|
28
|
+
Object.assign(cache.Cache.prototype, cacheMethods);
|
|
29
|
+
Object.assign(scope.Scope.prototype, scopeMethods);
|
|
30
30
|
//# sourceMappingURL=register.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register.cjs","sources":["../../../src/react/register.ts"],"sourcesContent":["import { reactMethods } from './reactMethods';\nimport { ScopeProvider, useScope, useScopeProp, useScopeStore, type ScopeProps } from './scope';\nimport { useCache, type UseCacheOptions } from './useCache';\nimport { type UseStoreOptions } from './useStore';\nimport { Cache, Scope, Store } from '@core';\n\ntype StoreMethods = typeof reactMethods;\ntype CacheMethods = typeof cacheMethods;\ntype ScopeMethods = typeof scopeMethods;\n\ndeclare module '@core' {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n interface Store<T> extends StoreMethods {}\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n interface Cache<T> extends CacheMethods {}\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n interface Scope<T> extends ScopeMethods {}\n}\n\nconst cacheMethods = {\n useCache<T>(this: Cache<T>, options?: UseCacheOptions) {\n return useCache(this, options);\n },\n};\n\nconst scopeMethods = {\n useScope<T>(this: Scope<T>) {\n return useScope(this);\n },\n\n useStore<T>(this: Scope<T>, options?: UseStoreOptions) {\n return useScopeStore(this, options);\n },\n\n useProp<T>(this: Scope<T>, options?: UseStoreOptions) {\n return useScopeProp(this, options);\n },\n\n Provider<T>(this: Scope<T>, props: Omit<ScopeProps<T>, 'scope'>) {\n return ScopeProvider({ ...props, scope: this });\n },\n};\n\nObject.assign(Store.prototype, reactMethods);\nObject.assign(Cache.prototype, cacheMethods);\nObject.assign(Scope.prototype, scopeMethods);\n"],"names":["useCache","useScope","useScopeStore","useScopeProp","ScopeProvider","Store","reactMethods","Cache","Scope"],"mappings":";;;;;;;AAqBA,MAAM,eAAe;AAAA,EACnB,SAA4B,SAA2B;AAC9C,WAAAA,
|
|
1
|
+
{"version":3,"file":"register.cjs","sources":["../../../src/react/register.ts"],"sourcesContent":["import { reactMethods } from './reactMethods';\nimport { ScopeProvider, useScope, useScopeProp, useScopeStore, type ScopeProps } from './scope';\nimport { useCache, type UseCacheOptions } from './useCache';\nimport { type UseStoreOptions } from './useStore';\nimport { Cache, Scope, Store } from '@core';\n\ntype StoreMethods = typeof reactMethods;\ntype CacheMethods = typeof cacheMethods;\ntype ScopeMethods = typeof scopeMethods;\n\ndeclare module '@core' {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n interface Store<T> extends StoreMethods {}\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n interface Cache<T> extends CacheMethods {}\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n interface Scope<T> extends ScopeMethods {}\n}\n\nconst cacheMethods = {\n useCache<T>(this: Cache<T>, options?: UseCacheOptions) {\n return useCache(this, options);\n },\n};\n\nconst scopeMethods = {\n useScope<T>(this: Scope<T>) {\n return useScope(this);\n },\n\n useStore<T>(this: Scope<T>, options?: UseStoreOptions) {\n return useScopeStore(this, options);\n },\n\n useProp<T>(this: Scope<T>, options?: UseStoreOptions) {\n return useScopeProp(this, options);\n },\n\n Provider<T>(this: Scope<T>, props: Omit<ScopeProps<T>, 'scope'>) {\n return ScopeProvider({ ...props, scope: this });\n },\n};\n\nObject.assign(Store.prototype, reactMethods);\nObject.assign(Cache.prototype, cacheMethods);\nObject.assign(Scope.prototype, scopeMethods);\n"],"names":["useCache","useScope","useScopeStore","useScopeProp","ScopeProvider","Store","reactMethods","Cache","Scope"],"mappings":";;;;;;;AAqBA,MAAM,eAAe;AAAA,EACnB,SAA4B,SAA2B;AAC9C,WAAAA,SAAA,SAAS,MAAM,OAAO;AAAA,EAC/B;AACF;AAEA,MAAM,eAAe;AAAA,EACnB,WAA4B;AAC1B,WAAOC,SAAAA,SAAS,IAAI;AAAA,EACtB;AAAA,EAEA,SAA4B,SAA2B;AAC9C,WAAAC,SAAA,cAAc,MAAM,OAAO;AAAA,EACpC;AAAA,EAEA,QAA2B,SAA2B;AAC7C,WAAAC,SAAA,aAAa,MAAM,OAAO;AAAA,EACnC;AAAA,EAEA,SAA4B,OAAqC;AAC/D,WAAOC,SAAAA,cAAc,EAAE,GAAG,OAAO,OAAO,KAAM,CAAA;AAAA,EAChD;AACF;AAEA,OAAO,OAAOC,MAAAA,MAAM,WAAWC,SAAY,YAAA;AAC3C,OAAO,OAAOC,MAAAA,MAAM,WAAW,YAAY;AAC3C,OAAO,OAAOC,MAAAA,MAAM,WAAW,YAAY;"}
|