cross-state 0.56.2 → 0.56.4

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.
Files changed (59) hide show
  1. package/dist/{diff-D7XuntCn.d.cts → diff-BslUrJZE.d.cts} +2 -2
  2. package/dist/{diff-qAkLCsnM.d.ts → diff-CElc7pJI.d.ts} +2 -2
  3. package/dist/index.cjs +3 -3
  4. package/dist/index.d.cts +4 -4
  5. package/dist/index.d.ts +4 -4
  6. package/dist/index.js +3 -3
  7. package/dist/mutative/index.d.cts +2 -2
  8. package/dist/mutative/index.d.ts +2 -2
  9. package/dist/mutative/register.cjs +1 -1
  10. package/dist/mutative/register.d.cts +2 -2
  11. package/dist/mutative/register.d.ts +2 -2
  12. package/dist/mutative/register.js +1 -1
  13. package/dist/{mutativeMethods-DRYtjUcH.d.ts → mutativeMethods-Bhd1Yi22.d.ts} +2 -2
  14. package/dist/{mutativeMethods-Be_XPk5N.d.cts → mutativeMethods-DWhwZRzv.d.cts} +2 -2
  15. package/dist/{patchMethods-BlYtjRUU.d.cts → patchMethods-BT4Tg5aG.d.cts} +3 -3
  16. package/dist/{patchMethods-Dr2OFh02.d.ts → patchMethods-DXWygPZ6.d.ts} +3 -3
  17. package/dist/patches/index.d.cts +3 -3
  18. package/dist/patches/index.d.ts +3 -3
  19. package/dist/patches/register.cjs +1 -1
  20. package/dist/patches/register.d.cts +3 -3
  21. package/dist/patches/register.d.ts +3 -3
  22. package/dist/patches/register.js +1 -1
  23. package/dist/persist/register.cjs +2 -2
  24. package/dist/persist/register.d.cts +2 -2
  25. package/dist/persist/register.d.ts +2 -2
  26. package/dist/persist/register.js +2 -2
  27. package/dist/{persist-DFzbvNoJ.js → persist-CLgS5Cqw.js} +2 -2
  28. package/dist/{persist-DFzbvNoJ.js.map → persist-CLgS5Cqw.js.map} +1 -1
  29. package/dist/{persist-CR3mhti7.d.cts → persist-DVKRq8RQ.d.cts} +2 -2
  30. package/dist/{persist-CQhYPv4d.cjs → persist-DboMIMOK.cjs} +2 -2
  31. package/dist/{persist-CQhYPv4d.cjs.map → persist-DboMIMOK.cjs.map} +1 -1
  32. package/dist/{persist-CIEYJ0rO.d.ts → persist-olbNkcdZ.d.ts} +2 -2
  33. package/dist/react/index.cjs +2 -2
  34. package/dist/react/index.d.cts +3 -3
  35. package/dist/react/index.d.ts +3 -3
  36. package/dist/react/index.js +2 -2
  37. package/dist/react/register.cjs +3 -3
  38. package/dist/react/register.d.cts +3 -3
  39. package/dist/react/register.d.ts +3 -3
  40. package/dist/react/register.js +3 -3
  41. package/dist/{scope-Mhr133F_.js → scope-7LeON9bZ.js} +2 -2
  42. package/dist/{scope-Mhr133F_.js.map → scope-7LeON9bZ.js.map} +1 -1
  43. package/dist/{scope-DkO-RIMy.d.cts → scope-CcBxgcrs.d.cts} +2 -2
  44. package/dist/{scope-C9JXWddv.cjs → scope-CfLlLxo9.cjs} +2 -2
  45. package/dist/{scope-C9JXWddv.cjs.map → scope-CfLlLxo9.cjs.map} +1 -1
  46. package/dist/{scope-ByLCVzKk.d.ts → scope-D3jkIPgn.d.ts} +2 -2
  47. package/dist/{store-DQcFfgKD.cjs → store-CdST5wJZ.cjs} +2 -2
  48. package/dist/{store-DQcFfgKD.cjs.map → store-CdST5wJZ.cjs.map} +1 -1
  49. package/dist/{store-B3PWCx63.d.cts → store-DnZ6fsiJ.d.ts} +2 -2
  50. package/dist/{store-DOEc60aP.js → store-Dx8w7yT-.js} +2 -2
  51. package/dist/{store-DOEc60aP.js.map → store-Dx8w7yT-.js.map} +1 -1
  52. package/dist/{store-BJWoRQIs.d.ts → store-MBrcOgtz.d.cts} +2 -2
  53. package/dist/{storeMethods-YDnpa-6-.cjs → storeMethods-B_RzvMaV.cjs} +2 -2
  54. package/dist/{storeMethods-YDnpa-6-.cjs.map → storeMethods-B_RzvMaV.cjs.map} +1 -1
  55. package/dist/{storeMethods-C7bswcgj.js → storeMethods-BrKuusQ2.js} +2 -2
  56. package/dist/{storeMethods-C7bswcgj.js.map → storeMethods-BrKuusQ2.js.map} +1 -1
  57. package/dist/{storeMethods-wsbbfJzY.d.ts → storeMethods-Cb1ur5K3.d.ts} +3 -3
  58. package/dist/{storeMethods-Dt_mJTe3.d.cts → storeMethods-CmWv1YMe.d.cts} +3 -3
  59. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"store-DQcFfgKD.cjs","names":["state: ValueState<T> | ErrorState | PendingState","value","q: {\n action: Action<any>;\n resolve: (value: any) => void;\n reject: (error: unknown) => void;\n ref?: any;\n }[]","value: T | undefined","connection: { active: boolean; cancel?: Cancel } | undefined","value","cancel: Cancel | undefined","actions: AsyncConnectionActions<any>","_cancel: Cancel | undefined","deepEqual","get","run: (() => void) | undefined","timeout: ReturnType<typeof setTimeout> | undefined","timeoutStarted: number | undefined","debounce","arrayMethods: {\n [P in 'splice' | 'push' | 'pop' | 'shift' | 'unshift' | 'reverse' | 'sort']: <\n T extends Array<any>,\n >(\n this: Store<T>,\n ...args: T[P] extends Function_ ? Parameters<T[P]> : never\n ) => T[P] extends Function_ ? ReturnType<T[P]> : never;\n}","timeout: ReturnType<typeof setTimeout> | undefined","getter: T | Calculate<T>","options: StoreOptions<T>","derivedFrom?: {\n store: Store<any>;\n selectors: (Selector<any, any> | AnyPath)[];\n updater: (state: any) => void;\n }","path: any","update: Update<any>","get","set","deepEqual","previousValue: { value: T } | undefined","timer: ReturnType<typeof setTimeout> | undefined","updater: ((value: any) => Update<T>) | undefined","active","methods: StoreMethods | undefined","isObject","createStore: typeof create & { defaultOptions: StoreOptions<any> }"],"sources":["../src/lib/autobind.ts","../src/lib/calcDuration.ts","../src/lib/deferred.ts","../src/lib/isPromise.ts","../src/lib/promiseWithState.ts","../src/lib/queue.ts","../src/lib/calculatedValue.ts","../src/lib/makeSelector.ts","../src/lib/debounce.ts","../src/lib/disposable.ts","../src/lib/forwardError.ts","../src/lib/promiseWithCancel.ts","../src/lib/standardMethods.ts","../src/lib/throttle.ts","../src/core/store.ts"],"sourcesContent":["const marker = Symbol('autobind');\n\nexport const autobind = <\n TClass extends abstract new (...args: any) => any = abstract new (...args: any) => any,\n>(\n _class: TClass,\n): TClass => {\n for (const key of Reflect.ownKeys(_class.prototype)) {\n if (key === 'constructor') {\n continue;\n }\n\n const descriptor = Reflect.getOwnPropertyDescriptor(_class.prototype, key);\n let method = descriptor?.get?.() ?? descriptor?.value;\n let isBinding = false;\n\n if (typeof method !== 'function' || method[marker]) {\n continue;\n }\n\n Reflect.defineProperty(_class.prototype, key, {\n configurable: true,\n get() {\n if (\n isBinding ||\n this === _class.prototype ||\n Object.prototype.hasOwnProperty.call(this, key) ||\n typeof method !== 'function'\n ) {\n return method;\n }\n\n const boundMethod = (...args: any[]) => Reflect.apply(method, this, args);\n boundMethod[marker] = true;\n isBinding = true;\n\n Object.defineProperty(this, key, {\n configurable: true,\n get() {\n return boundMethod;\n },\n });\n\n isBinding = false;\n return boundMethod;\n },\n set(v) {\n method = v;\n },\n });\n }\n\n return _class;\n};\n","import type { Duration } from '../core/commonTypes';\n\nexport function calcDuration(t: Duration): number {\n if (typeof t === 'number') return t;\n return (\n (t.milliseconds ?? 0) +\n (t.seconds ?? 0) * 1000 +\n (t.minutes ?? 0) * 60 * 1000 +\n (t.hours ?? 0) * 60 * 60 * 1000 +\n (t.days ?? 0) * 24 * 60 * 60 * 1000\n );\n}\n","export class Deferred<T = void> extends Promise<T> {\n resolve: (value: T | PromiseLike<T>) => void = () => undefined;\n reject: (reason?: any) => void = () => undefined;\n\n constructor() {\n Object.defineProperty(Deferred, Symbol.species, {\n value: Promise,\n });\n\n const that = {};\n\n super((resolve, reject) => {\n Object.assign(that, { resolve, reject });\n });\n\n Object.assign(this, that);\n }\n}\n","export default function isPromise(value: unknown): value is Promise<unknown> {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'then' in value &&\n typeof value.then === 'function'\n );\n}\n","import isPromise from '@lib/isPromise';\nimport { type ErrorState, type PendingState, type ValueState } from './cacheState';\nimport { type MaybePromise } from './maybePromise';\n\nexport class PromiseWithState<T> extends Promise<T> {\n static override resolve(): PromiseWithState<void>;\n\n static override resolve<T>(value: MaybePromise<T>): PromiseWithState<T>;\n\n static override resolve<T>(value?: MaybePromise<T>) {\n return new PromiseWithState<T>(value as MaybePromise<T>);\n }\n\n static override reject<T = never>(error: unknown): PromiseWithState<T> {\n return new PromiseWithState<T>(Promise.reject(error), { status: 'error', error });\n }\n\n constructor(\n value: MaybePromise<T>,\n public state: ValueState<T> | ErrorState | PendingState = { status: 'pending' },\n ) {\n super((resolve) => resolve(value));\n\n Object.defineProperty(PromiseWithState, Symbol.species, {\n value: Promise,\n });\n\n if (isPromise(value)) {\n value\n .then((value) => {\n this.state = { status: 'value', value: value };\n })\n .catch((error) => {\n this.state = { status: 'error', error };\n });\n } else {\n this.state = { status: 'value', value: value };\n }\n }\n}\n","import isPromise from '@lib/isPromise';\nimport type { MaybePromise } from './maybePromise';\nimport type { Listener } from '@core';\n\ntype Action<T> = () => MaybePromise<T>;\n\nexport interface Queue {\n <T>(action: Action<T>, ref?: any): Promise<T>;\n clear: () => void;\n whenDone: () => Promise<void>;\n size: number;\n getRefs: () => any[];\n}\n\nexport function queue(): Queue {\n const q: {\n action: Action<any>;\n resolve: (value: any) => void;\n reject: (error: unknown) => void;\n ref?: any;\n }[] = [];\n const completionListeners = new Set<Listener<void>>();\n let active = false;\n\n const notify = () => {\n for (const listener of completionListeners) {\n listener();\n }\n\n completionListeners.clear();\n };\n\n const run = async () => {\n if (!active) {\n active = true;\n\n let next;\n while ((next = q.shift())) {\n try {\n let result = next.action();\n if (isPromise(result)) {\n result = await result;\n }\n\n next.resolve(result);\n } catch (error) {\n next.reject(error);\n }\n }\n\n active = false;\n notify();\n }\n };\n\n return Object.assign(\n <T>(action: Action<T>, ref?: any) => {\n return new Promise<T>((resolve, reject) => {\n q.push({ action, resolve, reject, ref });\n run();\n });\n },\n {\n clear() {\n q.length = 0;\n },\n\n whenDone() {\n if (!active) {\n return Promise.resolve();\n }\n\n return new Promise<void>((resolve) => {\n completionListeners.add(resolve);\n });\n },\n\n get size() {\n return q.length;\n },\n\n getRefs() {\n return q.map((item) => item.ref).filter((x) => x !== undefined);\n },\n },\n );\n}\n","import type { Cache } from '@core';\nimport type { AsyncConnectionActions, Cancel, Connection, StoreLike } from '@core/commonTypes';\nimport type { Store } from '@core/store';\nimport { Deferred } from '@lib/deferred';\nimport isPromise from '@lib/isPromise';\nimport { PromiseWithState } from '@lib/promiseWithState';\nimport { queue } from '@lib/queue';\nimport { deepEqual } from './equals';\n\nexport interface CalculatedValue<T> {\n value: T;\n check: () => void;\n stop(): void;\n invalidateDependencies(recursive?: boolean): void;\n}\n\nexport function calculatedValue<T>(store: Store<T>, notify: () => void): CalculatedValue<T> {\n if (!(store.getter instanceof Function)) {\n return staticValue(store.getter);\n }\n\n let active = false;\n const deps = new Array<{ store: StoreLike<any>; value: any; on: () => void; off: () => void }>();\n let value: T | undefined;\n const whenConnected = new Deferred();\n const whenExecuted = new Deferred();\n const ac = new AbortController();\n let connection: { active: boolean; cancel?: Cancel } | undefined;\n const q = queue();\n q(() => whenExecuted);\n\n const cancelEffect = store.addEffect(() => {\n if (connection) {\n store.invalidate();\n return;\n }\n\n active = true;\n\n for (const dep of deps) {\n dep.on();\n }\n\n return () => {\n active = false;\n\n for (const dep of deps) {\n dep.off();\n }\n\n if (connection) {\n connection.active = false;\n connection.cancel?.();\n q.clear();\n\n if ('state' in store) {\n (store as unknown as Cache<any>).state.set((state) => ({\n ...state,\n isConnected: false,\n isStale: true,\n }));\n }\n }\n };\n });\n\n function use<S>(dep: StoreLike<S>) {\n const value = dep.get();\n let cancel: Cancel | undefined;\n\n const on = () => {\n cancel ||= dep.subscribe(() => store.invalidate(), { runNow: false });\n };\n\n const off = () => {\n cancel?.();\n cancel = undefined;\n };\n\n deps.push({ store: dep, value, on, off });\n\n if (active) {\n on();\n }\n\n return value;\n }\n\n async function connect(createConnection: Connection<T>) {\n if (!active) {\n connection = { active: false };\n return;\n }\n\n const actions: AsyncConnectionActions<any> = {\n set(_value) {\n q(() => {\n if (!connection?.active) {\n return;\n }\n\n value = _value;\n notify();\n });\n },\n updateValue(update) {\n q(async () => {\n if (!connection?.active) {\n return;\n }\n\n if (update instanceof Function) {\n const currentValue = await value;\n\n if (!connection?.active) {\n return;\n }\n\n try {\n update = update(currentValue);\n } catch (error) {\n value = PromiseWithState.reject(error) as T;\n notify();\n connection.active = false;\n connection.cancel?.();\n return;\n }\n }\n\n value = PromiseWithState.resolve(update) as T;\n notify();\n });\n },\n updateError(error) {\n q(() => {\n if (!connection?.active) {\n return;\n }\n\n connection.active = false;\n connection.cancel?.();\n\n if ('state' in store) {\n (store as unknown as Cache<any>).state.set({\n status: 'error',\n error,\n isConnected: false,\n isUpdating: false,\n isStale: false,\n });\n }\n\n value = PromiseWithState.reject(error) as T;\n notify();\n });\n },\n updateIsConnected(isConnected) {\n if (isConnected) {\n whenConnected.resolve();\n }\n\n q(() => {\n if (!connection?.active) {\n return;\n }\n\n if ('state' in store) {\n (store as unknown as Cache<any>).state.set('isConnected', isConnected);\n }\n });\n },\n close() {\n if (connection?.active) {\n store.invalidate();\n }\n },\n };\n\n connection = { active: true };\n let _cancel: Cancel | undefined = createConnection(actions as any);\n\n connection.cancel = () => {\n _cancel?.();\n _cancel = undefined;\n };\n\n if (!connection.active) {\n connection.cancel();\n }\n\n return whenConnected;\n }\n\n try {\n value = store.getter({ signal: ac.signal, use, connect });\n } catch (error) {\n value = PromiseWithState.reject(error) as T;\n\n if (connection) {\n connection.active = false;\n connection.cancel?.();\n q.clear();\n }\n }\n\n if (isPromise(value)) {\n value.finally(() => whenExecuted.resolve()).catch(() => undefined);\n } else {\n whenExecuted.resolve();\n }\n\n function check() {\n if (store.options.cacheValue === false) {\n return false;\n }\n\n for (const dep of deps) {\n if (!deepEqual(dep.store.get(), dep.value)) {\n return false;\n }\n }\n return true;\n }\n\n function stop() {\n cancelEffect();\n whenExecuted.resolve();\n whenConnected.resolve();\n ac.abort();\n\n if (connection) {\n connection.active = false;\n connection.cancel?.();\n q.clear();\n }\n }\n\n function invalidateDependencies(recursive?: boolean) {\n for (const dep of deps) {\n dep.store.invalidate(recursive);\n }\n }\n\n return {\n get value() {\n return value!;\n },\n check,\n stop,\n invalidateDependencies,\n };\n}\n\nexport function staticValue<T>(value: T): CalculatedValue<T> {\n return {\n value,\n check: () => true,\n stop: () => undefined,\n invalidateDependencies: () => undefined,\n };\n}\n\nexport function staleValue<T>(value: T): CalculatedValue<T> {\n return {\n value,\n check: () => false,\n stop: () => undefined,\n invalidateDependencies: () => undefined,\n };\n}\n","import type { AnyPath } from './path';\nimport { get } from './propAccess';\n\nexport function makeSelector<T, S>(selector?: ((value: T) => S) | AnyPath): (value: T) => S {\n if (!selector) {\n return (x) => x as any;\n }\n\n if (selector instanceof Function) {\n return selector;\n }\n\n return (x) => get(x, selector as any) as any;\n}\n","import { calcDuration } from './calcDuration';\nimport type { Duration } from '@core';\n\nexport type DebounceOptions =\n | Duration\n | {\n wait: Duration;\n maxWait?: Duration;\n waitOnRunNow?: boolean;\n };\n\nexport function debounce<Args extends any[]>(\n action: (...args: Args) => void,\n options: Duration | DebounceOptions,\n): {\n (...args: Args): void;\n flush(): void;\n cancel(): void;\n isScheduled(): boolean;\n} {\n const wait =\n typeof options === 'object' && 'wait' in options\n ? calcDuration(options.wait)\n : calcDuration(options);\n\n const maxWait =\n typeof options === 'object' && 'maxWait' in options && options.maxWait !== undefined\n ? calcDuration(options.maxWait)\n : undefined;\n\n let run: (() => void) | undefined;\n let timeout: ReturnType<typeof setTimeout> | undefined;\n let timeoutStarted: number | undefined;\n\n function flush() {\n if (timeout !== undefined) {\n clearTimeout(timeout);\n }\n\n run?.();\n }\n\n function cancel() {\n if (timeout !== undefined) {\n clearTimeout(timeout);\n }\n\n run = undefined;\n timeout = undefined;\n timeoutStarted = undefined;\n }\n\n function isScheduled() {\n return timeout !== undefined;\n }\n\n function debounce(...args: Args) {\n const now = Date.now();\n timeoutStarted ??= now;\n\n const deadline = Math.min(\n //\n now + wait,\n timeoutStarted + (maxWait ?? Number.POSITIVE_INFINITY),\n );\n\n if (timeout !== undefined) {\n clearTimeout(timeout);\n }\n\n run = () => {\n run = undefined;\n timeout = undefined;\n timeoutStarted = undefined;\n\n action(...args);\n };\n\n timeout = setTimeout(run, deadline - now);\n }\n\n return Object.assign(debounce, { flush, cancel, isScheduled });\n}\n","import type { Cancel } from '@core';\nimport type { DisposableCancel } from '@core/commonTypes';\n\nexport default function disposable(dispose: Cancel): DisposableCancel {\n return Object.assign(\n dispose,\n Symbol.dispose ? { [Symbol.dispose]: dispose } : {},\n ) as DisposableCancel;\n}\n","export function forwardError(error: unknown): void {\n setTimeout(() => {\n throw error;\n });\n}\n","import { autobind } from '@lib/autobind';\n\nexport class PromiseCancelError extends Error {\n constructor() {\n super('cancelled');\n }\n}\n\nexport class PromiseWithCancel<T> extends Promise<T> {\n private abortController;\n\n constructor(\n executor: (\n resolve: (value: T) => void,\n reject: (error: unknown) => void,\n signal: AbortSignal,\n ) => void,\n ) {\n autobind(PromiseWithCancel);\n const abortController = new AbortController();\n\n super((resolve, reject) => {\n executor(resolve, reject, abortController.signal);\n\n abortController.signal.addEventListener('abort', () => {\n reject(abortController.signal.reason);\n });\n });\n\n this.abortController = abortController;\n }\n\n cancel(reason: any = new PromiseCancelError()): void {\n this.abortController.abort(reason);\n }\n}\n","import type { Store } from '../core/store';\nimport type { OptionalProperties, OptionalPropertyOf } from './typeHelpers';\n\ntype Function_ = (...args: any) => any;\n\nfunction createArrayAction<P extends keyof Array<any>>(prop: P) {\n return function arrayAction<T extends Array<any>>(\n this: Store<T>,\n ...args: T[P] extends Function_ ? Parameters<T[P]> : never\n ): T[P] extends Function_ ? ReturnType<T[P]> : never {\n const newArray = this.get().slice() as T;\n const result = (newArray[prop] as Function_)(...(args as any));\n this.set(newArray);\n return result;\n };\n}\nexport const arrayMethods: {\n [P in 'splice' | 'push' | 'pop' | 'shift' | 'unshift' | 'reverse' | 'sort']: <\n T extends Array<any>,\n >(\n this: Store<T>,\n ...args: T[P] extends Function_ ? Parameters<T[P]> : never\n ) => T[P] extends Function_ ? ReturnType<T[P]> : never;\n} = {\n splice: /* @__PURE__ */ createArrayAction('splice'),\n push: /* @__PURE__ */ createArrayAction('push'),\n pop: /* @__PURE__ */ createArrayAction('pop'),\n shift: /* @__PURE__ */ createArrayAction('shift'),\n unshift: /* @__PURE__ */ createArrayAction('unshift'),\n reverse: /* @__PURE__ */ createArrayAction('reverse'),\n sort: /* @__PURE__ */ createArrayAction('sort'),\n};\n\nexport const recordMethods = {\n delete<T extends Record<any, any>, K extends OptionalPropertyOf<T>>(\n this: Store<T>,\n key: K,\n ): void {\n const copy = { ...this.get() };\n delete copy[key];\n this.set(copy);\n },\n\n clear<T extends Record<any, any>>(\n this: OptionalProperties<T> extends T ? Store<T> : never,\n ): void {\n this.set({} as T);\n },\n};\n\nexport const mapMethods = {\n delete<K, V>(this: Store<Map<K, V>>, key: K): boolean {\n const newMap = new Map(this.get());\n const result = newMap.delete(key);\n this.set(newMap);\n return result;\n },\n\n clear<K, V>(this: Store<Map<K, V>>): void {\n this.set(new Map());\n },\n};\n\nexport const setMethods = {\n add<T>(this: Store<Set<T>>, value: T): void {\n const newSet = new Set(this.get());\n newSet.add(value);\n this.set(newSet);\n },\n\n delete<T>(this: Store<Set<T>>, value: T): void {\n const newSet = new Set(this.get());\n newSet.delete(value);\n this.set(newSet);\n },\n\n clear<T>(this: Store<Set<T>>): void {\n this.set(new Set());\n },\n};\n","import { calcDuration } from './calcDuration';\nimport type { Duration } from '@core';\n\nexport function throttle<Args extends any[]>(\n action: (...args: Args) => void,\n duration: Duration,\n): (...args: Args) => void {\n const ms = calcDuration(duration);\n\n let t = 0;\n let timeout: ReturnType<typeof setTimeout> | undefined;\n\n return (...args: Args) => {\n if (timeout !== undefined) {\n clearTimeout(timeout);\n }\n\n const dt = t + ms - Date.now();\n if (dt <= 0) {\n action(...args);\n t = Date.now();\n return;\n }\n\n timeout = setTimeout(() => {\n action(...args);\n t = Date.now();\n }, dt);\n };\n}\n","import { autobind } from '@lib/autobind';\nimport { calcDuration } from '@lib/calcDuration';\nimport { calculatedValue, staticValue, type CalculatedValue } from '@lib/calculatedValue';\nimport type { Constrain } from '@lib/constrain';\nimport { debounce } from '@lib/debounce';\nimport disposable from '@lib/disposable';\nimport { deepEqual } from '@lib/equals';\nimport { forwardError } from '@lib/forwardError';\nimport { isObject } from '@lib/helpers';\nimport { makeSelector } from '@lib/makeSelector';\nimport type { AnyPath, Path, SettablePath, Value } from '@lib/path';\nimport { PromiseWithCancel } from '@lib/promiseWithCancel';\nimport { get, set } from '@lib/propAccess';\nimport { arrayMethods, mapMethods, recordMethods, setMethods } from '@lib/standardMethods';\nimport { throttle } from '@lib/throttle';\nimport type {\n CalculationActions,\n Cancel,\n DisposableCancel,\n Duration,\n Effect,\n Listener,\n Selector,\n SubscribeOptions,\n Update,\n} from './commonTypes';\n\nexport type StoreMethods = Record<string, (...args: any[]) => any>;\n\nexport type BoundStoreMethods<T, Methods extends StoreMethods> = Methods &\n ThisType<Store<T> & Methods>;\n\nexport interface StoreOptions<T> {\n retain?: Duration;\n equals?: SubscribeOptions['equals'];\n effect?: Effect<Store<T>> | { effect: Effect<Store<T>>; retain?: Duration };\n cacheValue?: boolean;\n}\n\nexport interface StoreOptionsWithMethods<T, Methods extends StoreMethods> extends StoreOptions<T> {\n methods?: Methods & ThisType<Store<T> & Methods & StandardMethods<T>>;\n}\n\nexport type Calculate<T> = (helpers: CalculationActions<T>) => T;\n\ntype StandardMethods<T> =\n T extends Map<any, any>\n ? typeof mapMethods\n : T extends Set<any>\n ? typeof setMethods\n : T extends Array<any>\n ? typeof arrayMethods\n : T extends Record<any, any>\n ? typeof recordMethods\n : Record<string, never>;\n\ntype StoreWithMethods<T, Methods extends StoreMethods> = Store<T> &\n Omit<BoundStoreMethods<T, Methods>, keyof Store<T>> &\n StandardMethods<T>;\n\nexport interface OnceOptions {\n signal?: AbortSignal;\n timeout?: Duration;\n}\n\nfunction noop() {\n return undefined;\n}\n\nexport class Store<T> {\n private static hooks?: Set<(this: Store<any>, store: Store<any>) => void>;\n\n static addHook(hook: (store: Store<any>) => void): DisposableCancel {\n this.hooks ??= new Set();\n this.hooks.add(hook);\n return disposable(() => this.hooks?.delete(hook));\n }\n\n version?: string;\n\n protected calculatedValue?: CalculatedValue<T>;\n protected defaultValue?: CalculatedValue<T>;\n\n protected listeners: Map<Listener, boolean> = new Map();\n\n protected effects: Map<\n Effect<Store<T>>,\n { handle?: Cancel; retain?: number; timeout?: ReturnType<typeof setTimeout> }\n > = new Map();\n\n protected notifyId = {};\n\n constructor(\n public readonly getter: T | Calculate<T>,\n public readonly options: StoreOptions<T> = {},\n public readonly derivedFrom?: {\n store: Store<any>;\n selectors: (Selector<any, any> | AnyPath)[];\n updater: (state: any) => void;\n },\n ) {\n autobind(Store);\n\n if (typeof getter !== 'function') {\n this.calculatedValue = this.defaultValue = staticValue(getter);\n }\n\n for (const hook of Store.hooks ?? []) {\n hook.apply(this, [this]);\n }\n\n if (options.effect instanceof Function) {\n this.addEffect(options.effect);\n } else if (options.effect) {\n this.addEffect(options.effect.effect, options.effect.retain);\n }\n }\n\n get(): T {\n if (!this.calculatedValue?.check()) {\n this.calculatedValue?.stop();\n this.calculatedValue = undefined;\n }\n\n if (!this.calculatedValue) {\n this.calculatedValue = calculatedValue(this, this.notify);\n }\n\n return this.calculatedValue.value;\n }\n\n set(update: Update<T>): void;\n\n set<const P>(path: Constrain<P, Path<T>>, update: Update<Value<T, P>>): void;\n\n set(...args: any[]): void {\n const path: any = args.length > 1 ? args[0] : [];\n let update: Update<any> = args.length > 1 ? args[1] : args[0];\n\n if (update instanceof Function) {\n const before = this.get();\n const valueBefore = get(before, path);\n const valueAfter = update(valueBefore);\n update = set(before, path, valueAfter);\n } else if (path.length > 0) {\n update = set(this.get(), path, update);\n }\n\n if (this.derivedFrom) {\n this.derivedFrom.updater(update);\n return;\n }\n\n this.calculatedValue?.stop();\n this.calculatedValue = staticValue(update);\n this.notify();\n }\n\n invalidate(recursive?: boolean): void {\n if (recursive) {\n this.calculatedValue?.invalidateDependencies(recursive);\n }\n\n this.calculatedValue?.stop();\n this.calculatedValue = this.defaultValue;\n this.notify();\n }\n\n subscribe(\n listener: Listener<T, { cancel: Cancel }>,\n options?: SubscribeOptions,\n ): DisposableCancel {\n const {\n passive,\n runNow = true,\n throttle: throttleOption,\n debounce: debounceOption,\n equals = this.options.equals ?? deepEqual,\n } = options ?? {};\n\n let isSetup = false;\n let previousValue: { value: T } | undefined;\n\n let innerListener = () => {\n if (!isSetup) {\n return;\n }\n\n const value = passive ? this.calculatedValue : { value: this.get() };\n\n if (!value) {\n return;\n }\n\n if (previousValue && equals(value.value, previousValue.value)) {\n return;\n }\n\n const _previousValue = previousValue?.value;\n previousValue = this.calculatedValue && { value: this.calculatedValue?.value };\n\n try {\n listener.apply({ cancel }, [value.value, _previousValue]);\n } catch (error) {\n forwardError(error);\n }\n };\n\n if (throttleOption) {\n innerListener = throttle(innerListener, throttleOption);\n } else if (debounceOption) {\n innerListener = debounce(innerListener, debounceOption);\n }\n\n this.listeners.set(innerListener, !passive);\n const cancel = () => {\n if (this.listeners.delete(innerListener) && !passive) {\n this.onUnsubscribe();\n }\n };\n\n if (!passive) {\n this.onSubscribe();\n }\n\n isSetup = true;\n\n if (runNow) {\n innerListener();\n\n if (\n !throttleOption &&\n typeof debounceOption === 'object' &&\n 'waitOnRunNow' in debounceOption &&\n debounceOption.waitOnRunNow === false &&\n 'flush' in innerListener\n ) {\n (innerListener as { flush: () => void }).flush();\n }\n } else {\n previousValue = passive\n ? this.calculatedValue && { value: this.calculatedValue.value }\n : { value: this.get() };\n }\n\n return disposable(cancel);\n }\n\n once<S extends T>(\n condition: (value: T) => value is S,\n options?: OnceOptions,\n ): PromiseWithCancel<S>;\n\n once(condition: (value: T) => boolean, options?: OnceOptions): PromiseWithCancel<T>;\n\n once(options?: OnceOptions): PromiseWithCancel<T>;\n\n once(\n ...args: [condition: (value: any) => boolean, options?: OnceOptions] | [options?: OnceOptions]\n ): PromiseWithCancel<any> {\n const condition = args[0] instanceof Function ? args[0] : Boolean;\n const options = args[0] instanceof Function ? args[1] : args[0];\n\n return new PromiseWithCancel<T>((resolve, reject, signal) => {\n let stopped = false;\n let timer: ReturnType<typeof setTimeout> | undefined;\n\n const cancel = this.subscribe(\n (value) => {\n if (stopped || !condition(value)) {\n return;\n }\n\n resolve(value);\n stopped = true;\n if (timer) {\n clearTimeout(timer);\n }\n setTimeout(() => cancel());\n },\n {\n runNow: !!condition,\n },\n );\n\n if (stopped) {\n return;\n }\n\n signal.addEventListener('abort', cancel);\n\n options?.signal?.addEventListener('abort', () => {\n cancel();\n reject(options.signal?.reason ?? new Error('cancelled'));\n });\n\n if (options?.timeout !== undefined) {\n timer = setTimeout(() => {\n cancel();\n reject(new Error('timeout'));\n }, calcDuration(options.timeout));\n }\n });\n }\n\n map<S>(selector: Selector<T, S>, updater?: (value: S) => Update<T>): Store<S>;\n\n map<const P>(selector: Constrain<P, SettablePath<T>>): Store<Value<T, P>>;\n\n map(_selector: Selector<T, any> | SettablePath<any>, ...args: any[]): Store<any> {\n const updater: ((value: any) => Update<T>) | undefined =\n _selector instanceof Function\n ? args[0]\n : (value) => (state) => set(state, _selector as any, value);\n\n const selector = makeSelector(_selector);\n\n const derivedFrom = {\n store: this.derivedFrom ? this.derivedFrom.store : this,\n selectors: this.derivedFrom ? [...this.derivedFrom.selectors, _selector] : [_selector],\n\n updater: (value: any) => {\n if (!updater) {\n throw new TypeError(\n 'Can only update computed stores that either are derived from other stores using string selectors or have an updater function.',\n );\n }\n\n let update = updater(value);\n\n if (update instanceof Function) {\n update = update(this.get());\n }\n\n if (this.derivedFrom) {\n this.derivedFrom.updater(update);\n } else {\n this.set(update);\n }\n },\n };\n\n return new Store(\n ({ use }) => {\n return selector(use(this));\n },\n undefined,\n derivedFrom,\n );\n }\n\n /** Add an effect that will be executed when the store becomes active, which means when it has at least one subscriber.\n * @param effect\n * If there is already a subscriber, the effect will be executed immediately.\n * Otherweise it will be executed as soon as the first subscription is created.\n * Every time all subscriptions are removed and the first is created again, the effect will be executed again.\n * @param retain\n * If provided, delay tearing down effects when the last subscriber is removed. This is useful if a short gap in subscriber coverage is supposed to be ignored. E.g. when switching pages, the old page might unsubscribe, while the new page subscribes immediately after.\n * @returns\n * The effect can return a teardown callback, which will be executed when the last subscription is removed and potentially the ratain time has passed.\n */\n addEffect(\n effect: Effect<Store<T>>,\n retain: Duration | undefined = this.options.retain,\n ): DisposableCancel {\n this.effects.set(effect, {\n handle: this.isActive() ? (effect.apply(this, [this]) ?? noop) : undefined,\n retain: retain !== undefined ? calcDuration(retain) : undefined,\n });\n\n return disposable(() => {\n const { handle, timeout } = this.effects.get(effect) ?? {};\n handle?.();\n\n if (timeout !== undefined) {\n clearTimeout(timeout);\n }\n\n this.effects.delete(effect);\n });\n }\n\n /** Return whether the store is currently active, which means whether it has at least one subscriber. */\n isActive(): boolean {\n return [...this.listeners.values()].some(Boolean);\n }\n\n protected onSubscribe(): void {\n if ([...this.listeners.values()].filter(Boolean).length > 1) return;\n\n for (const [effect, { handle, retain, timeout }] of this.effects.entries()) {\n if (timeout !== undefined) {\n clearTimeout(timeout);\n }\n\n this.effects.set(effect, {\n handle: handle ?? effect.apply(this, [this]) ?? noop,\n retain,\n timeout: undefined,\n });\n }\n }\n\n protected onUnsubscribe(): void {\n if ([...this.listeners.values()].some(Boolean)) return;\n\n for (const [effect, { handle, retain, timeout }] of this.effects.entries()) {\n if (!retain) {\n handle?.();\n\n if (timeout !== undefined) {\n clearTimeout(timeout);\n }\n\n this.effects.set(effect, {\n handle: undefined,\n retain,\n timeout: undefined,\n });\n\n continue;\n }\n\n const newTimeout =\n timeout ??\n (handle\n ? setTimeout(() => {\n handle();\n this.effects.set(effect, {\n handle: undefined,\n retain,\n timeout: undefined,\n });\n }, retain)\n : undefined);\n\n this.effects.set(effect, {\n handle,\n retain,\n timeout: newTimeout,\n });\n }\n }\n\n protected notify(): void {\n const n = {};\n this.notifyId = n;\n\n const snapshot = [...this.listeners.entries()];\n const active = snapshot.filter(([, active]) => active);\n const passive = snapshot.filter(([, active]) => !active);\n for (const [listener] of [...active, ...passive]) {\n listener();\n if (n !== this.notifyId) break;\n }\n }\n}\n\nfunction create<T>(calculate: Calculate<T>, options?: StoreOptions<T>): Store<T>;\nfunction create<T, Methods extends StoreMethods = {}>(\n initialState: T,\n options?: StoreOptionsWithMethods<T, Methods>,\n): StoreWithMethods<T, Methods>;\nfunction create<T, Methods extends StoreMethods>(\n initialState: T | Calculate<T>,\n options?: StoreOptionsWithMethods<T, Methods>,\n): StoreWithMethods<T, Methods> | Store<T> {\n options = { ...createStore.defaultOptions, ...options };\n\n const store = new Store(initialState, options);\n\n if (initialState instanceof Function) {\n return store;\n }\n\n let methods: StoreMethods | undefined = options?.methods;\n\n if (initialState instanceof Map) {\n methods = { ...mapMethods, ...methods };\n } else if (initialState instanceof Set) {\n methods = { ...setMethods, ...methods };\n } else if (Array.isArray(initialState)) {\n methods = { ...arrayMethods, ...methods };\n } else if (isObject(initialState)) {\n methods = { ...recordMethods, ...methods };\n }\n\n const boundMethods = Object.fromEntries(\n Object.entries(methods ?? ({} as BoundStoreMethods<T, any>))\n .filter(([name]) => !(name in store))\n .map(([name, action]) => [name, (action as any).bind(store)]),\n ) as BoundStoreMethods<T, any>;\n\n return Object.assign(store, boundMethods);\n}\n\nexport const createStore: typeof create & { defaultOptions: StoreOptions<any> } =\n /* @__PURE__ */ Object.assign(create, {\n defaultOptions: {\n equals: deepEqual,\n } as StoreOptions<any>,\n });\n"],"mappings":";;;AAAA,MAAM,SAAS,OAAO;AAEtB,MAAa,YAGX,WACW;AACX,MAAK,MAAM,OAAO,QAAQ,QAAQ,OAAO,YAAY;AACnD,MAAI,QAAQ,cACV;EAGF,MAAM,aAAa,QAAQ,yBAAyB,OAAO,WAAW;EACtE,IAAI,SAAS,YAA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jD,OAAK,MAAM,CAAC,aAAa,CAAC,GAAG,QAAQ,GAAG,UAAU;AAChD;AACA,OAAI,MAAM,KAAK,SAAU;;;;AAU/B,SAAS,OACP,cACA,SACyC;AACzC,WAAU;EAAE,GAAG,YAAY;EAAgB,GAAG;;CAE9C,MAAM,QAAQ,IAAI,MAAM,cAAc;AAEtC,KAAI,wBAAwB,SAC1B,QAAO;CAGT,IAAIC,UAAoC,SAAS;AAEjD,KAAI,wBAAwB,IAC1B,WAAU;EAAE,GAAG;EAAY,GAAG;;UACrB,wBAAwB,IACjC,WAAU;EAAE,GAAG;EAAY,GAAG;;UACrB,MAAM,QAAQ,cACvB,WAAU;EAAE,GAAG;EAAc,GAAG;;UACvBC,4BAAS,cAClB,WAAU;EAAE,GAAG;EAAe,GAAG;;CAGnC,MAAM,eAAe,OAAO,YAC1B,OAAO,QAAQ,WAAY,IACxB,QAAQ,CAAC,UAAU,EAAE,QAAQ,QAC7B,KAAK,CAAC,MAAM,YAAY,CAAC,MAAO,OAAe,KAAK;AAGzD,QAAO,OAAO,OAAO,OAAO;;AAG9B,MAAaC,cACK,uBAAO,OAAO,QAAQ,EACpC,gBAAgB,EACd,QAAQP"}
1
+ {"version":3,"file":"store-CdST5wJZ.cjs","names":["state: ValueState<T> | ErrorState | PendingState","value","q: {\n action: Action<any>;\n resolve: (value: any) => void;\n reject: (error: unknown) => void;\n ref?: any;\n }[]","value: T | undefined","connection: { active: boolean; cancel?: Cancel } | undefined","value","cancel: Cancel | undefined","actions: AsyncConnectionActions<any>","_cancel: Cancel | undefined","deepEqual","get","run: (() => void) | undefined","timeout: ReturnType<typeof setTimeout> | undefined","timeoutStarted: number | undefined","debounce","arrayMethods: {\n [P in 'splice' | 'push' | 'pop' | 'shift' | 'unshift' | 'reverse' | 'sort']: <\n T extends Array<any>,\n >(\n this: Store<T>,\n ...args: T[P] extends Function_ ? Parameters<T[P]> : never\n ) => T[P] extends Function_ ? ReturnType<T[P]> : never;\n}","timeout: ReturnType<typeof setTimeout> | undefined","getter: T | Calculate<T>","options: StoreOptions<T>","derivedFrom?: {\n store: Store<any>;\n selectors: (Selector<any, any> | AnyPath)[];\n updater: (state: any) => void;\n }","path: any","update: Update<any>","get","set","deepEqual","previousValue: { value: T } | undefined","timer: ReturnType<typeof setTimeout> | undefined","updater: ((value: any) => Update<T>) | undefined","active","methods: StoreMethods | undefined","isObject","createStore: typeof create & { defaultOptions: StoreOptions<any> }"],"sources":["../src/lib/autobind.ts","../src/lib/calcDuration.ts","../src/lib/deferred.ts","../src/lib/isPromise.ts","../src/lib/promiseWithState.ts","../src/lib/queue.ts","../src/lib/calculatedValue.ts","../src/lib/makeSelector.ts","../src/lib/debounce.ts","../src/lib/disposable.ts","../src/lib/forwardError.ts","../src/lib/promiseWithCancel.ts","../src/lib/standardMethods.ts","../src/lib/throttle.ts","../src/core/store.ts"],"sourcesContent":["const marker = Symbol('autobind');\n\nexport const autobind = <\n TClass extends abstract new (...args: any) => any = abstract new (...args: any) => any,\n>(\n _class: TClass,\n): TClass => {\n for (const key of Reflect.ownKeys(_class.prototype)) {\n if (key === 'constructor') {\n continue;\n }\n\n const descriptor = Reflect.getOwnPropertyDescriptor(_class.prototype, key);\n let method = descriptor?.get?.() ?? descriptor?.value;\n let isBinding = false;\n\n if (typeof method !== 'function' || method[marker]) {\n continue;\n }\n\n Reflect.defineProperty(_class.prototype, key, {\n configurable: true,\n get() {\n if (\n isBinding ||\n this === _class.prototype ||\n Object.prototype.hasOwnProperty.call(this, key) ||\n typeof method !== 'function'\n ) {\n return method;\n }\n\n const boundMethod = (...args: any[]) => Reflect.apply(method, this, args);\n boundMethod[marker] = true;\n isBinding = true;\n\n Object.defineProperty(this, key, {\n configurable: true,\n get() {\n return boundMethod;\n },\n });\n\n isBinding = false;\n return boundMethod;\n },\n set(v) {\n method = v;\n },\n });\n }\n\n return _class;\n};\n","import type { Duration } from '../core/commonTypes';\n\nexport function calcDuration(t: Duration): number {\n if (typeof t === 'number') return t;\n return (\n (t.milliseconds ?? 0) +\n (t.seconds ?? 0) * 1000 +\n (t.minutes ?? 0) * 60 * 1000 +\n (t.hours ?? 0) * 60 * 60 * 1000 +\n (t.days ?? 0) * 24 * 60 * 60 * 1000\n );\n}\n","export class Deferred<T = void> extends Promise<T> {\n resolve: (value: T | PromiseLike<T>) => void = () => undefined;\n reject: (reason?: any) => void = () => undefined;\n\n constructor() {\n Object.defineProperty(Deferred, Symbol.species, {\n value: Promise,\n });\n\n const that = {};\n\n super((resolve, reject) => {\n Object.assign(that, { resolve, reject });\n });\n\n Object.assign(this, that);\n }\n}\n","export default function isPromise(value: unknown): value is Promise<unknown> {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'then' in value &&\n typeof value.then === 'function'\n );\n}\n","import isPromise from '@lib/isPromise';\nimport { type ErrorState, type PendingState, type ValueState } from './cacheState';\nimport { type MaybePromise } from './maybePromise';\n\nexport class PromiseWithState<T> extends Promise<T> {\n static override resolve(): PromiseWithState<void>;\n\n static override resolve<T>(value: MaybePromise<T>): PromiseWithState<T>;\n\n static override resolve<T>(value?: MaybePromise<T>) {\n return new PromiseWithState<T>(value as MaybePromise<T>);\n }\n\n static override reject<T = never>(error: unknown): PromiseWithState<T> {\n return new PromiseWithState<T>(Promise.reject(error), { status: 'error', error });\n }\n\n constructor(\n value: MaybePromise<T>,\n public state: ValueState<T> | ErrorState | PendingState = { status: 'pending' },\n ) {\n super((resolve) => resolve(value));\n\n Object.defineProperty(PromiseWithState, Symbol.species, {\n value: Promise,\n });\n\n if (isPromise(value)) {\n value\n .then((value) => {\n this.state = { status: 'value', value: value };\n })\n .catch((error) => {\n this.state = { status: 'error', error };\n });\n } else {\n this.state = { status: 'value', value: value };\n }\n }\n}\n","import isPromise from '@lib/isPromise';\nimport type { MaybePromise } from './maybePromise';\nimport type { Listener } from '@core';\n\ntype Action<T> = () => MaybePromise<T>;\n\nexport interface Queue {\n <T>(action: Action<T>, ref?: any): Promise<T>;\n clear: () => void;\n whenDone: () => Promise<void>;\n size: number;\n getRefs: () => any[];\n}\n\nexport function queue(): Queue {\n const q: {\n action: Action<any>;\n resolve: (value: any) => void;\n reject: (error: unknown) => void;\n ref?: any;\n }[] = [];\n const completionListeners = new Set<Listener<void>>();\n let active = false;\n\n const notify = () => {\n for (const listener of completionListeners) {\n listener();\n }\n\n completionListeners.clear();\n };\n\n const run = async () => {\n if (!active) {\n active = true;\n\n let next;\n while ((next = q.shift())) {\n try {\n let result = next.action();\n if (isPromise(result)) {\n result = await result;\n }\n\n next.resolve(result);\n } catch (error) {\n next.reject(error);\n }\n }\n\n active = false;\n notify();\n }\n };\n\n return Object.assign(\n <T>(action: Action<T>, ref?: any) => {\n return new Promise<T>((resolve, reject) => {\n q.push({ action, resolve, reject, ref });\n run();\n });\n },\n {\n clear() {\n q.length = 0;\n },\n\n whenDone() {\n if (!active) {\n return Promise.resolve();\n }\n\n return new Promise<void>((resolve) => {\n completionListeners.add(resolve);\n });\n },\n\n get size() {\n return q.length;\n },\n\n getRefs() {\n return q.map((item) => item.ref).filter((x) => x !== undefined);\n },\n },\n );\n}\n","import type { Cache } from '@core';\nimport type { AsyncConnectionActions, Cancel, Connection, StoreLike } from '@core/commonTypes';\nimport type { Store } from '@core/store';\nimport { Deferred } from '@lib/deferred';\nimport isPromise from '@lib/isPromise';\nimport { PromiseWithState } from '@lib/promiseWithState';\nimport { queue } from '@lib/queue';\nimport { deepEqual } from './equals';\n\nexport interface CalculatedValue<T> {\n value: T;\n check: () => void;\n stop(): void;\n invalidateDependencies(recursive?: boolean): void;\n}\n\nexport function calculatedValue<T>(store: Store<T>, notify: () => void): CalculatedValue<T> {\n if (!(store.getter instanceof Function)) {\n return staticValue(store.getter);\n }\n\n let active = false;\n const deps = new Array<{ store: StoreLike<any>; value: any; on: () => void; off: () => void }>();\n let value: T | undefined;\n const whenConnected = new Deferred();\n const whenExecuted = new Deferred();\n const ac = new AbortController();\n let connection: { active: boolean; cancel?: Cancel } | undefined;\n const q = queue();\n q(() => whenExecuted);\n\n const cancelEffect = store.addEffect(() => {\n if (connection) {\n store.invalidate();\n return;\n }\n\n active = true;\n\n for (const dep of deps) {\n dep.on();\n }\n\n return () => {\n active = false;\n\n for (const dep of deps) {\n dep.off();\n }\n\n if (connection) {\n connection.active = false;\n connection.cancel?.();\n q.clear();\n\n if ('state' in store) {\n (store as unknown as Cache<any>).state.set((state) => ({\n ...state,\n isConnected: false,\n isStale: true,\n }));\n }\n }\n };\n });\n\n function use<S>(dep: StoreLike<S>) {\n const value = dep.get();\n let cancel: Cancel | undefined;\n\n const on = () => {\n cancel ||= dep.subscribe(() => store.invalidate(), { runNow: false });\n };\n\n const off = () => {\n cancel?.();\n cancel = undefined;\n };\n\n deps.push({ store: dep, value, on, off });\n\n if (active) {\n on();\n }\n\n return value;\n }\n\n async function connect(createConnection: Connection<T>) {\n if (!active) {\n connection = { active: false };\n return;\n }\n\n const actions: AsyncConnectionActions<any> = {\n set(_value) {\n q(() => {\n if (!connection?.active) {\n return;\n }\n\n value = _value;\n notify();\n });\n },\n updateValue(update) {\n q(async () => {\n if (!connection?.active) {\n return;\n }\n\n if (update instanceof Function) {\n const currentValue = await value;\n\n if (!connection?.active) {\n return;\n }\n\n try {\n update = update(currentValue);\n } catch (error) {\n value = PromiseWithState.reject(error) as T;\n notify();\n connection.active = false;\n connection.cancel?.();\n return;\n }\n }\n\n value = PromiseWithState.resolve(update) as T;\n notify();\n });\n },\n updateError(error) {\n q(() => {\n if (!connection?.active) {\n return;\n }\n\n connection.active = false;\n connection.cancel?.();\n\n if ('state' in store) {\n (store as unknown as Cache<any>).state.set({\n status: 'error',\n error,\n isConnected: false,\n isUpdating: false,\n isStale: false,\n });\n }\n\n value = PromiseWithState.reject(error) as T;\n notify();\n });\n },\n updateIsConnected(isConnected) {\n if (isConnected) {\n whenConnected.resolve();\n }\n\n q(() => {\n if (!connection?.active) {\n return;\n }\n\n if ('state' in store) {\n (store as unknown as Cache<any>).state.set('isConnected', isConnected);\n }\n });\n },\n close() {\n if (connection?.active) {\n store.invalidate();\n }\n },\n };\n\n connection = { active: true };\n let _cancel: Cancel | undefined = createConnection(actions as any);\n\n connection.cancel = () => {\n _cancel?.();\n _cancel = undefined;\n };\n\n if (!connection.active) {\n connection.cancel();\n }\n\n return whenConnected;\n }\n\n try {\n value = store.getter({ signal: ac.signal, use, connect });\n } catch (error) {\n value = PromiseWithState.reject(error) as T;\n\n if (connection) {\n connection.active = false;\n connection.cancel?.();\n q.clear();\n }\n }\n\n if (isPromise(value)) {\n value.finally(() => whenExecuted.resolve()).catch(() => undefined);\n } else {\n whenExecuted.resolve();\n }\n\n function check() {\n if (store.options.cacheValue === false) {\n return false;\n }\n\n for (const dep of deps) {\n if (!deepEqual(dep.store.get(), dep.value)) {\n return false;\n }\n }\n return true;\n }\n\n function stop() {\n cancelEffect();\n whenExecuted.resolve();\n whenConnected.resolve();\n ac.abort();\n\n if (connection) {\n connection.active = false;\n connection.cancel?.();\n q.clear();\n }\n }\n\n function invalidateDependencies(recursive?: boolean) {\n for (const dep of deps) {\n dep.store.invalidate(recursive);\n }\n }\n\n return {\n get value() {\n return value!;\n },\n check,\n stop,\n invalidateDependencies,\n };\n}\n\nexport function staticValue<T>(value: T): CalculatedValue<T> {\n return {\n value,\n check: () => true,\n stop: () => undefined,\n invalidateDependencies: () => undefined,\n };\n}\n\nexport function staleValue<T>(value: T): CalculatedValue<T> {\n return {\n value,\n check: () => false,\n stop: () => undefined,\n invalidateDependencies: () => undefined,\n };\n}\n","import type { AnyPath } from './path';\nimport { get } from './propAccess';\n\nexport function makeSelector<T, S>(selector?: ((value: T) => S) | AnyPath): (value: T) => S {\n if (!selector) {\n return (x) => x as any;\n }\n\n if (selector instanceof Function) {\n return selector;\n }\n\n return (x) => get(x, selector as any) as any;\n}\n","import { calcDuration } from './calcDuration';\nimport type { Duration } from '@core';\n\nexport type DebounceOptions =\n | Duration\n | {\n wait: Duration;\n maxWait?: Duration;\n waitOnRunNow?: boolean;\n };\n\nexport function debounce<Args extends any[]>(\n action: (...args: Args) => void,\n options: Duration | DebounceOptions,\n): {\n (...args: Args): void;\n flush(): void;\n cancel(): void;\n isScheduled(): boolean;\n} {\n const wait =\n typeof options === 'object' && 'wait' in options\n ? calcDuration(options.wait)\n : calcDuration(options);\n\n const maxWait =\n typeof options === 'object' && 'maxWait' in options && options.maxWait !== undefined\n ? calcDuration(options.maxWait)\n : undefined;\n\n let run: (() => void) | undefined;\n let timeout: ReturnType<typeof setTimeout> | undefined;\n let timeoutStarted: number | undefined;\n\n function flush() {\n if (timeout !== undefined) {\n clearTimeout(timeout);\n }\n\n run?.();\n }\n\n function cancel() {\n if (timeout !== undefined) {\n clearTimeout(timeout);\n }\n\n run = undefined;\n timeout = undefined;\n timeoutStarted = undefined;\n }\n\n function isScheduled() {\n return timeout !== undefined;\n }\n\n function debounce(...args: Args) {\n const now = Date.now();\n timeoutStarted ??= now;\n\n const deadline = Math.min(\n //\n now + wait,\n timeoutStarted + (maxWait ?? Number.POSITIVE_INFINITY),\n );\n\n if (timeout !== undefined) {\n clearTimeout(timeout);\n }\n\n run = () => {\n run = undefined;\n timeout = undefined;\n timeoutStarted = undefined;\n\n action(...args);\n };\n\n timeout = setTimeout(run, deadline - now);\n }\n\n return Object.assign(debounce, { flush, cancel, isScheduled });\n}\n","import type { Cancel } from '@core';\nimport type { DisposableCancel } from '@core/commonTypes';\n\nexport default function disposable(dispose: Cancel): DisposableCancel {\n return Object.assign(\n dispose,\n Symbol.dispose ? { [Symbol.dispose]: dispose } : {},\n ) as DisposableCancel;\n}\n","export function forwardError(error: unknown): void {\n setTimeout(() => {\n throw error;\n });\n}\n","import { autobind } from '@lib/autobind';\n\nexport class PromiseCancelError extends Error {\n constructor() {\n super('cancelled');\n }\n}\n\nexport class PromiseWithCancel<T> extends Promise<T> {\n private abortController;\n\n constructor(\n executor: (\n resolve: (value: T) => void,\n reject: (error: unknown) => void,\n signal: AbortSignal,\n ) => void,\n ) {\n autobind(PromiseWithCancel);\n const abortController = new AbortController();\n\n super((resolve, reject) => {\n executor(resolve, reject, abortController.signal);\n\n abortController.signal.addEventListener('abort', () => {\n reject(abortController.signal.reason);\n });\n });\n\n this.abortController = abortController;\n }\n\n cancel(reason: any = new PromiseCancelError()): void {\n this.abortController.abort(reason);\n }\n}\n","import type { Store } from '../core/store';\nimport type { OptionalProperties, OptionalPropertyOf } from './typeHelpers';\n\ntype Function_ = (...args: any) => any;\n\nfunction createArrayAction<P extends keyof Array<any>>(prop: P) {\n return function arrayAction<T extends Array<any>>(\n this: Store<T>,\n ...args: T[P] extends Function_ ? Parameters<T[P]> : never\n ): T[P] extends Function_ ? ReturnType<T[P]> : never {\n const newArray = this.get().slice() as T;\n const result = (newArray[prop] as Function_)(...(args as any));\n this.set(newArray);\n return result;\n };\n}\nexport const arrayMethods: {\n [P in 'splice' | 'push' | 'pop' | 'shift' | 'unshift' | 'reverse' | 'sort']: <\n T extends Array<any>,\n >(\n this: Store<T>,\n ...args: T[P] extends Function_ ? Parameters<T[P]> : never\n ) => T[P] extends Function_ ? ReturnType<T[P]> : never;\n} = {\n splice: /* @__PURE__ */ createArrayAction('splice'),\n push: /* @__PURE__ */ createArrayAction('push'),\n pop: /* @__PURE__ */ createArrayAction('pop'),\n shift: /* @__PURE__ */ createArrayAction('shift'),\n unshift: /* @__PURE__ */ createArrayAction('unshift'),\n reverse: /* @__PURE__ */ createArrayAction('reverse'),\n sort: /* @__PURE__ */ createArrayAction('sort'),\n};\n\nexport const recordMethods = {\n delete<T extends Record<any, any>, K extends OptionalPropertyOf<T>>(\n this: Store<T>,\n key: K,\n ): void {\n const copy = { ...this.get() };\n delete copy[key];\n this.set(copy);\n },\n\n clear<T extends Record<any, any>>(\n this: OptionalProperties<T> extends T ? Store<T> : never,\n ): void {\n this.set({} as T);\n },\n};\n\nexport const mapMethods = {\n delete<K, V>(this: Store<Map<K, V>>, key: K): boolean {\n const newMap = new Map(this.get());\n const result = newMap.delete(key);\n this.set(newMap);\n return result;\n },\n\n clear<K, V>(this: Store<Map<K, V>>): void {\n this.set(new Map());\n },\n};\n\nexport const setMethods = {\n add<T>(this: Store<Set<T>>, value: T): void {\n const newSet = new Set(this.get());\n newSet.add(value);\n this.set(newSet);\n },\n\n delete<T>(this: Store<Set<T>>, value: T): void {\n const newSet = new Set(this.get());\n newSet.delete(value);\n this.set(newSet);\n },\n\n clear<T>(this: Store<Set<T>>): void {\n this.set(new Set());\n },\n};\n","import { calcDuration } from './calcDuration';\nimport type { Duration } from '@core';\n\nexport function throttle<Args extends any[]>(\n action: (...args: Args) => void,\n duration: Duration,\n): (...args: Args) => void {\n const ms = calcDuration(duration);\n\n let t = 0;\n let timeout: ReturnType<typeof setTimeout> | undefined;\n\n return (...args: Args) => {\n if (timeout !== undefined) {\n clearTimeout(timeout);\n }\n\n const dt = t + ms - Date.now();\n if (dt <= 0) {\n action(...args);\n t = Date.now();\n return;\n }\n\n timeout = setTimeout(() => {\n action(...args);\n t = Date.now();\n }, dt);\n };\n}\n","import { autobind } from '@lib/autobind';\nimport { calcDuration } from '@lib/calcDuration';\nimport { calculatedValue, staticValue, type CalculatedValue } from '@lib/calculatedValue';\nimport type { Constrain } from '@lib/constrain';\nimport { debounce } from '@lib/debounce';\nimport disposable from '@lib/disposable';\nimport { deepEqual } from '@lib/equals';\nimport { forwardError } from '@lib/forwardError';\nimport { isObject } from '@lib/helpers';\nimport { makeSelector } from '@lib/makeSelector';\nimport type { AnyPath, Path, SettablePath, Value } from '@lib/path';\nimport { PromiseWithCancel } from '@lib/promiseWithCancel';\nimport { get, set } from '@lib/propAccess';\nimport { arrayMethods, mapMethods, recordMethods, setMethods } from '@lib/standardMethods';\nimport { throttle } from '@lib/throttle';\nimport type {\n CalculationActions,\n Cancel,\n DisposableCancel,\n Duration,\n Effect,\n Listener,\n Selector,\n SubscribeOptions,\n Update,\n} from './commonTypes';\n\nexport type StoreMethods = Record<string, (...args: any[]) => any>;\n\nexport type BoundStoreMethods<T, Methods extends StoreMethods> = Methods &\n ThisType<Store<T> & Methods>;\n\nexport interface StoreOptions<T> {\n retain?: Duration;\n equals?: SubscribeOptions['equals'];\n effect?: Effect<Store<T>> | { effect: Effect<Store<T>>; retain?: Duration };\n cacheValue?: boolean;\n}\n\nexport interface StoreOptionsWithMethods<T, Methods extends StoreMethods> extends StoreOptions<T> {\n methods?: Methods & ThisType<Store<T> & Methods & StandardMethods<T>>;\n}\n\nexport type Calculate<T> = (helpers: CalculationActions<T>) => T;\n\ntype StandardMethods<T> =\n T extends Map<any, any>\n ? typeof mapMethods\n : T extends Set<any>\n ? typeof setMethods\n : T extends Array<any>\n ? typeof arrayMethods\n : T extends Record<any, any>\n ? typeof recordMethods\n : Record<string, never>;\n\ntype StoreWithMethods<T, Methods extends StoreMethods> = Store<T> &\n Omit<BoundStoreMethods<T, Methods>, keyof Store<T>> &\n StandardMethods<T>;\n\nexport interface OnceOptions {\n signal?: AbortSignal;\n timeout?: Duration;\n}\n\nfunction noop() {\n return undefined;\n}\n\nexport class Store<T> {\n private static hooks?: Set<(this: Store<any>, store: Store<any>) => void>;\n\n static addHook(hook: (store: Store<any>) => void): DisposableCancel {\n this.hooks ??= new Set();\n this.hooks.add(hook);\n return disposable(() => this.hooks?.delete(hook));\n }\n\n version?: string;\n\n protected calculatedValue?: CalculatedValue<T>;\n protected defaultValue?: CalculatedValue<T>;\n\n protected listeners: Map<Listener, boolean> = new Map();\n\n protected effects: Map<\n Effect<Store<T>>,\n { handle?: Cancel; retain?: number; timeout?: ReturnType<typeof setTimeout> }\n > = new Map();\n\n protected notifyId = {};\n\n constructor(\n public readonly getter: T | Calculate<T>,\n public readonly options: StoreOptions<T> = {},\n public readonly derivedFrom?: {\n store: Store<any>;\n selectors: (Selector<any, any> | AnyPath)[];\n updater: (state: any) => void;\n },\n ) {\n autobind(Store);\n\n if (typeof getter !== 'function') {\n this.calculatedValue = this.defaultValue = staticValue(getter);\n }\n\n for (const hook of Store.hooks ?? []) {\n hook.apply(this, [this]);\n }\n\n if (options.effect instanceof Function) {\n this.addEffect(options.effect);\n } else if (options.effect) {\n this.addEffect(options.effect.effect, options.effect.retain);\n }\n }\n\n get(): T {\n if (!this.calculatedValue?.check()) {\n this.calculatedValue?.stop();\n this.calculatedValue = undefined;\n }\n\n if (!this.calculatedValue) {\n this.calculatedValue = calculatedValue(this, this.notify);\n }\n\n return this.calculatedValue.value;\n }\n\n set(update: Update<T>): void;\n\n set<const P>(path: Constrain<P, Path<T>>, update: Update<Value<T, P>>): void;\n\n set(...args: any[]): void {\n const path: any = args.length > 1 ? args[0] : [];\n let update: Update<any> = args.length > 1 ? args[1] : args[0];\n\n if (update instanceof Function) {\n const before = this.get();\n const valueBefore = get(before, path);\n const valueAfter = update(valueBefore);\n update = set(before, path, valueAfter);\n } else if (path.length > 0) {\n update = set(this.get(), path, update);\n }\n\n if (this.derivedFrom) {\n this.derivedFrom.updater(update);\n return;\n }\n\n this.calculatedValue?.stop();\n this.calculatedValue = staticValue(update);\n this.notify();\n }\n\n invalidate(recursive?: boolean): void {\n if (recursive) {\n this.calculatedValue?.invalidateDependencies(recursive);\n }\n\n this.calculatedValue?.stop();\n this.calculatedValue = this.defaultValue;\n this.notify();\n }\n\n subscribe(\n listener: Listener<T, { cancel: Cancel }>,\n options?: SubscribeOptions,\n ): DisposableCancel {\n const {\n passive,\n runNow = true,\n throttle: throttleOption,\n debounce: debounceOption,\n equals = this.options.equals ?? deepEqual,\n } = options ?? {};\n\n let isSetup = false;\n let previousValue: { value: T } | undefined;\n\n let innerListener = () => {\n if (!isSetup) {\n return;\n }\n\n const value = passive ? this.calculatedValue : { value: this.get() };\n\n if (!value) {\n return;\n }\n\n if (previousValue && equals(value.value, previousValue.value)) {\n return;\n }\n\n const _previousValue = previousValue?.value;\n previousValue = this.calculatedValue && { value: this.calculatedValue?.value };\n\n try {\n listener.apply({ cancel }, [value.value, _previousValue]);\n } catch (error) {\n forwardError(error);\n }\n };\n\n if (throttleOption) {\n innerListener = throttle(innerListener, throttleOption);\n } else if (debounceOption) {\n innerListener = debounce(innerListener, debounceOption);\n }\n\n this.listeners.set(innerListener, !passive);\n const cancel = () => {\n if (this.listeners.delete(innerListener) && !passive) {\n this.onUnsubscribe();\n }\n };\n\n if (!passive) {\n this.onSubscribe();\n }\n\n isSetup = true;\n\n if (runNow) {\n innerListener();\n\n if (\n !throttleOption &&\n typeof debounceOption === 'object' &&\n 'waitOnRunNow' in debounceOption &&\n debounceOption.waitOnRunNow === false &&\n 'flush' in innerListener\n ) {\n (innerListener as { flush: () => void }).flush();\n }\n } else {\n previousValue = passive\n ? this.calculatedValue && { value: this.calculatedValue.value }\n : { value: this.get() };\n }\n\n return disposable(cancel);\n }\n\n once<S extends T>(\n condition: (value: T) => value is S,\n options?: OnceOptions,\n ): PromiseWithCancel<S>;\n\n once(condition: (value: T) => boolean, options?: OnceOptions): PromiseWithCancel<T>;\n\n once(options?: OnceOptions): PromiseWithCancel<Exclude<T, undefined>>;\n\n once(\n ...args: [condition: (value: any) => boolean, options?: OnceOptions] | [options?: OnceOptions]\n ): PromiseWithCancel<any> {\n const condition = args[0] instanceof Function ? args[0] : (x: T) => x !== undefined;\n const options = args[0] instanceof Function ? args[1] : args[0];\n\n return new PromiseWithCancel<T>((resolve, reject, signal) => {\n let stopped = false;\n let timer: ReturnType<typeof setTimeout> | undefined;\n\n const cancel = this.subscribe(\n (value) => {\n if (stopped || !condition(value)) {\n return;\n }\n\n resolve(value);\n stopped = true;\n if (timer) {\n clearTimeout(timer);\n }\n setTimeout(() => cancel());\n },\n {\n runNow: !!condition,\n },\n );\n\n if (stopped) {\n return;\n }\n\n signal.addEventListener('abort', cancel);\n\n options?.signal?.addEventListener('abort', () => {\n cancel();\n reject(options.signal?.reason ?? new Error('cancelled'));\n });\n\n if (options?.timeout !== undefined) {\n timer = setTimeout(() => {\n cancel();\n reject(new Error('timeout'));\n }, calcDuration(options.timeout));\n }\n });\n }\n\n map<S>(selector: Selector<T, S>, updater?: (value: S) => Update<T>): Store<S>;\n\n map<const P>(selector: Constrain<P, SettablePath<T>>): Store<Value<T, P>>;\n\n map(_selector: Selector<T, any> | SettablePath<any>, ...args: any[]): Store<any> {\n const updater: ((value: any) => Update<T>) | undefined =\n _selector instanceof Function\n ? args[0]\n : (value) => (state) => set(state, _selector as any, value);\n\n const selector = makeSelector(_selector);\n\n const derivedFrom = {\n store: this.derivedFrom ? this.derivedFrom.store : this,\n selectors: this.derivedFrom ? [...this.derivedFrom.selectors, _selector] : [_selector],\n\n updater: (value: any) => {\n if (!updater) {\n throw new TypeError(\n 'Can only update computed stores that either are derived from other stores using string selectors or have an updater function.',\n );\n }\n\n let update = updater(value);\n\n if (update instanceof Function) {\n update = update(this.get());\n }\n\n if (this.derivedFrom) {\n this.derivedFrom.updater(update);\n } else {\n this.set(update);\n }\n },\n };\n\n return new Store(\n ({ use }) => {\n return selector(use(this));\n },\n undefined,\n derivedFrom,\n );\n }\n\n /** Add an effect that will be executed when the store becomes active, which means when it has at least one subscriber.\n * @param effect\n * If there is already a subscriber, the effect will be executed immediately.\n * Otherweise it will be executed as soon as the first subscription is created.\n * Every time all subscriptions are removed and the first is created again, the effect will be executed again.\n * @param retain\n * If provided, delay tearing down effects when the last subscriber is removed. This is useful if a short gap in subscriber coverage is supposed to be ignored. E.g. when switching pages, the old page might unsubscribe, while the new page subscribes immediately after.\n * @returns\n * The effect can return a teardown callback, which will be executed when the last subscription is removed and potentially the ratain time has passed.\n */\n addEffect(\n effect: Effect<Store<T>>,\n retain: Duration | undefined = this.options.retain,\n ): DisposableCancel {\n this.effects.set(effect, {\n handle: this.isActive() ? (effect.apply(this, [this]) ?? noop) : undefined,\n retain: retain !== undefined ? calcDuration(retain) : undefined,\n });\n\n return disposable(() => {\n const { handle, timeout } = this.effects.get(effect) ?? {};\n handle?.();\n\n if (timeout !== undefined) {\n clearTimeout(timeout);\n }\n\n this.effects.delete(effect);\n });\n }\n\n /** Return whether the store is currently active, which means whether it has at least one subscriber. */\n isActive(): boolean {\n return [...this.listeners.values()].some(Boolean);\n }\n\n protected onSubscribe(): void {\n if ([...this.listeners.values()].filter(Boolean).length > 1) return;\n\n for (const [effect, { handle, retain, timeout }] of this.effects.entries()) {\n if (timeout !== undefined) {\n clearTimeout(timeout);\n }\n\n this.effects.set(effect, {\n handle: handle ?? effect.apply(this, [this]) ?? noop,\n retain,\n timeout: undefined,\n });\n }\n }\n\n protected onUnsubscribe(): void {\n if ([...this.listeners.values()].some(Boolean)) return;\n\n for (const [effect, { handle, retain, timeout }] of this.effects.entries()) {\n if (!retain) {\n handle?.();\n\n if (timeout !== undefined) {\n clearTimeout(timeout);\n }\n\n this.effects.set(effect, {\n handle: undefined,\n retain,\n timeout: undefined,\n });\n\n continue;\n }\n\n const newTimeout =\n timeout ??\n (handle\n ? setTimeout(() => {\n handle();\n this.effects.set(effect, {\n handle: undefined,\n retain,\n timeout: undefined,\n });\n }, retain)\n : undefined);\n\n this.effects.set(effect, {\n handle,\n retain,\n timeout: newTimeout,\n });\n }\n }\n\n protected notify(): void {\n const n = {};\n this.notifyId = n;\n\n const snapshot = [...this.listeners.entries()];\n const active = snapshot.filter(([, active]) => active);\n const passive = snapshot.filter(([, active]) => !active);\n for (const [listener] of [...active, ...passive]) {\n listener();\n if (n !== this.notifyId) break;\n }\n }\n}\n\nfunction create<T>(calculate: Calculate<T>, options?: StoreOptions<T>): Store<T>;\nfunction create<T, Methods extends StoreMethods = {}>(\n initialState: T,\n options?: StoreOptionsWithMethods<T, Methods>,\n): StoreWithMethods<T, Methods>;\nfunction create<T, Methods extends StoreMethods>(\n initialState: T | Calculate<T>,\n options?: StoreOptionsWithMethods<T, Methods>,\n): StoreWithMethods<T, Methods> | Store<T> {\n options = { ...createStore.defaultOptions, ...options };\n\n const store = new Store(initialState, options);\n\n if (initialState instanceof Function) {\n return store;\n }\n\n let methods: StoreMethods | undefined = options?.methods;\n\n if (initialState instanceof Map) {\n methods = { ...mapMethods, ...methods };\n } else if (initialState instanceof Set) {\n methods = { ...setMethods, ...methods };\n } else if (Array.isArray(initialState)) {\n methods = { ...arrayMethods, ...methods };\n } else if (isObject(initialState)) {\n methods = { ...recordMethods, ...methods };\n }\n\n const boundMethods = Object.fromEntries(\n Object.entries(methods ?? ({} as BoundStoreMethods<T, any>))\n .filter(([name]) => !(name in store))\n .map(([name, action]) => [name, (action as any).bind(store)]),\n ) as BoundStoreMethods<T, any>;\n\n return Object.assign(store, boundMethods);\n}\n\nexport const createStore: typeof create & { defaultOptions: StoreOptions<any> } =\n /* @__PURE__ */ Object.assign(create, {\n defaultOptions: {\n equals: deepEqual,\n } as StoreOptions<any>,\n });\n"],"mappings":";;;AAAA,MAAM,SAAS,OAAO;AAEtB,MAAa,YAGX,WACW;AACX,MAAK,MAAM,OAAO,QAAQ,QAAQ,OAAO,YAAY;AACnD,MAAI,QAAQ,cACV;EAGF,MAAM,aAAa,QAAQ,yBAAyB,OAAO,WAAW;EACtE,IAAI,SAAS,YAAY,WAAW,YAAY;EAChD,IAAI,YAAY;AAEhB,MAAI,OAAO,WAAW,cAAc,OAAO,QACzC;AAGF,UAAQ,eAAe,OAAO,WAAW,KAAK;GAC5C,cAAc;GACd,MAAM;AACJ,QACE,aACA,SAAS,OAAO,aAChB,OAAO,UAAU,eAAe,KAAK,MAAM,QAC3C,OAAO,WAAW,WAElB,QAAO;IAGT,MAAM,eAAe,GAAG,SAAgB,QAAQ,MAAM,QAAQ,MAAM;AACpE,gBAAY,UAAU;AACtB,gBAAY;AAEZ,WAAO,eAAe,MAAM,KAAK;KAC/B,cAAc;KACd,MAAM;AACJ,aAAO;;;AAIX,gBAAY;AACZ,WAAO;;GAET,IAAI,GAAG;AACL,aAAS;;;;AAKf,QAAO;;;;;AClDT,SAAgB,aAAa,GAAqB;AAChD,KAAI,OAAO,MAAM,SAAU,QAAO;AAClC,SACG,EAAE,gBAAgB,MAClB,EAAE,WAAW,KAAK,OAClB,EAAE,WAAW,KAAK,KAAK,OACvB,EAAE,SAAS,KAAK,KAAK,KAAK,OAC1B,EAAE,QAAQ,KAAK,KAAK,KAAK,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G9B,MAAaC,cACK,uBAAO,OAAO,QAAQ,EACpC,gBAAgB,EACd,QAAQP"}
@@ -213,7 +213,7 @@ declare class Store<T> {
213
213
  }>, options?: SubscribeOptions): DisposableCancel;
214
214
  once<S extends T>(condition: (value: T) => value is S, options?: OnceOptions): PromiseWithCancel<S>;
215
215
  once(condition: (value: T) => boolean, options?: OnceOptions): PromiseWithCancel<T>;
216
- once(options?: OnceOptions): PromiseWithCancel<T>;
216
+ once(options?: OnceOptions): PromiseWithCancel<Exclude<T, undefined>>;
217
217
  map<S>(selector: Selector<T, S>, updater?: (value: S) => Update<T>): Store<S>;
218
218
  map<const P>(selector: Constrain<P, SettablePath<T>>): Store<Value$1<T, P>>;
219
219
  /** Add an effect that will be executed when the store becomes active, which means when it has at least one subscriber.
@@ -240,4 +240,4 @@ declare const createStore: typeof create & {
240
240
  };
241
241
  //#endregion
242
242
  export { AnyPath, AsyncConnectionActions, AsyncUpdateFunction, BaseConnectionActions, BoundStoreMethods, Calculate, CalculationActions, Cancel, Connection, ConnectionActions, Constrain, DisposableCancel, Duration, Effect, GetKeys, Join, KeyType, Listener, MaybePromise, Object_, Path, PathAsArray, PathAsString, Selector, SettablePath, SettablePathAsArray, SettablePathAsString, SettableValue, Store, StoreMethods, StoreOptions, StoreOptionsWithMethods, SubscribeOptions, Update, UpdateFrom, UpdateFunction, Use, Value$1 as Value, WildcardPath, WildcardPathAsString, WildcardValue, arrayMethods, createStore, mapMethods, recordMethods, setMethods };
243
- //# sourceMappingURL=store-B3PWCx63.d.cts.map
243
+ //# sourceMappingURL=store-DnZ6fsiJ.d.ts.map
@@ -579,7 +579,7 @@ var Store = class Store {
579
579
  return disposable(cancel);
580
580
  }
581
581
  once(...args) {
582
- const condition = args[0] instanceof Function ? args[0] : Boolean;
582
+ const condition = args[0] instanceof Function ? args[0] : (x) => x !== void 0;
583
583
  const options = args[0] instanceof Function ? args[1] : args[0];
584
584
  return new PromiseWithCancel((resolve, reject, signal) => {
585
585
  let stopped = false;
@@ -729,4 +729,4 @@ const createStore = /* @__PURE__ */ Object.assign(create, { defaultOptions: { eq
729
729
 
730
730
  //#endregion
731
731
  export { PromiseWithState, Store, arrayMethods, autobind, calcDuration, calculatedValue, createStore, debounce, isPromise, makeSelector, mapMethods, queue, recordMethods, setMethods, throttle };
732
- //# sourceMappingURL=store-DOEc60aP.js.map
732
+ //# sourceMappingURL=store-Dx8w7yT-.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"store-DOEc60aP.js","names":["state: ValueState<T> | ErrorState | PendingState","value","q: {\n action: Action<any>;\n resolve: (value: any) => void;\n reject: (error: unknown) => void;\n ref?: any;\n }[]","value: T | undefined","connection: { active: boolean; cancel?: Cancel } | undefined","value","cancel: Cancel | undefined","actions: AsyncConnectionActions<any>","_cancel: Cancel | undefined","run: (() => void) | undefined","timeout: ReturnType<typeof setTimeout> | undefined","timeoutStarted: number | undefined","debounce","arrayMethods: {\n [P in 'splice' | 'push' | 'pop' | 'shift' | 'unshift' | 'reverse' | 'sort']: <\n T extends Array<any>,\n >(\n this: Store<T>,\n ...args: T[P] extends Function_ ? Parameters<T[P]> : never\n ) => T[P] extends Function_ ? ReturnType<T[P]> : never;\n}","timeout: ReturnType<typeof setTimeout> | undefined","getter: T | Calculate<T>","options: StoreOptions<T>","derivedFrom?: {\n store: Store<any>;\n selectors: (Selector<any, any> | AnyPath)[];\n updater: (state: any) => void;\n }","path: any","update: Update<any>","previousValue: { value: T } | undefined","timer: ReturnType<typeof setTimeout> | undefined","updater: ((value: any) => Update<T>) | undefined","active","methods: StoreMethods | undefined","createStore: typeof create & { defaultOptions: StoreOptions<any> }"],"sources":["../src/lib/autobind.ts","../src/lib/calcDuration.ts","../src/lib/deferred.ts","../src/lib/isPromise.ts","../src/lib/promiseWithState.ts","../src/lib/queue.ts","../src/lib/calculatedValue.ts","../src/lib/makeSelector.ts","../src/lib/debounce.ts","../src/lib/disposable.ts","../src/lib/forwardError.ts","../src/lib/promiseWithCancel.ts","../src/lib/standardMethods.ts","../src/lib/throttle.ts","../src/core/store.ts"],"sourcesContent":["const marker = Symbol('autobind');\n\nexport const autobind = <\n TClass extends abstract new (...args: any) => any = abstract new (...args: any) => any,\n>(\n _class: TClass,\n): TClass => {\n for (const key of Reflect.ownKeys(_class.prototype)) {\n if (key === 'constructor') {\n continue;\n }\n\n const descriptor = Reflect.getOwnPropertyDescriptor(_class.prototype, key);\n let method = descriptor?.get?.() ?? descriptor?.value;\n let isBinding = false;\n\n if (typeof method !== 'function' || method[marker]) {\n continue;\n }\n\n Reflect.defineProperty(_class.prototype, key, {\n configurable: true,\n get() {\n if (\n isBinding ||\n this === _class.prototype ||\n Object.prototype.hasOwnProperty.call(this, key) ||\n typeof method !== 'function'\n ) {\n return method;\n }\n\n const boundMethod = (...args: any[]) => Reflect.apply(method, this, args);\n boundMethod[marker] = true;\n isBinding = true;\n\n Object.defineProperty(this, key, {\n configurable: true,\n get() {\n return boundMethod;\n },\n });\n\n isBinding = false;\n return boundMethod;\n },\n set(v) {\n method = v;\n },\n });\n }\n\n return _class;\n};\n","import type { Duration } from '../core/commonTypes';\n\nexport function calcDuration(t: Duration): number {\n if (typeof t === 'number') return t;\n return (\n (t.milliseconds ?? 0) +\n (t.seconds ?? 0) * 1000 +\n (t.minutes ?? 0) * 60 * 1000 +\n (t.hours ?? 0) * 60 * 60 * 1000 +\n (t.days ?? 0) * 24 * 60 * 60 * 1000\n );\n}\n","export class Deferred<T = void> extends Promise<T> {\n resolve: (value: T | PromiseLike<T>) => void = () => undefined;\n reject: (reason?: any) => void = () => undefined;\n\n constructor() {\n Object.defineProperty(Deferred, Symbol.species, {\n value: Promise,\n });\n\n const that = {};\n\n super((resolve, reject) => {\n Object.assign(that, { resolve, reject });\n });\n\n Object.assign(this, that);\n }\n}\n","export default function isPromise(value: unknown): value is Promise<unknown> {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'then' in value &&\n typeof value.then === 'function'\n );\n}\n","import isPromise from '@lib/isPromise';\nimport { type ErrorState, type PendingState, type ValueState } from './cacheState';\nimport { type MaybePromise } from './maybePromise';\n\nexport class PromiseWithState<T> extends Promise<T> {\n static override resolve(): PromiseWithState<void>;\n\n static override resolve<T>(value: MaybePromise<T>): PromiseWithState<T>;\n\n static override resolve<T>(value?: MaybePromise<T>) {\n return new PromiseWithState<T>(value as MaybePromise<T>);\n }\n\n static override reject<T = never>(error: unknown): PromiseWithState<T> {\n return new PromiseWithState<T>(Promise.reject(error), { status: 'error', error });\n }\n\n constructor(\n value: MaybePromise<T>,\n public state: ValueState<T> | ErrorState | PendingState = { status: 'pending' },\n ) {\n super((resolve) => resolve(value));\n\n Object.defineProperty(PromiseWithState, Symbol.species, {\n value: Promise,\n });\n\n if (isPromise(value)) {\n value\n .then((value) => {\n this.state = { status: 'value', value: value };\n })\n .catch((error) => {\n this.state = { status: 'error', error };\n });\n } else {\n this.state = { status: 'value', value: value };\n }\n }\n}\n","import isPromise from '@lib/isPromise';\nimport type { MaybePromise } from './maybePromise';\nimport type { Listener } from '@core';\n\ntype Action<T> = () => MaybePromise<T>;\n\nexport interface Queue {\n <T>(action: Action<T>, ref?: any): Promise<T>;\n clear: () => void;\n whenDone: () => Promise<void>;\n size: number;\n getRefs: () => any[];\n}\n\nexport function queue(): Queue {\n const q: {\n action: Action<any>;\n resolve: (value: any) => void;\n reject: (error: unknown) => void;\n ref?: any;\n }[] = [];\n const completionListeners = new Set<Listener<void>>();\n let active = false;\n\n const notify = () => {\n for (const listener of completionListeners) {\n listener();\n }\n\n completionListeners.clear();\n };\n\n const run = async () => {\n if (!active) {\n active = true;\n\n let next;\n while ((next = q.shift())) {\n try {\n let result = next.action();\n if (isPromise(result)) {\n result = await result;\n }\n\n next.resolve(result);\n } catch (error) {\n next.reject(error);\n }\n }\n\n active = false;\n notify();\n }\n };\n\n return Object.assign(\n <T>(action: Action<T>, ref?: any) => {\n return new Promise<T>((resolve, reject) => {\n q.push({ action, resolve, reject, ref });\n run();\n });\n },\n {\n clear() {\n q.length = 0;\n },\n\n whenDone() {\n if (!active) {\n return Promise.resolve();\n }\n\n return new Promise<void>((resolve) => {\n completionListeners.add(resolve);\n });\n },\n\n get size() {\n return q.length;\n },\n\n getRefs() {\n return q.map((item) => item.ref).filter((x) => x !== undefined);\n },\n },\n );\n}\n","import type { Cache } from '@core';\nimport type { AsyncConnectionActions, Cancel, Connection, StoreLike } from '@core/commonTypes';\nimport type { Store } from '@core/store';\nimport { Deferred } from '@lib/deferred';\nimport isPromise from '@lib/isPromise';\nimport { PromiseWithState } from '@lib/promiseWithState';\nimport { queue } from '@lib/queue';\nimport { deepEqual } from './equals';\n\nexport interface CalculatedValue<T> {\n value: T;\n check: () => void;\n stop(): void;\n invalidateDependencies(recursive?: boolean): void;\n}\n\nexport function calculatedValue<T>(store: Store<T>, notify: () => void): CalculatedValue<T> {\n if (!(store.getter instanceof Function)) {\n return staticValue(store.getter);\n }\n\n let active = false;\n const deps = new Array<{ store: StoreLike<any>; value: any; on: () => void; off: () => void }>();\n let value: T | undefined;\n const whenConnected = new Deferred();\n const whenExecuted = new Deferred();\n const ac = new AbortController();\n let connection: { active: boolean; cancel?: Cancel } | undefined;\n const q = queue();\n q(() => whenExecuted);\n\n const cancelEffect = store.addEffect(() => {\n if (connection) {\n store.invalidate();\n return;\n }\n\n active = true;\n\n for (const dep of deps) {\n dep.on();\n }\n\n return () => {\n active = false;\n\n for (const dep of deps) {\n dep.off();\n }\n\n if (connection) {\n connection.active = false;\n connection.cancel?.();\n q.clear();\n\n if ('state' in store) {\n (store as unknown as Cache<any>).state.set((state) => ({\n ...state,\n isConnected: false,\n isStale: true,\n }));\n }\n }\n };\n });\n\n function use<S>(dep: StoreLike<S>) {\n const value = dep.get();\n let cancel: Cancel | undefined;\n\n const on = () => {\n cancel ||= dep.subscribe(() => store.invalidate(), { runNow: false });\n };\n\n const off = () => {\n cancel?.();\n cancel = undefined;\n };\n\n deps.push({ store: dep, value, on, off });\n\n if (active) {\n on();\n }\n\n return value;\n }\n\n async function connect(createConnection: Connection<T>) {\n if (!active) {\n connection = { active: false };\n return;\n }\n\n const actions: AsyncConnectionActions<any> = {\n set(_value) {\n q(() => {\n if (!connection?.active) {\n return;\n }\n\n value = _value;\n notify();\n });\n },\n updateValue(update) {\n q(async () => {\n if (!connection?.active) {\n return;\n }\n\n if (update instanceof Function) {\n const currentValue = await value;\n\n if (!connection?.active) {\n return;\n }\n\n try {\n update = update(currentValue);\n } catch (error) {\n value = PromiseWithState.reject(error) as T;\n notify();\n connection.active = false;\n connection.cancel?.();\n return;\n }\n }\n\n value = PromiseWithState.resolve(update) as T;\n notify();\n });\n },\n updateError(error) {\n q(() => {\n if (!connection?.active) {\n return;\n }\n\n connection.active = false;\n connection.cancel?.();\n\n if ('state' in store) {\n (store as unknown as Cache<any>).state.set({\n status: 'error',\n error,\n isConnected: false,\n isUpdating: false,\n isStale: false,\n });\n }\n\n value = PromiseWithState.reject(error) as T;\n notify();\n });\n },\n updateIsConnected(isConnected) {\n if (isConnected) {\n whenConnected.resolve();\n }\n\n q(() => {\n if (!connection?.active) {\n return;\n }\n\n if ('state' in store) {\n (store as unknown as Cache<any>).state.set('isConnected', isConnected);\n }\n });\n },\n close() {\n if (connection?.active) {\n store.invalidate();\n }\n },\n };\n\n connection = { active: true };\n let _cancel: Cancel | undefined = createConnection(actions as any);\n\n connection.cancel = () => {\n _cancel?.();\n _cancel = undefined;\n };\n\n if (!connection.active) {\n connection.cancel();\n }\n\n return whenConnected;\n }\n\n try {\n value = store.getter({ signal: ac.signal, use, connect });\n } catch (error) {\n value = PromiseWithState.reject(error) as T;\n\n if (connection) {\n connection.active = false;\n connection.cancel?.();\n q.clear();\n }\n }\n\n if (isPromise(value)) {\n value.finally(() => whenExecuted.resolve()).catch(() => undefined);\n } else {\n whenExecuted.resolve();\n }\n\n function check() {\n if (store.options.cacheValue === false) {\n return false;\n }\n\n for (const dep of deps) {\n if (!deepEqual(dep.store.get(), dep.value)) {\n return false;\n }\n }\n return true;\n }\n\n function stop() {\n cancelEffect();\n whenExecuted.resolve();\n whenConnected.resolve();\n ac.abort();\n\n if (connection) {\n connection.active = false;\n connection.cancel?.();\n q.clear();\n }\n }\n\n function invalidateDependencies(recursive?: boolean) {\n for (const dep of deps) {\n dep.store.invalidate(recursive);\n }\n }\n\n return {\n get value() {\n return value!;\n },\n check,\n stop,\n invalidateDependencies,\n };\n}\n\nexport function staticValue<T>(value: T): CalculatedValue<T> {\n return {\n value,\n check: () => true,\n stop: () => undefined,\n invalidateDependencies: () => undefined,\n };\n}\n\nexport function staleValue<T>(value: T): CalculatedValue<T> {\n return {\n value,\n check: () => false,\n stop: () => undefined,\n invalidateDependencies: () => undefined,\n };\n}\n","import type { AnyPath } from './path';\nimport { get } from './propAccess';\n\nexport function makeSelector<T, S>(selector?: ((value: T) => S) | AnyPath): (value: T) => S {\n if (!selector) {\n return (x) => x as any;\n }\n\n if (selector instanceof Function) {\n return selector;\n }\n\n return (x) => get(x, selector as any) as any;\n}\n","import { calcDuration } from './calcDuration';\nimport type { Duration } from '@core';\n\nexport type DebounceOptions =\n | Duration\n | {\n wait: Duration;\n maxWait?: Duration;\n waitOnRunNow?: boolean;\n };\n\nexport function debounce<Args extends any[]>(\n action: (...args: Args) => void,\n options: Duration | DebounceOptions,\n): {\n (...args: Args): void;\n flush(): void;\n cancel(): void;\n isScheduled(): boolean;\n} {\n const wait =\n typeof options === 'object' && 'wait' in options\n ? calcDuration(options.wait)\n : calcDuration(options);\n\n const maxWait =\n typeof options === 'object' && 'maxWait' in options && options.maxWait !== undefined\n ? calcDuration(options.maxWait)\n : undefined;\n\n let run: (() => void) | undefined;\n let timeout: ReturnType<typeof setTimeout> | undefined;\n let timeoutStarted: number | undefined;\n\n function flush() {\n if (timeout !== undefined) {\n clearTimeout(timeout);\n }\n\n run?.();\n }\n\n function cancel() {\n if (timeout !== undefined) {\n clearTimeout(timeout);\n }\n\n run = undefined;\n timeout = undefined;\n timeoutStarted = undefined;\n }\n\n function isScheduled() {\n return timeout !== undefined;\n }\n\n function debounce(...args: Args) {\n const now = Date.now();\n timeoutStarted ??= now;\n\n const deadline = Math.min(\n //\n now + wait,\n timeoutStarted + (maxWait ?? Number.POSITIVE_INFINITY),\n );\n\n if (timeout !== undefined) {\n clearTimeout(timeout);\n }\n\n run = () => {\n run = undefined;\n timeout = undefined;\n timeoutStarted = undefined;\n\n action(...args);\n };\n\n timeout = setTimeout(run, deadline - now);\n }\n\n return Object.assign(debounce, { flush, cancel, isScheduled });\n}\n","import type { Cancel } from '@core';\nimport type { DisposableCancel } from '@core/commonTypes';\n\nexport default function disposable(dispose: Cancel): DisposableCancel {\n return Object.assign(\n dispose,\n Symbol.dispose ? { [Symbol.dispose]: dispose } : {},\n ) as DisposableCancel;\n}\n","export function forwardError(error: unknown): void {\n setTimeout(() => {\n throw error;\n });\n}\n","import { autobind } from '@lib/autobind';\n\nexport class PromiseCancelError extends Error {\n constructor() {\n super('cancelled');\n }\n}\n\nexport class PromiseWithCancel<T> extends Promise<T> {\n private abortController;\n\n constructor(\n executor: (\n resolve: (value: T) => void,\n reject: (error: unknown) => void,\n signal: AbortSignal,\n ) => void,\n ) {\n autobind(PromiseWithCancel);\n const abortController = new AbortController();\n\n super((resolve, reject) => {\n executor(resolve, reject, abortController.signal);\n\n abortController.signal.addEventListener('abort', () => {\n reject(abortController.signal.reason);\n });\n });\n\n this.abortController = abortController;\n }\n\n cancel(reason: any = new PromiseCancelError()): void {\n this.abortController.abort(reason);\n }\n}\n","import type { Store } from '../core/store';\nimport type { OptionalProperties, OptionalPropertyOf } from './typeHelpers';\n\ntype Function_ = (...args: any) => any;\n\nfunction createArrayAction<P extends keyof Array<any>>(prop: P) {\n return function arrayAction<T extends Array<any>>(\n this: Store<T>,\n ...args: T[P] extends Function_ ? Parameters<T[P]> : never\n ): T[P] extends Function_ ? ReturnType<T[P]> : never {\n const newArray = this.get().slice() as T;\n const result = (newArray[prop] as Function_)(...(args as any));\n this.set(newArray);\n return result;\n };\n}\nexport const arrayMethods: {\n [P in 'splice' | 'push' | 'pop' | 'shift' | 'unshift' | 'reverse' | 'sort']: <\n T extends Array<any>,\n >(\n this: Store<T>,\n ...args: T[P] extends Function_ ? Parameters<T[P]> : never\n ) => T[P] extends Function_ ? ReturnType<T[P]> : never;\n} = {\n splice: /* @__PURE__ */ createArrayAction('splice'),\n push: /* @__PURE__ */ createArrayAction('push'),\n pop: /* @__PURE__ */ createArrayAction('pop'),\n shift: /* @__PURE__ */ createArrayAction('shift'),\n unshift: /* @__PURE__ */ createArrayAction('unshift'),\n reverse: /* @__PURE__ */ createArrayAction('reverse'),\n sort: /* @__PURE__ */ createArrayAction('sort'),\n};\n\nexport const recordMethods = {\n delete<T extends Record<any, any>, K extends OptionalPropertyOf<T>>(\n this: Store<T>,\n key: K,\n ): void {\n const copy = { ...this.get() };\n delete copy[key];\n this.set(copy);\n },\n\n clear<T extends Record<any, any>>(\n this: OptionalProperties<T> extends T ? Store<T> : never,\n ): void {\n this.set({} as T);\n },\n};\n\nexport const mapMethods = {\n delete<K, V>(this: Store<Map<K, V>>, key: K): boolean {\n const newMap = new Map(this.get());\n const result = newMap.delete(key);\n this.set(newMap);\n return result;\n },\n\n clear<K, V>(this: Store<Map<K, V>>): void {\n this.set(new Map());\n },\n};\n\nexport const setMethods = {\n add<T>(this: Store<Set<T>>, value: T): void {\n const newSet = new Set(this.get());\n newSet.add(value);\n this.set(newSet);\n },\n\n delete<T>(this: Store<Set<T>>, value: T): void {\n const newSet = new Set(this.get());\n newSet.delete(value);\n this.set(newSet);\n },\n\n clear<T>(this: Store<Set<T>>): void {\n this.set(new Set());\n },\n};\n","import { calcDuration } from './calcDuration';\nimport type { Duration } from '@core';\n\nexport function throttle<Args extends any[]>(\n action: (...args: Args) => void,\n duration: Duration,\n): (...args: Args) => void {\n const ms = calcDuration(duration);\n\n let t = 0;\n let timeout: ReturnType<typeof setTimeout> | undefined;\n\n return (...args: Args) => {\n if (timeout !== undefined) {\n clearTimeout(timeout);\n }\n\n const dt = t + ms - Date.now();\n if (dt <= 0) {\n action(...args);\n t = Date.now();\n return;\n }\n\n timeout = setTimeout(() => {\n action(...args);\n t = Date.now();\n }, dt);\n };\n}\n","import { autobind } from '@lib/autobind';\nimport { calcDuration } from '@lib/calcDuration';\nimport { calculatedValue, staticValue, type CalculatedValue } from '@lib/calculatedValue';\nimport type { Constrain } from '@lib/constrain';\nimport { debounce } from '@lib/debounce';\nimport disposable from '@lib/disposable';\nimport { deepEqual } from '@lib/equals';\nimport { forwardError } from '@lib/forwardError';\nimport { isObject } from '@lib/helpers';\nimport { makeSelector } from '@lib/makeSelector';\nimport type { AnyPath, Path, SettablePath, Value } from '@lib/path';\nimport { PromiseWithCancel } from '@lib/promiseWithCancel';\nimport { get, set } from '@lib/propAccess';\nimport { arrayMethods, mapMethods, recordMethods, setMethods } from '@lib/standardMethods';\nimport { throttle } from '@lib/throttle';\nimport type {\n CalculationActions,\n Cancel,\n DisposableCancel,\n Duration,\n Effect,\n Listener,\n Selector,\n SubscribeOptions,\n Update,\n} from './commonTypes';\n\nexport type StoreMethods = Record<string, (...args: any[]) => any>;\n\nexport type BoundStoreMethods<T, Methods extends StoreMethods> = Methods &\n ThisType<Store<T> & Methods>;\n\nexport interface StoreOptions<T> {\n retain?: Duration;\n equals?: SubscribeOptions['equals'];\n effect?: Effect<Store<T>> | { effect: Effect<Store<T>>; retain?: Duration };\n cacheValue?: boolean;\n}\n\nexport interface StoreOptionsWithMethods<T, Methods extends StoreMethods> extends StoreOptions<T> {\n methods?: Methods & ThisType<Store<T> & Methods & StandardMethods<T>>;\n}\n\nexport type Calculate<T> = (helpers: CalculationActions<T>) => T;\n\ntype StandardMethods<T> =\n T extends Map<any, any>\n ? typeof mapMethods\n : T extends Set<any>\n ? typeof setMethods\n : T extends Array<any>\n ? typeof arrayMethods\n : T extends Record<any, any>\n ? typeof recordMethods\n : Record<string, never>;\n\ntype StoreWithMethods<T, Methods extends StoreMethods> = Store<T> &\n Omit<BoundStoreMethods<T, Methods>, keyof Store<T>> &\n StandardMethods<T>;\n\nexport interface OnceOptions {\n signal?: AbortSignal;\n timeout?: Duration;\n}\n\nfunction noop() {\n return undefined;\n}\n\nexport class Store<T> {\n private static hooks?: Set<(this: Store<any>, store: Store<any>) => void>;\n\n static addHook(hook: (store: Store<any>) => void): DisposableCancel {\n this.hooks ??= new Set();\n this.hooks.add(hook);\n return disposable(() => this.hooks?.delete(hook));\n }\n\n version?: string;\n\n protected calculatedValue?: CalculatedValue<T>;\n protected defaultValue?: CalculatedValue<T>;\n\n protected listeners: Map<Listener, boolean> = new Map();\n\n protected effects: Map<\n Effect<Store<T>>,\n { handle?: Cancel; retain?: number; timeout?: ReturnType<typeof setTimeout> }\n > = new Map();\n\n protected notifyId = {};\n\n constructor(\n public readonly getter: T | Calculate<T>,\n public readonly options: StoreOptions<T> = {},\n public readonly derivedFrom?: {\n store: Store<any>;\n selectors: (Selector<any, any> | AnyPath)[];\n updater: (state: any) => void;\n },\n ) {\n autobind(Store);\n\n if (typeof getter !== 'function') {\n this.calculatedValue = this.defaultValue = staticValue(getter);\n }\n\n for (const hook of Store.hooks ?? []) {\n hook.apply(this, [this]);\n }\n\n if (options.effect instanceof Function) {\n this.addEffect(options.effect);\n } else if (options.effect) {\n this.addEffect(options.effect.effect, options.effect.retain);\n }\n }\n\n get(): T {\n if (!this.calculatedValue?.check()) {\n this.calculatedValue?.stop();\n this.calculatedValue = undefined;\n }\n\n if (!this.calculatedValue) {\n this.calculatedValue = calculatedValue(this, this.notify);\n }\n\n return this.calculatedValue.value;\n }\n\n set(update: Update<T>): void;\n\n set<const P>(path: Constrain<P, Path<T>>, update: Update<Value<T, P>>): void;\n\n set(...args: any[]): void {\n const path: any = args.length > 1 ? args[0] : [];\n let update: Update<any> = args.length > 1 ? args[1] : args[0];\n\n if (update instanceof Function) {\n const before = this.get();\n const valueBefore = get(before, path);\n const valueAfter = update(valueBefore);\n update = set(before, path, valueAfter);\n } else if (path.length > 0) {\n update = set(this.get(), path, update);\n }\n\n if (this.derivedFrom) {\n this.derivedFrom.updater(update);\n return;\n }\n\n this.calculatedValue?.stop();\n this.calculatedValue = staticValue(update);\n this.notify();\n }\n\n invalidate(recursive?: boolean): void {\n if (recursive) {\n this.calculatedValue?.invalidateDependencies(recursive);\n }\n\n this.calculatedValue?.stop();\n this.calculatedValue = this.defaultValue;\n this.notify();\n }\n\n subscribe(\n listener: Listener<T, { cancel: Cancel }>,\n options?: SubscribeOptions,\n ): DisposableCancel {\n const {\n passive,\n runNow = true,\n throttle: throttleOption,\n debounce: debounceOption,\n equals = this.options.equals ?? deepEqual,\n } = options ?? {};\n\n let isSetup = false;\n let previousValue: { value: T } | undefined;\n\n let innerListener = () => {\n if (!isSetup) {\n return;\n }\n\n const value = passive ? this.calculatedValue : { value: this.get() };\n\n if (!value) {\n return;\n }\n\n if (previousValue && equals(value.value, previousValue.value)) {\n return;\n }\n\n const _previousValue = previousValue?.value;\n previousValue = this.calculatedValue && { value: this.calculatedValue?.value };\n\n try {\n listener.apply({ cancel }, [value.value, _previousValue]);\n } catch (error) {\n forwardError(error);\n }\n };\n\n if (throttleOption) {\n innerListener = throttle(innerListener, throttleOption);\n } else if (debounceOption) {\n innerListener = debounce(innerListener, debounceOption);\n }\n\n this.listeners.set(innerListener, !passive);\n const cancel = () => {\n if (this.listeners.delete(innerListener) && !passive) {\n this.onUnsubscribe();\n }\n };\n\n if (!passive) {\n this.onSubscribe();\n }\n\n isSetup = true;\n\n if (runNow) {\n innerListener();\n\n if (\n !throttleOption &&\n typeof debounceOption === 'object' &&\n 'waitOnRunNow' in debounceOption &&\n debounceOption.waitOnRunNow === false &&\n 'flush' in innerListener\n ) {\n (innerListener as { flush: () => void }).flush();\n }\n } else {\n previousValue = passive\n ? this.calculatedValue && { value: this.calculatedValue.value }\n : { value: this.get() };\n }\n\n return disposable(cancel);\n }\n\n once<S extends T>(\n condition: (value: T) => value is S,\n options?: OnceOptions,\n ): PromiseWithCancel<S>;\n\n once(condition: (value: T) => boolean, options?: OnceOptions): PromiseWithCancel<T>;\n\n once(options?: OnceOptions): PromiseWithCancel<T>;\n\n once(\n ...args: [condition: (value: any) => boolean, options?: OnceOptions] | [options?: OnceOptions]\n ): PromiseWithCancel<any> {\n const condition = args[0] instanceof Function ? args[0] : Boolean;\n const options = args[0] instanceof Function ? args[1] : args[0];\n\n return new PromiseWithCancel<T>((resolve, reject, signal) => {\n let stopped = false;\n let timer: ReturnType<typeof setTimeout> | undefined;\n\n const cancel = this.subscribe(\n (value) => {\n if (stopped || !condition(value)) {\n return;\n }\n\n resolve(value);\n stopped = true;\n if (timer) {\n clearTimeout(timer);\n }\n setTimeout(() => cancel());\n },\n {\n runNow: !!condition,\n },\n );\n\n if (stopped) {\n return;\n }\n\n signal.addEventListener('abort', cancel);\n\n options?.signal?.addEventListener('abort', () => {\n cancel();\n reject(options.signal?.reason ?? new Error('cancelled'));\n });\n\n if (options?.timeout !== undefined) {\n timer = setTimeout(() => {\n cancel();\n reject(new Error('timeout'));\n }, calcDuration(options.timeout));\n }\n });\n }\n\n map<S>(selector: Selector<T, S>, updater?: (value: S) => Update<T>): Store<S>;\n\n map<const P>(selector: Constrain<P, SettablePath<T>>): Store<Value<T, P>>;\n\n map(_selector: Selector<T, any> | SettablePath<any>, ...args: any[]): Store<any> {\n const updater: ((value: any) => Update<T>) | undefined =\n _selector instanceof Function\n ? args[0]\n : (value) => (state) => set(state, _selector as any, value);\n\n const selector = makeSelector(_selector);\n\n const derivedFrom = {\n store: this.derivedFrom ? this.derivedFrom.store : this,\n selectors: this.derivedFrom ? [...this.derivedFrom.selectors, _selector] : [_selector],\n\n updater: (value: any) => {\n if (!updater) {\n throw new TypeError(\n 'Can only update computed stores that either are derived from other stores using string selectors or have an updater function.',\n );\n }\n\n let update = updater(value);\n\n if (update instanceof Function) {\n update = update(this.get());\n }\n\n if (this.derivedFrom) {\n this.derivedFrom.updater(update);\n } else {\n this.set(update);\n }\n },\n };\n\n return new Store(\n ({ use }) => {\n return selector(use(this));\n },\n undefined,\n derivedFrom,\n );\n }\n\n /** Add an effect that will be executed when the store becomes active, which means when it has at least one subscriber.\n * @param effect\n * If there is already a subscriber, the effect will be executed immediately.\n * Otherweise it will be executed as soon as the first subscription is created.\n * Every time all subscriptions are removed and the first is created again, the effect will be executed again.\n * @param retain\n * If provided, delay tearing down effects when the last subscriber is removed. This is useful if a short gap in subscriber coverage is supposed to be ignored. E.g. when switching pages, the old page might unsubscribe, while the new page subscribes immediately after.\n * @returns\n * The effect can return a teardown callback, which will be executed when the last subscription is removed and potentially the ratain time has passed.\n */\n addEffect(\n effect: Effect<Store<T>>,\n retain: Duration | undefined = this.options.retain,\n ): DisposableCancel {\n this.effects.set(effect, {\n handle: this.isActive() ? (effect.apply(this, [this]) ?? noop) : undefined,\n retain: retain !== undefined ? calcDuration(retain) : undefined,\n });\n\n return disposable(() => {\n const { handle, timeout } = this.effects.get(effect) ?? {};\n handle?.();\n\n if (timeout !== undefined) {\n clearTimeout(timeout);\n }\n\n this.effects.delete(effect);\n });\n }\n\n /** Return whether the store is currently active, which means whether it has at least one subscriber. */\n isActive(): boolean {\n return [...this.listeners.values()].some(Boolean);\n }\n\n protected onSubscribe(): void {\n if ([...this.listeners.values()].filter(Boolean).length > 1) return;\n\n for (const [effect, { handle, retain, timeout }] of this.effects.entries()) {\n if (timeout !== undefined) {\n clearTimeout(timeout);\n }\n\n this.effects.set(effect, {\n handle: handle ?? effect.apply(this, [this]) ?? noop,\n retain,\n timeout: undefined,\n });\n }\n }\n\n protected onUnsubscribe(): void {\n if ([...this.listeners.values()].some(Boolean)) return;\n\n for (const [effect, { handle, retain, timeout }] of this.effects.entries()) {\n if (!retain) {\n handle?.();\n\n if (timeout !== undefined) {\n clearTimeout(timeout);\n }\n\n this.effects.set(effect, {\n handle: undefined,\n retain,\n timeout: undefined,\n });\n\n continue;\n }\n\n const newTimeout =\n timeout ??\n (handle\n ? setTimeout(() => {\n handle();\n this.effects.set(effect, {\n handle: undefined,\n retain,\n timeout: undefined,\n });\n }, retain)\n : undefined);\n\n this.effects.set(effect, {\n handle,\n retain,\n timeout: newTimeout,\n });\n }\n }\n\n protected notify(): void {\n const n = {};\n this.notifyId = n;\n\n const snapshot = [...this.listeners.entries()];\n const active = snapshot.filter(([, active]) => active);\n const passive = snapshot.filter(([, active]) => !active);\n for (const [listener] of [...active, ...passive]) {\n listener();\n if (n !== this.notifyId) break;\n }\n }\n}\n\nfunction create<T>(calculate: Calculate<T>, options?: StoreOptions<T>): Store<T>;\nfunction create<T, Methods extends StoreMethods = {}>(\n initialState: T,\n options?: StoreOptionsWithMethods<T, Methods>,\n): StoreWithMethods<T, Methods>;\nfunction create<T, Methods extends StoreMethods>(\n initialState: T | Calculate<T>,\n options?: StoreOptionsWithMethods<T, Methods>,\n): StoreWithMethods<T, Methods> | Store<T> {\n options = { ...createStore.defaultOptions, ...options };\n\n const store = new Store(initialState, options);\n\n if (initialState instanceof Function) {\n return store;\n }\n\n let methods: StoreMethods | undefined = options?.methods;\n\n if (initialState instanceof Map) {\n methods = { ...mapMethods, ...methods };\n } else if (initialState instanceof Set) {\n methods = { ...setMethods, ...methods };\n } else if (Array.isArray(initialState)) {\n methods = { ...arrayMethods, ...methods };\n } else if (isObject(initialState)) {\n methods = { ...recordMethods, ...methods };\n }\n\n const boundMethods = Object.fromEntries(\n Object.entries(methods ?? ({} as BoundStoreMethods<T, any>))\n .filter(([name]) => !(name in store))\n .map(([name, action]) => [name, (action as any).bind(store)]),\n ) as BoundStoreMethods<T, any>;\n\n return Object.assign(store, boundMethods);\n}\n\nexport const createStore: typeof create & { defaultOptions: StoreOptions<any> } =\n /* @__PURE__ */ Object.assign(create, {\n defaultOptions: {\n equals: deepEqual,\n } as StoreOptions<any>,\n });\n"],"mappings":";;;AAAA,MAAM,SAAS,OAAO;AAEtB,MAAa,YAGX,WACW;AACX,MAAK,MAAM,OAAO,QAAQ,QAAQ,OAAO,YAAY;AACnD,MAAI,QAAQ,cACV;EAGF,MAAM,aAAa,QAAQ,yBAAyB,OA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A,cAAY,CAACA;AACjD,OAAK,MAAM,CAAC,aAAa,CAAC,GAAG,QAAQ,GAAG,UAAU;AAChD;AACA,OAAI,MAAM,KAAK,SAAU;;;;AAU/B,SAAS,OACP,cACA,SACyC;AACzC,WAAU;EAAE,GAAG,YAAY;EAAgB,GAAG;;CAE9C,MAAM,QAAQ,IAAI,MAAM,cAAc;AAEtC,KAAI,wBAAwB,SAC1B,QAAO;CAGT,IAAIC,UAAoC,SAAS;AAEjD,KAAI,wBAAwB,IAC1B,WAAU;EAAE,GAAG;EAAY,GAAG;;UACrB,wBAAwB,IACjC,WAAU;EAAE,GAAG;EAAY,GAAG;;UACrB,MAAM,QAAQ,cACvB,WAAU;EAAE,GAAG;EAAc,GAAG;;UACvB,SAAS,cAClB,WAAU;EAAE,GAAG;EAAe,GAAG;;CAGnC,MAAM,eAAe,OAAO,YAC1B,OAAO,QAAQ,WAAY,IACxB,QAAQ,CAAC,UAAU,EAAE,QAAQ,QAC7B,KAAK,CAAC,MAAM,YAAY,CAAC,MAAO,OAAe,KAAK;AAGzD,QAAO,OAAO,OAAO,OAAO;;AAG9B,MAAaC,cACK,uBAAO,OAAO,QAAQ,EACpC,gBAAgB,EACd,QAAQ"}
1
+ {"version":3,"file":"store-Dx8w7yT-.js","names":["state: ValueState<T> | ErrorState | PendingState","value","q: {\n action: Action<any>;\n resolve: (value: any) => void;\n reject: (error: unknown) => void;\n ref?: any;\n }[]","value: T | undefined","connection: { active: boolean; cancel?: Cancel } | undefined","value","cancel: Cancel | undefined","actions: AsyncConnectionActions<any>","_cancel: Cancel | undefined","run: (() => void) | undefined","timeout: ReturnType<typeof setTimeout> | undefined","timeoutStarted: number | undefined","debounce","arrayMethods: {\n [P in 'splice' | 'push' | 'pop' | 'shift' | 'unshift' | 'reverse' | 'sort']: <\n T extends Array<any>,\n >(\n this: Store<T>,\n ...args: T[P] extends Function_ ? Parameters<T[P]> : never\n ) => T[P] extends Function_ ? ReturnType<T[P]> : never;\n}","timeout: ReturnType<typeof setTimeout> | undefined","getter: T | Calculate<T>","options: StoreOptions<T>","derivedFrom?: {\n store: Store<any>;\n selectors: (Selector<any, any> | AnyPath)[];\n updater: (state: any) => void;\n }","path: any","update: Update<any>","previousValue: { value: T } | undefined","timer: ReturnType<typeof setTimeout> | undefined","updater: ((value: any) => Update<T>) | undefined","active","methods: StoreMethods | undefined","createStore: typeof create & { defaultOptions: StoreOptions<any> }"],"sources":["../src/lib/autobind.ts","../src/lib/calcDuration.ts","../src/lib/deferred.ts","../src/lib/isPromise.ts","../src/lib/promiseWithState.ts","../src/lib/queue.ts","../src/lib/calculatedValue.ts","../src/lib/makeSelector.ts","../src/lib/debounce.ts","../src/lib/disposable.ts","../src/lib/forwardError.ts","../src/lib/promiseWithCancel.ts","../src/lib/standardMethods.ts","../src/lib/throttle.ts","../src/core/store.ts"],"sourcesContent":["const marker = Symbol('autobind');\n\nexport const autobind = <\n TClass extends abstract new (...args: any) => any = abstract new (...args: any) => any,\n>(\n _class: TClass,\n): TClass => {\n for (const key of Reflect.ownKeys(_class.prototype)) {\n if (key === 'constructor') {\n continue;\n }\n\n const descriptor = Reflect.getOwnPropertyDescriptor(_class.prototype, key);\n let method = descriptor?.get?.() ?? descriptor?.value;\n let isBinding = false;\n\n if (typeof method !== 'function' || method[marker]) {\n continue;\n }\n\n Reflect.defineProperty(_class.prototype, key, {\n configurable: true,\n get() {\n if (\n isBinding ||\n this === _class.prototype ||\n Object.prototype.hasOwnProperty.call(this, key) ||\n typeof method !== 'function'\n ) {\n return method;\n }\n\n const boundMethod = (...args: any[]) => Reflect.apply(method, this, args);\n boundMethod[marker] = true;\n isBinding = true;\n\n Object.defineProperty(this, key, {\n configurable: true,\n get() {\n return boundMethod;\n },\n });\n\n isBinding = false;\n return boundMethod;\n },\n set(v) {\n method = v;\n },\n });\n }\n\n return _class;\n};\n","import type { Duration } from '../core/commonTypes';\n\nexport function calcDuration(t: Duration): number {\n if (typeof t === 'number') return t;\n return (\n (t.milliseconds ?? 0) +\n (t.seconds ?? 0) * 1000 +\n (t.minutes ?? 0) * 60 * 1000 +\n (t.hours ?? 0) * 60 * 60 * 1000 +\n (t.days ?? 0) * 24 * 60 * 60 * 1000\n );\n}\n","export class Deferred<T = void> extends Promise<T> {\n resolve: (value: T | PromiseLike<T>) => void = () => undefined;\n reject: (reason?: any) => void = () => undefined;\n\n constructor() {\n Object.defineProperty(Deferred, Symbol.species, {\n value: Promise,\n });\n\n const that = {};\n\n super((resolve, reject) => {\n Object.assign(that, { resolve, reject });\n });\n\n Object.assign(this, that);\n }\n}\n","export default function isPromise(value: unknown): value is Promise<unknown> {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'then' in value &&\n typeof value.then === 'function'\n );\n}\n","import isPromise from '@lib/isPromise';\nimport { type ErrorState, type PendingState, type ValueState } from './cacheState';\nimport { type MaybePromise } from './maybePromise';\n\nexport class PromiseWithState<T> extends Promise<T> {\n static override resolve(): PromiseWithState<void>;\n\n static override resolve<T>(value: MaybePromise<T>): PromiseWithState<T>;\n\n static override resolve<T>(value?: MaybePromise<T>) {\n return new PromiseWithState<T>(value as MaybePromise<T>);\n }\n\n static override reject<T = never>(error: unknown): PromiseWithState<T> {\n return new PromiseWithState<T>(Promise.reject(error), { status: 'error', error });\n }\n\n constructor(\n value: MaybePromise<T>,\n public state: ValueState<T> | ErrorState | PendingState = { status: 'pending' },\n ) {\n super((resolve) => resolve(value));\n\n Object.defineProperty(PromiseWithState, Symbol.species, {\n value: Promise,\n });\n\n if (isPromise(value)) {\n value\n .then((value) => {\n this.state = { status: 'value', value: value };\n })\n .catch((error) => {\n this.state = { status: 'error', error };\n });\n } else {\n this.state = { status: 'value', value: value };\n }\n }\n}\n","import isPromise from '@lib/isPromise';\nimport type { MaybePromise } from './maybePromise';\nimport type { Listener } from '@core';\n\ntype Action<T> = () => MaybePromise<T>;\n\nexport interface Queue {\n <T>(action: Action<T>, ref?: any): Promise<T>;\n clear: () => void;\n whenDone: () => Promise<void>;\n size: number;\n getRefs: () => any[];\n}\n\nexport function queue(): Queue {\n const q: {\n action: Action<any>;\n resolve: (value: any) => void;\n reject: (error: unknown) => void;\n ref?: any;\n }[] = [];\n const completionListeners = new Set<Listener<void>>();\n let active = false;\n\n const notify = () => {\n for (const listener of completionListeners) {\n listener();\n }\n\n completionListeners.clear();\n };\n\n const run = async () => {\n if (!active) {\n active = true;\n\n let next;\n while ((next = q.shift())) {\n try {\n let result = next.action();\n if (isPromise(result)) {\n result = await result;\n }\n\n next.resolve(result);\n } catch (error) {\n next.reject(error);\n }\n }\n\n active = false;\n notify();\n }\n };\n\n return Object.assign(\n <T>(action: Action<T>, ref?: any) => {\n return new Promise<T>((resolve, reject) => {\n q.push({ action, resolve, reject, ref });\n run();\n });\n },\n {\n clear() {\n q.length = 0;\n },\n\n whenDone() {\n if (!active) {\n return Promise.resolve();\n }\n\n return new Promise<void>((resolve) => {\n completionListeners.add(resolve);\n });\n },\n\n get size() {\n return q.length;\n },\n\n getRefs() {\n return q.map((item) => item.ref).filter((x) => x !== undefined);\n },\n },\n );\n}\n","import type { Cache } from '@core';\nimport type { AsyncConnectionActions, Cancel, Connection, StoreLike } from '@core/commonTypes';\nimport type { Store } from '@core/store';\nimport { Deferred } from '@lib/deferred';\nimport isPromise from '@lib/isPromise';\nimport { PromiseWithState } from '@lib/promiseWithState';\nimport { queue } from '@lib/queue';\nimport { deepEqual } from './equals';\n\nexport interface CalculatedValue<T> {\n value: T;\n check: () => void;\n stop(): void;\n invalidateDependencies(recursive?: boolean): void;\n}\n\nexport function calculatedValue<T>(store: Store<T>, notify: () => void): CalculatedValue<T> {\n if (!(store.getter instanceof Function)) {\n return staticValue(store.getter);\n }\n\n let active = false;\n const deps = new Array<{ store: StoreLike<any>; value: any; on: () => void; off: () => void }>();\n let value: T | undefined;\n const whenConnected = new Deferred();\n const whenExecuted = new Deferred();\n const ac = new AbortController();\n let connection: { active: boolean; cancel?: Cancel } | undefined;\n const q = queue();\n q(() => whenExecuted);\n\n const cancelEffect = store.addEffect(() => {\n if (connection) {\n store.invalidate();\n return;\n }\n\n active = true;\n\n for (const dep of deps) {\n dep.on();\n }\n\n return () => {\n active = false;\n\n for (const dep of deps) {\n dep.off();\n }\n\n if (connection) {\n connection.active = false;\n connection.cancel?.();\n q.clear();\n\n if ('state' in store) {\n (store as unknown as Cache<any>).state.set((state) => ({\n ...state,\n isConnected: false,\n isStale: true,\n }));\n }\n }\n };\n });\n\n function use<S>(dep: StoreLike<S>) {\n const value = dep.get();\n let cancel: Cancel | undefined;\n\n const on = () => {\n cancel ||= dep.subscribe(() => store.invalidate(), { runNow: false });\n };\n\n const off = () => {\n cancel?.();\n cancel = undefined;\n };\n\n deps.push({ store: dep, value, on, off });\n\n if (active) {\n on();\n }\n\n return value;\n }\n\n async function connect(createConnection: Connection<T>) {\n if (!active) {\n connection = { active: false };\n return;\n }\n\n const actions: AsyncConnectionActions<any> = {\n set(_value) {\n q(() => {\n if (!connection?.active) {\n return;\n }\n\n value = _value;\n notify();\n });\n },\n updateValue(update) {\n q(async () => {\n if (!connection?.active) {\n return;\n }\n\n if (update instanceof Function) {\n const currentValue = await value;\n\n if (!connection?.active) {\n return;\n }\n\n try {\n update = update(currentValue);\n } catch (error) {\n value = PromiseWithState.reject(error) as T;\n notify();\n connection.active = false;\n connection.cancel?.();\n return;\n }\n }\n\n value = PromiseWithState.resolve(update) as T;\n notify();\n });\n },\n updateError(error) {\n q(() => {\n if (!connection?.active) {\n return;\n }\n\n connection.active = false;\n connection.cancel?.();\n\n if ('state' in store) {\n (store as unknown as Cache<any>).state.set({\n status: 'error',\n error,\n isConnected: false,\n isUpdating: false,\n isStale: false,\n });\n }\n\n value = PromiseWithState.reject(error) as T;\n notify();\n });\n },\n updateIsConnected(isConnected) {\n if (isConnected) {\n whenConnected.resolve();\n }\n\n q(() => {\n if (!connection?.active) {\n return;\n }\n\n if ('state' in store) {\n (store as unknown as Cache<any>).state.set('isConnected', isConnected);\n }\n });\n },\n close() {\n if (connection?.active) {\n store.invalidate();\n }\n },\n };\n\n connection = { active: true };\n let _cancel: Cancel | undefined = createConnection(actions as any);\n\n connection.cancel = () => {\n _cancel?.();\n _cancel = undefined;\n };\n\n if (!connection.active) {\n connection.cancel();\n }\n\n return whenConnected;\n }\n\n try {\n value = store.getter({ signal: ac.signal, use, connect });\n } catch (error) {\n value = PromiseWithState.reject(error) as T;\n\n if (connection) {\n connection.active = false;\n connection.cancel?.();\n q.clear();\n }\n }\n\n if (isPromise(value)) {\n value.finally(() => whenExecuted.resolve()).catch(() => undefined);\n } else {\n whenExecuted.resolve();\n }\n\n function check() {\n if (store.options.cacheValue === false) {\n return false;\n }\n\n for (const dep of deps) {\n if (!deepEqual(dep.store.get(), dep.value)) {\n return false;\n }\n }\n return true;\n }\n\n function stop() {\n cancelEffect();\n whenExecuted.resolve();\n whenConnected.resolve();\n ac.abort();\n\n if (connection) {\n connection.active = false;\n connection.cancel?.();\n q.clear();\n }\n }\n\n function invalidateDependencies(recursive?: boolean) {\n for (const dep of deps) {\n dep.store.invalidate(recursive);\n }\n }\n\n return {\n get value() {\n return value!;\n },\n check,\n stop,\n invalidateDependencies,\n };\n}\n\nexport function staticValue<T>(value: T): CalculatedValue<T> {\n return {\n value,\n check: () => true,\n stop: () => undefined,\n invalidateDependencies: () => undefined,\n };\n}\n\nexport function staleValue<T>(value: T): CalculatedValue<T> {\n return {\n value,\n check: () => false,\n stop: () => undefined,\n invalidateDependencies: () => undefined,\n };\n}\n","import type { AnyPath } from './path';\nimport { get } from './propAccess';\n\nexport function makeSelector<T, S>(selector?: ((value: T) => S) | AnyPath): (value: T) => S {\n if (!selector) {\n return (x) => x as any;\n }\n\n if (selector instanceof Function) {\n return selector;\n }\n\n return (x) => get(x, selector as any) as any;\n}\n","import { calcDuration } from './calcDuration';\nimport type { Duration } from '@core';\n\nexport type DebounceOptions =\n | Duration\n | {\n wait: Duration;\n maxWait?: Duration;\n waitOnRunNow?: boolean;\n };\n\nexport function debounce<Args extends any[]>(\n action: (...args: Args) => void,\n options: Duration | DebounceOptions,\n): {\n (...args: Args): void;\n flush(): void;\n cancel(): void;\n isScheduled(): boolean;\n} {\n const wait =\n typeof options === 'object' && 'wait' in options\n ? calcDuration(options.wait)\n : calcDuration(options);\n\n const maxWait =\n typeof options === 'object' && 'maxWait' in options && options.maxWait !== undefined\n ? calcDuration(options.maxWait)\n : undefined;\n\n let run: (() => void) | undefined;\n let timeout: ReturnType<typeof setTimeout> | undefined;\n let timeoutStarted: number | undefined;\n\n function flush() {\n if (timeout !== undefined) {\n clearTimeout(timeout);\n }\n\n run?.();\n }\n\n function cancel() {\n if (timeout !== undefined) {\n clearTimeout(timeout);\n }\n\n run = undefined;\n timeout = undefined;\n timeoutStarted = undefined;\n }\n\n function isScheduled() {\n return timeout !== undefined;\n }\n\n function debounce(...args: Args) {\n const now = Date.now();\n timeoutStarted ??= now;\n\n const deadline = Math.min(\n //\n now + wait,\n timeoutStarted + (maxWait ?? Number.POSITIVE_INFINITY),\n );\n\n if (timeout !== undefined) {\n clearTimeout(timeout);\n }\n\n run = () => {\n run = undefined;\n timeout = undefined;\n timeoutStarted = undefined;\n\n action(...args);\n };\n\n timeout = setTimeout(run, deadline - now);\n }\n\n return Object.assign(debounce, { flush, cancel, isScheduled });\n}\n","import type { Cancel } from '@core';\nimport type { DisposableCancel } from '@core/commonTypes';\n\nexport default function disposable(dispose: Cancel): DisposableCancel {\n return Object.assign(\n dispose,\n Symbol.dispose ? { [Symbol.dispose]: dispose } : {},\n ) as DisposableCancel;\n}\n","export function forwardError(error: unknown): void {\n setTimeout(() => {\n throw error;\n });\n}\n","import { autobind } from '@lib/autobind';\n\nexport class PromiseCancelError extends Error {\n constructor() {\n super('cancelled');\n }\n}\n\nexport class PromiseWithCancel<T> extends Promise<T> {\n private abortController;\n\n constructor(\n executor: (\n resolve: (value: T) => void,\n reject: (error: unknown) => void,\n signal: AbortSignal,\n ) => void,\n ) {\n autobind(PromiseWithCancel);\n const abortController = new AbortController();\n\n super((resolve, reject) => {\n executor(resolve, reject, abortController.signal);\n\n abortController.signal.addEventListener('abort', () => {\n reject(abortController.signal.reason);\n });\n });\n\n this.abortController = abortController;\n }\n\n cancel(reason: any = new PromiseCancelError()): void {\n this.abortController.abort(reason);\n }\n}\n","import type { Store } from '../core/store';\nimport type { OptionalProperties, OptionalPropertyOf } from './typeHelpers';\n\ntype Function_ = (...args: any) => any;\n\nfunction createArrayAction<P extends keyof Array<any>>(prop: P) {\n return function arrayAction<T extends Array<any>>(\n this: Store<T>,\n ...args: T[P] extends Function_ ? Parameters<T[P]> : never\n ): T[P] extends Function_ ? ReturnType<T[P]> : never {\n const newArray = this.get().slice() as T;\n const result = (newArray[prop] as Function_)(...(args as any));\n this.set(newArray);\n return result;\n };\n}\nexport const arrayMethods: {\n [P in 'splice' | 'push' | 'pop' | 'shift' | 'unshift' | 'reverse' | 'sort']: <\n T extends Array<any>,\n >(\n this: Store<T>,\n ...args: T[P] extends Function_ ? Parameters<T[P]> : never\n ) => T[P] extends Function_ ? ReturnType<T[P]> : never;\n} = {\n splice: /* @__PURE__ */ createArrayAction('splice'),\n push: /* @__PURE__ */ createArrayAction('push'),\n pop: /* @__PURE__ */ createArrayAction('pop'),\n shift: /* @__PURE__ */ createArrayAction('shift'),\n unshift: /* @__PURE__ */ createArrayAction('unshift'),\n reverse: /* @__PURE__ */ createArrayAction('reverse'),\n sort: /* @__PURE__ */ createArrayAction('sort'),\n};\n\nexport const recordMethods = {\n delete<T extends Record<any, any>, K extends OptionalPropertyOf<T>>(\n this: Store<T>,\n key: K,\n ): void {\n const copy = { ...this.get() };\n delete copy[key];\n this.set(copy);\n },\n\n clear<T extends Record<any, any>>(\n this: OptionalProperties<T> extends T ? Store<T> : never,\n ): void {\n this.set({} as T);\n },\n};\n\nexport const mapMethods = {\n delete<K, V>(this: Store<Map<K, V>>, key: K): boolean {\n const newMap = new Map(this.get());\n const result = newMap.delete(key);\n this.set(newMap);\n return result;\n },\n\n clear<K, V>(this: Store<Map<K, V>>): void {\n this.set(new Map());\n },\n};\n\nexport const setMethods = {\n add<T>(this: Store<Set<T>>, value: T): void {\n const newSet = new Set(this.get());\n newSet.add(value);\n this.set(newSet);\n },\n\n delete<T>(this: Store<Set<T>>, value: T): void {\n const newSet = new Set(this.get());\n newSet.delete(value);\n this.set(newSet);\n },\n\n clear<T>(this: Store<Set<T>>): void {\n this.set(new Set());\n },\n};\n","import { calcDuration } from './calcDuration';\nimport type { Duration } from '@core';\n\nexport function throttle<Args extends any[]>(\n action: (...args: Args) => void,\n duration: Duration,\n): (...args: Args) => void {\n const ms = calcDuration(duration);\n\n let t = 0;\n let timeout: ReturnType<typeof setTimeout> | undefined;\n\n return (...args: Args) => {\n if (timeout !== undefined) {\n clearTimeout(timeout);\n }\n\n const dt = t + ms - Date.now();\n if (dt <= 0) {\n action(...args);\n t = Date.now();\n return;\n }\n\n timeout = setTimeout(() => {\n action(...args);\n t = Date.now();\n }, dt);\n };\n}\n","import { autobind } from '@lib/autobind';\nimport { calcDuration } from '@lib/calcDuration';\nimport { calculatedValue, staticValue, type CalculatedValue } from '@lib/calculatedValue';\nimport type { Constrain } from '@lib/constrain';\nimport { debounce } from '@lib/debounce';\nimport disposable from '@lib/disposable';\nimport { deepEqual } from '@lib/equals';\nimport { forwardError } from '@lib/forwardError';\nimport { isObject } from '@lib/helpers';\nimport { makeSelector } from '@lib/makeSelector';\nimport type { AnyPath, Path, SettablePath, Value } from '@lib/path';\nimport { PromiseWithCancel } from '@lib/promiseWithCancel';\nimport { get, set } from '@lib/propAccess';\nimport { arrayMethods, mapMethods, recordMethods, setMethods } from '@lib/standardMethods';\nimport { throttle } from '@lib/throttle';\nimport type {\n CalculationActions,\n Cancel,\n DisposableCancel,\n Duration,\n Effect,\n Listener,\n Selector,\n SubscribeOptions,\n Update,\n} from './commonTypes';\n\nexport type StoreMethods = Record<string, (...args: any[]) => any>;\n\nexport type BoundStoreMethods<T, Methods extends StoreMethods> = Methods &\n ThisType<Store<T> & Methods>;\n\nexport interface StoreOptions<T> {\n retain?: Duration;\n equals?: SubscribeOptions['equals'];\n effect?: Effect<Store<T>> | { effect: Effect<Store<T>>; retain?: Duration };\n cacheValue?: boolean;\n}\n\nexport interface StoreOptionsWithMethods<T, Methods extends StoreMethods> extends StoreOptions<T> {\n methods?: Methods & ThisType<Store<T> & Methods & StandardMethods<T>>;\n}\n\nexport type Calculate<T> = (helpers: CalculationActions<T>) => T;\n\ntype StandardMethods<T> =\n T extends Map<any, any>\n ? typeof mapMethods\n : T extends Set<any>\n ? typeof setMethods\n : T extends Array<any>\n ? typeof arrayMethods\n : T extends Record<any, any>\n ? typeof recordMethods\n : Record<string, never>;\n\ntype StoreWithMethods<T, Methods extends StoreMethods> = Store<T> &\n Omit<BoundStoreMethods<T, Methods>, keyof Store<T>> &\n StandardMethods<T>;\n\nexport interface OnceOptions {\n signal?: AbortSignal;\n timeout?: Duration;\n}\n\nfunction noop() {\n return undefined;\n}\n\nexport class Store<T> {\n private static hooks?: Set<(this: Store<any>, store: Store<any>) => void>;\n\n static addHook(hook: (store: Store<any>) => void): DisposableCancel {\n this.hooks ??= new Set();\n this.hooks.add(hook);\n return disposable(() => this.hooks?.delete(hook));\n }\n\n version?: string;\n\n protected calculatedValue?: CalculatedValue<T>;\n protected defaultValue?: CalculatedValue<T>;\n\n protected listeners: Map<Listener, boolean> = new Map();\n\n protected effects: Map<\n Effect<Store<T>>,\n { handle?: Cancel; retain?: number; timeout?: ReturnType<typeof setTimeout> }\n > = new Map();\n\n protected notifyId = {};\n\n constructor(\n public readonly getter: T | Calculate<T>,\n public readonly options: StoreOptions<T> = {},\n public readonly derivedFrom?: {\n store: Store<any>;\n selectors: (Selector<any, any> | AnyPath)[];\n updater: (state: any) => void;\n },\n ) {\n autobind(Store);\n\n if (typeof getter !== 'function') {\n this.calculatedValue = this.defaultValue = staticValue(getter);\n }\n\n for (const hook of Store.hooks ?? []) {\n hook.apply(this, [this]);\n }\n\n if (options.effect instanceof Function) {\n this.addEffect(options.effect);\n } else if (options.effect) {\n this.addEffect(options.effect.effect, options.effect.retain);\n }\n }\n\n get(): T {\n if (!this.calculatedValue?.check()) {\n this.calculatedValue?.stop();\n this.calculatedValue = undefined;\n }\n\n if (!this.calculatedValue) {\n this.calculatedValue = calculatedValue(this, this.notify);\n }\n\n return this.calculatedValue.value;\n }\n\n set(update: Update<T>): void;\n\n set<const P>(path: Constrain<P, Path<T>>, update: Update<Value<T, P>>): void;\n\n set(...args: any[]): void {\n const path: any = args.length > 1 ? args[0] : [];\n let update: Update<any> = args.length > 1 ? args[1] : args[0];\n\n if (update instanceof Function) {\n const before = this.get();\n const valueBefore = get(before, path);\n const valueAfter = update(valueBefore);\n update = set(before, path, valueAfter);\n } else if (path.length > 0) {\n update = set(this.get(), path, update);\n }\n\n if (this.derivedFrom) {\n this.derivedFrom.updater(update);\n return;\n }\n\n this.calculatedValue?.stop();\n this.calculatedValue = staticValue(update);\n this.notify();\n }\n\n invalidate(recursive?: boolean): void {\n if (recursive) {\n this.calculatedValue?.invalidateDependencies(recursive);\n }\n\n this.calculatedValue?.stop();\n this.calculatedValue = this.defaultValue;\n this.notify();\n }\n\n subscribe(\n listener: Listener<T, { cancel: Cancel }>,\n options?: SubscribeOptions,\n ): DisposableCancel {\n const {\n passive,\n runNow = true,\n throttle: throttleOption,\n debounce: debounceOption,\n equals = this.options.equals ?? deepEqual,\n } = options ?? {};\n\n let isSetup = false;\n let previousValue: { value: T } | undefined;\n\n let innerListener = () => {\n if (!isSetup) {\n return;\n }\n\n const value = passive ? this.calculatedValue : { value: this.get() };\n\n if (!value) {\n return;\n }\n\n if (previousValue && equals(value.value, previousValue.value)) {\n return;\n }\n\n const _previousValue = previousValue?.value;\n previousValue = this.calculatedValue && { value: this.calculatedValue?.value };\n\n try {\n listener.apply({ cancel }, [value.value, _previousValue]);\n } catch (error) {\n forwardError(error);\n }\n };\n\n if (throttleOption) {\n innerListener = throttle(innerListener, throttleOption);\n } else if (debounceOption) {\n innerListener = debounce(innerListener, debounceOption);\n }\n\n this.listeners.set(innerListener, !passive);\n const cancel = () => {\n if (this.listeners.delete(innerListener) && !passive) {\n this.onUnsubscribe();\n }\n };\n\n if (!passive) {\n this.onSubscribe();\n }\n\n isSetup = true;\n\n if (runNow) {\n innerListener();\n\n if (\n !throttleOption &&\n typeof debounceOption === 'object' &&\n 'waitOnRunNow' in debounceOption &&\n debounceOption.waitOnRunNow === false &&\n 'flush' in innerListener\n ) {\n (innerListener as { flush: () => void }).flush();\n }\n } else {\n previousValue = passive\n ? this.calculatedValue && { value: this.calculatedValue.value }\n : { value: this.get() };\n }\n\n return disposable(cancel);\n }\n\n once<S extends T>(\n condition: (value: T) => value is S,\n options?: OnceOptions,\n ): PromiseWithCancel<S>;\n\n once(condition: (value: T) => boolean, options?: OnceOptions): PromiseWithCancel<T>;\n\n once(options?: OnceOptions): PromiseWithCancel<Exclude<T, undefined>>;\n\n once(\n ...args: [condition: (value: any) => boolean, options?: OnceOptions] | [options?: OnceOptions]\n ): PromiseWithCancel<any> {\n const condition = args[0] instanceof Function ? args[0] : (x: T) => x !== undefined;\n const options = args[0] instanceof Function ? args[1] : args[0];\n\n return new PromiseWithCancel<T>((resolve, reject, signal) => {\n let stopped = false;\n let timer: ReturnType<typeof setTimeout> | undefined;\n\n const cancel = this.subscribe(\n (value) => {\n if (stopped || !condition(value)) {\n return;\n }\n\n resolve(value);\n stopped = true;\n if (timer) {\n clearTimeout(timer);\n }\n setTimeout(() => cancel());\n },\n {\n runNow: !!condition,\n },\n );\n\n if (stopped) {\n return;\n }\n\n signal.addEventListener('abort', cancel);\n\n options?.signal?.addEventListener('abort', () => {\n cancel();\n reject(options.signal?.reason ?? new Error('cancelled'));\n });\n\n if (options?.timeout !== undefined) {\n timer = setTimeout(() => {\n cancel();\n reject(new Error('timeout'));\n }, calcDuration(options.timeout));\n }\n });\n }\n\n map<S>(selector: Selector<T, S>, updater?: (value: S) => Update<T>): Store<S>;\n\n map<const P>(selector: Constrain<P, SettablePath<T>>): Store<Value<T, P>>;\n\n map(_selector: Selector<T, any> | SettablePath<any>, ...args: any[]): Store<any> {\n const updater: ((value: any) => Update<T>) | undefined =\n _selector instanceof Function\n ? args[0]\n : (value) => (state) => set(state, _selector as any, value);\n\n const selector = makeSelector(_selector);\n\n const derivedFrom = {\n store: this.derivedFrom ? this.derivedFrom.store : this,\n selectors: this.derivedFrom ? [...this.derivedFrom.selectors, _selector] : [_selector],\n\n updater: (value: any) => {\n if (!updater) {\n throw new TypeError(\n 'Can only update computed stores that either are derived from other stores using string selectors or have an updater function.',\n );\n }\n\n let update = updater(value);\n\n if (update instanceof Function) {\n update = update(this.get());\n }\n\n if (this.derivedFrom) {\n this.derivedFrom.updater(update);\n } else {\n this.set(update);\n }\n },\n };\n\n return new Store(\n ({ use }) => {\n return selector(use(this));\n },\n undefined,\n derivedFrom,\n );\n }\n\n /** Add an effect that will be executed when the store becomes active, which means when it has at least one subscriber.\n * @param effect\n * If there is already a subscriber, the effect will be executed immediately.\n * Otherweise it will be executed as soon as the first subscription is created.\n * Every time all subscriptions are removed and the first is created again, the effect will be executed again.\n * @param retain\n * If provided, delay tearing down effects when the last subscriber is removed. This is useful if a short gap in subscriber coverage is supposed to be ignored. E.g. when switching pages, the old page might unsubscribe, while the new page subscribes immediately after.\n * @returns\n * The effect can return a teardown callback, which will be executed when the last subscription is removed and potentially the ratain time has passed.\n */\n addEffect(\n effect: Effect<Store<T>>,\n retain: Duration | undefined = this.options.retain,\n ): DisposableCancel {\n this.effects.set(effect, {\n handle: this.isActive() ? (effect.apply(this, [this]) ?? noop) : undefined,\n retain: retain !== undefined ? calcDuration(retain) : undefined,\n });\n\n return disposable(() => {\n const { handle, timeout } = this.effects.get(effect) ?? {};\n handle?.();\n\n if (timeout !== undefined) {\n clearTimeout(timeout);\n }\n\n this.effects.delete(effect);\n });\n }\n\n /** Return whether the store is currently active, which means whether it has at least one subscriber. */\n isActive(): boolean {\n return [...this.listeners.values()].some(Boolean);\n }\n\n protected onSubscribe(): void {\n if ([...this.listeners.values()].filter(Boolean).length > 1) return;\n\n for (const [effect, { handle, retain, timeout }] of this.effects.entries()) {\n if (timeout !== undefined) {\n clearTimeout(timeout);\n }\n\n this.effects.set(effect, {\n handle: handle ?? effect.apply(this, [this]) ?? noop,\n retain,\n timeout: undefined,\n });\n }\n }\n\n protected onUnsubscribe(): void {\n if ([...this.listeners.values()].some(Boolean)) return;\n\n for (const [effect, { handle, retain, timeout }] of this.effects.entries()) {\n if (!retain) {\n handle?.();\n\n if (timeout !== undefined) {\n clearTimeout(timeout);\n }\n\n this.effects.set(effect, {\n handle: undefined,\n retain,\n timeout: undefined,\n });\n\n continue;\n }\n\n const newTimeout =\n timeout ??\n (handle\n ? setTimeout(() => {\n handle();\n this.effects.set(effect, {\n handle: undefined,\n retain,\n timeout: undefined,\n });\n }, retain)\n : undefined);\n\n this.effects.set(effect, {\n handle,\n retain,\n timeout: newTimeout,\n });\n }\n }\n\n protected notify(): void {\n const n = {};\n this.notifyId = n;\n\n const snapshot = [...this.listeners.entries()];\n const active = snapshot.filter(([, active]) => active);\n const passive = snapshot.filter(([, active]) => !active);\n for (const [listener] of [...active, ...passive]) {\n listener();\n if (n !== this.notifyId) break;\n }\n }\n}\n\nfunction create<T>(calculate: Calculate<T>, options?: StoreOptions<T>): Store<T>;\nfunction create<T, Methods extends StoreMethods = {}>(\n initialState: T,\n options?: StoreOptionsWithMethods<T, Methods>,\n): StoreWithMethods<T, Methods>;\nfunction create<T, Methods extends StoreMethods>(\n initialState: T | Calculate<T>,\n options?: StoreOptionsWithMethods<T, Methods>,\n): StoreWithMethods<T, Methods> | Store<T> {\n options = { ...createStore.defaultOptions, ...options };\n\n const store = new Store(initialState, options);\n\n if (initialState instanceof Function) {\n return store;\n }\n\n let methods: StoreMethods | undefined = options?.methods;\n\n if (initialState instanceof Map) {\n methods = { ...mapMethods, ...methods };\n } else if (initialState instanceof Set) {\n methods = { ...setMethods, ...methods };\n } else if (Array.isArray(initialState)) {\n methods = { ...arrayMethods, ...methods };\n } else if (isObject(initialState)) {\n methods = { ...recordMethods, ...methods };\n }\n\n const boundMethods = Object.fromEntries(\n Object.entries(methods ?? ({} as BoundStoreMethods<T, any>))\n .filter(([name]) => !(name in store))\n .map(([name, action]) => [name, (action as any).bind(store)]),\n ) as BoundStoreMethods<T, any>;\n\n return Object.assign(store, boundMethods);\n}\n\nexport const createStore: typeof create & { defaultOptions: StoreOptions<any> } =\n /* @__PURE__ */ Object.assign(create, {\n defaultOptions: {\n equals: deepEqual,\n } as StoreOptions<any>,\n });\n"],"mappings":";;;AAAA,MAAM,SAAS,OAAO;AAEtB,MAAa,YAGX,WACW;AACX,MAAK,MAAM,OAAO,QAAQ,QAAQ,OAAO,YAAY;AACnD,MAAI,QAAQ,cACV;EAGF,MAAM,aAAa,QAAQ,yBAAyB,OAAO,WAAW;EACtE,IAAI,SAAS,YAAY,WAAW,YAAY;EAChD,IAAI,YAAY;AAEhB,MAAI,OAAO,WAAW,cAAc,OAAO,QACzC;AAGF,UAAQ,eAAe,OAAO,WAAW,KAAK;GAC5C,cAAc;GACd,MAAM;AACJ,QACE,aACA,SAAS,OAAO,aAChB,OAAO,UAAU,eAAe,KAAK,MAAM,QAC3C,OAAO,WAAW,WAElB,QAAO;IAGT,MAAM,eAAe,GAAG,SAAgB,QAAQ,MAAM,QAAQ,MAAM;AACpE,gBAAY,UAAU;AACtB,gBAAY;AAEZ,WAAO,eAAe,MAAM,KAAK;KAC/B,cAAc;KACd,MAAM;AACJ,aAAO;;;AAIX,gBAAY;AACZ,WAAO;;GAET,IAAI,GAAG;AACL,aAAS;;;;AAKf,QAAO;;;;;AClDT,SAAgB,aAAa,GAAqB;AAChD,KAAI,OAAO,MAAM,SAAU,QAAO;AAClC,SACG,EAAE,gBAAgB,MAClB,EAAE,WAAW,KAAK,OAClB,EAAE,WAAW,KAAK,KAAK,OACvB,EAAE,SAAS,KAAK,KAAK,KAAK,OAC1B,EAAE,QAAQ,KAAK,KAAK,KAAK,KAAK;;;;;AC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QAAQ,EACpC,gBAAgB,EACd,QAAQ"}
@@ -213,7 +213,7 @@ declare class Store<T> {
213
213
  }>, options?: SubscribeOptions): DisposableCancel;
214
214
  once<S extends T>(condition: (value: T) => value is S, options?: OnceOptions): PromiseWithCancel<S>;
215
215
  once(condition: (value: T) => boolean, options?: OnceOptions): PromiseWithCancel<T>;
216
- once(options?: OnceOptions): PromiseWithCancel<T>;
216
+ once(options?: OnceOptions): PromiseWithCancel<Exclude<T, undefined>>;
217
217
  map<S>(selector: Selector<T, S>, updater?: (value: S) => Update<T>): Store<S>;
218
218
  map<const P>(selector: Constrain<P, SettablePath<T>>): Store<Value$1<T, P>>;
219
219
  /** Add an effect that will be executed when the store becomes active, which means when it has at least one subscriber.
@@ -240,4 +240,4 @@ declare const createStore: typeof create & {
240
240
  };
241
241
  //#endregion
242
242
  export { AnyPath, AsyncConnectionActions, AsyncUpdateFunction, BaseConnectionActions, BoundStoreMethods, Calculate, CalculationActions, Cancel, Connection, ConnectionActions, Constrain, DisposableCancel, Duration, Effect, GetKeys, Join, KeyType, Listener, MaybePromise, Object_, Path, PathAsArray, PathAsString, Selector, SettablePath, SettablePathAsArray, SettablePathAsString, SettableValue, Store, StoreMethods, StoreOptions, StoreOptionsWithMethods, SubscribeOptions, Update, UpdateFrom, UpdateFunction, Use, Value$1 as Value, WildcardPath, WildcardPathAsString, WildcardValue, arrayMethods, createStore, mapMethods, recordMethods, setMethods };
243
- //# sourceMappingURL=store-BJWoRQIs.d.ts.map
243
+ //# sourceMappingURL=store-MBrcOgtz.d.cts.map
@@ -1,5 +1,5 @@
1
1
  const require_chunk = require('./chunk-CUT6urMc.cjs');
2
- const require_store = require('./store-DQcFfgKD.cjs');
2
+ const require_store = require('./store-CdST5wJZ.cjs');
3
3
  const require_propAccess = require('./propAccess-BdLsqViO.cjs');
4
4
  const require_hash = require('./hash-Dv3XlmHn.cjs');
5
5
  const react = require_chunk.__toESM(require("react"));
@@ -372,4 +372,4 @@ Object.defineProperty(exports, 'useStore', {
372
372
  return useStore;
373
373
  }
374
374
  });
375
- //# sourceMappingURL=storeMethods-YDnpa-6-.cjs.map
375
+ //# sourceMappingURL=storeMethods-B_RzvMaV.cjs.map