@expressive/mvc 0.78.0 → 0.79.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/component.d.ts +6 -3
- package/dist/component.js.map +1 -1
- package/dist/field/set.d.ts +14 -0
- package/dist/field/set.js +5 -1
- package/dist/field/set.js.map +1 -1
- package/dist/state.d.ts +10 -1
- package/dist/state.js +7 -5
- package/dist/state.js.map +1 -1
- package/package.json +1 -1
package/dist/component.d.ts
CHANGED
|
@@ -8,12 +8,15 @@ type Acceptable<T> = { [P in keyof T]-?: IfEquals<{ [Q in P]: T[P] }, { -readonl
|
|
|
8
8
|
declare namespace Component {
|
|
9
9
|
/**
|
|
10
10
|
* Host element type produced by `Component.render`. Delegates to the
|
|
11
|
-
* {@link Host} manifest on the jsx-runtime entry;
|
|
12
|
-
* until an adapter augments it with `node`.
|
|
11
|
+
* {@link Host} manifest on the jsx-runtime entry; falls back to `any`
|
|
12
|
+
* until an adapter augments it with `node`. `any` (not `unknown`) so an
|
|
13
|
+
* un-annotated `render` override in a host-agnostic package still emits a
|
|
14
|
+
* JSX-valid return - `any` is assignable to every host's node type, where
|
|
15
|
+
* `unknown` is assignable to none.
|
|
13
16
|
*/
|
|
14
17
|
type Node = Host extends {
|
|
15
18
|
node: infer T;
|
|
16
|
-
} ? T :
|
|
19
|
+
} ? T : any;
|
|
17
20
|
interface BaseProps<T extends Component> {
|
|
18
21
|
/**
|
|
19
22
|
* Callback for newly created instance. Only called once.
|
package/dist/component.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component.js","names":[],"sources":["../src/component.ts"],"sourcesContent":["import { Context } from './context';\nimport { set } from './field/set';\nimport { State, unbind } from './state';\n\nimport type { Host } from './jsx-runtime';\n\nconst PENDING = new WeakMap<object, Component>();\n\n/** Per-class composed content render. */\nconst CHAIN = new WeakMap<Function, Function>();\n\ntype IfEquals<X, Y, A, B> =\n (<T>() => T extends X ? 1 : 2) extends\n (<T>() => T extends Y ? 1 : 2) ? A : B;\n\n/** Keys of T which are settable (excludes get-only accessors and `readonly`). */\ntype Acceptable<T> = {\n [P in keyof T]-?: IfEquals<\n { [Q in P]: T[P] },\n { -readonly [Q in P]: T[P] },\n P, never\n >;\n}[keyof T];\n\ndeclare namespace Component {\n /**\n * Host element type produced by `Component.render`. Delegates to the\n * {@link Host} manifest on the jsx-runtime entry;
|
|
1
|
+
{"version":3,"file":"component.js","names":[],"sources":["../src/component.ts"],"sourcesContent":["import { Context } from './context';\nimport { set } from './field/set';\nimport { State, unbind } from './state';\n\nimport type { Host } from './jsx-runtime';\n\nconst PENDING = new WeakMap<object, Component>();\n\n/** Per-class composed content render. */\nconst CHAIN = new WeakMap<Function, Function>();\n\ntype IfEquals<X, Y, A, B> =\n (<T>() => T extends X ? 1 : 2) extends\n (<T>() => T extends Y ? 1 : 2) ? A : B;\n\n/** Keys of T which are settable (excludes get-only accessors and `readonly`). */\ntype Acceptable<T> = {\n [P in keyof T]-?: IfEquals<\n { [Q in P]: T[P] },\n { -readonly [Q in P]: T[P] },\n P, never\n >;\n}[keyof T];\n\ndeclare namespace Component {\n /**\n * Host element type produced by `Component.render`. Delegates to the\n * {@link Host} manifest on the jsx-runtime entry; falls back to `any`\n * until an adapter augments it with `node`. `any` (not `unknown`) so an\n * un-annotated `render` override in a host-agnostic package still emits a\n * JSX-valid return - `any` is assignable to every host's node type, where\n * `unknown` is assignable to none.\n */\n type Node = Host extends { node: infer T } ? T : any;\n\n interface BaseProps<T extends Component> {\n /**\n * Callback for newly created instance. Only called once.\n *\n * Runs after props apply but **before** the `new()` lifecycle hook - so it\n * may configure state that `new()` then observes. To react to a fully\n * initialized instance instead, use `watch` or an effect.\n */\n is?: (instance: T) => void;\n\n /**\n * Fallback to show when suspended or in error recovery.\n * Pass `false` to opt out of the component's own suspense boundary,\n * letting suspension bubble to an ancestor.\n */\n fallback?: Component.Node;\n }\n\n type StateProps<T extends State> = {\n [K in Exclude<keyof T, keyof Component> & Acceptable<T>]?: T[K];\n };\n\n type RenderProps<T> = [T] extends [(props: infer P) => any]\n ? [keyof NonNullable<P>] extends [never]\n ? { children?: Component.Node }\n : NonNullable<P>\n : { children?: Component.Node };\n\n type Props<T extends Component> =\n & StateProps<T>\n & BaseProps<T>\n & RenderProps<T['render']>;\n}\n\nclass Component extends State {\n /**\n * All JSX attributes passed to this component.\n * Includes state-derived props, render props, and built-in props like `is` and `fallback`.\n *\n * Will incorperate extra props you declare as props parameter in `render` method.\n */\n declare readonly props: Component.Props<this>;\n\n /**\n * Content to display while this component or its children are suspended.\n * Will cover suspense by pending properties in `this.render` as well.\n * Can be set as a class property or overridden via the `fallback` JSX prop.\n *\n * Defaults to null - nothing will be rendered.\n * Set `false` to opt out of having a boundary at all - suspension then\n * bubbles to the nearest ancestor boundary.\n */\n fallback: Component.Node = set(null);\n\n constructor(props?: any, ...rest: any[]) {\n if (props == null) props = {};\n\n const seen = {} as Record<string, undefined>;\n const copy = PENDING.get(props);\n\n if (typeof props == 'object') merge(props);\n\n function merge(props: {}) {\n for (const k in props) seen[k] = undefined;\n return { ...seen, ...props };\n }\n\n super(copy ? [] : [\n props,\n rest.filter((x) => !(x instanceof Context)),\n () => {\n props.is?.(this);\n Object.defineProperty(this, 'props', { enumerable: false });\n PENDING.delete(props);\n }\n ]);\n\n if (copy) return copy;\n\n PENDING.set(props, this);\n\n this.props = props;\n this.set('props', () => {\n this.set(merge(this.props));\n });\n\n Object.defineProperty(this, 'render', {\n writable: true,\n configurable: true,\n value: render(this)\n });\n }\n\n /**\n * Output for this component. Override to define custom JSX.\n *\n * Properties accessed via `this` are reactive and trigger a render when they\n * change, in addition to props. Accepts an optional parameter to receive extra\n * props from JSX, beyond those merged to state properties; declare its shape\n * via `props = {} as { ... }`. Without a parameter (the default below),\n * children pass through.\n *\n * The constructor installs a composed `render` per instance; the bootstrap\n * `type` pass seals this and any override non-configurable, keeping it the\n * content-render seam the chain reads.\n */\n render(props?: {}): Component.Node {\n const { children } = (props || this.props) as { children?: Component.Node };\n return children || null;\n }\n\n /**\n * Called when a child component throws during render.\n * While this is pending, `fallback` is displayed.\n * When resolved, the error boundary resets and `render` is called again.\n *\n * Override to handle errors - set `this.fallback` for error-specific UI,\n * await async recovery, or await user interaction before retrying. If you\n * assign a fallback within catch, it will be reverted after resolved.\n */\n catch?(error: Error): Promise<void> | void;\n}\n\n/**\n * Seal each class's own `render` non-configurable at bootstrap so member\n * classification leaves it unbound - it stays the content-render seam the chain\n * reads (and which adapters like preact detect as the class-component marker).\n */\nComponent.on({\n type(type) {\n const desc = Object.getOwnPropertyDescriptor(type.prototype, 'render');\n\n if (desc && typeof desc.value == 'function')\n Object.defineProperty(type.prototype, 'render', {\n ...desc,\n configurable: false\n });\n }\n});\n\n/**\n * Build (or fetch the cached) composed content render for an instance's class.\n * Walks the prototype chain for content renders strictly below Component - the\n * default render on Component.prototype is excluded and serves as the fallback\n * when a class authors none.\n */\nfunction render(target: Component) {\n const cached = CHAIN.get(target.constructor);\n\n if (cached) return cached;\n\n let render: Function | undefined;\n let proto = target;\n\n while ((proto = Object.getPrototypeOf(proto)) !== Component.prototype) {\n const desc = Object.getOwnPropertyDescriptor(proto, 'render');\n\n if (desc) {\n const layer = unbind(desc.get || desc.value);\n render = render ? compose(layer, render) : layer;\n }\n }\n\n if (!render)\n render = Component.prototype.render;\n\n CHAIN.set(target.constructor, render);\n\n return render;\n}\n\n/** Wrap an outer render so it receives `inner` as a lazy `children` getter. */\nfunction compose(outer: Function, inner: Function): Function {\n return function (this: Component, props?: {}) {\n const self = this;\n return outer.call(self, {\n ...props,\n get children() {\n return inner.call(self, props);\n }\n });\n };\n}\n\nexport { Component };\n"],"mappings":";;;;;AAMA,MAAM,0BAAU,IAAI,SAA4B;;AAGhD,MAAM,wBAAQ,IAAI,SAA6B;AA4D/C,IAAM,YAAN,cAAwB,MAAM;CAoB5B,YAAY,OAAa,GAAG,MAAa;AACvC,MAAI,SAAS,KAAM,SAAQ,EAA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D,MAAI,MAAM;GACR,MAAM,QAAQ,OAAO,KAAK,OAAO,KAAK,MAAM;AAC5C,YAAS,SAAS,QAAQ,OAAO,OAAO,GAAG;;;AAI/C,KAAI,CAAC,OACH,UAAS,UAAU,UAAU;AAE/B,OAAM,IAAI,OAAO,aAAa,OAAO;AAErC,QAAO;;;AAIT,SAAS,QAAQ,OAAiB,OAA2B;AAC3D,QAAO,SAA2B,OAAY;EAC5C,MAAM,OAAO;AACb,SAAO,MAAM,KAAK,MAAM;GACtB,GAAG;GACH,IAAI,WAAW;AACb,WAAO,MAAM,KAAK,MAAM,MAAM;;GAEjC,CAAC"}
|
package/dist/field/set.d.ts
CHANGED
|
@@ -44,6 +44,20 @@ declare function set<T>(factory: () => T | Promise<T>, required: boolean): T | u
|
|
|
44
44
|
* @param onUpdate - Callback run when property is updated.
|
|
45
45
|
*/
|
|
46
46
|
declare function set<T>(factory: () => T | Promise<T>, onUpdate: set.Callback<T>): T;
|
|
47
|
+
/**
|
|
48
|
+
* Define a reactive computed property - the instruction equivalent of a getter.
|
|
49
|
+
*
|
|
50
|
+
* Unlike a zero-arg factory (which runs once and caches), the compute function
|
|
51
|
+
* re-runs whenever any managed property it reads is updated. It receives the
|
|
52
|
+
* instance as both `this` and its first argument, so arrow functions work.
|
|
53
|
+
*
|
|
54
|
+
* Enumerable and read-only, matching a prototype getter. Because it assigns
|
|
55
|
+
* through an instruction rather than a concrete getter, subclasses may refine
|
|
56
|
+
* the property's type with `declare`.
|
|
57
|
+
*
|
|
58
|
+
* @param compute - Function of arity >= 1; receives the instance to derive from.
|
|
59
|
+
*/
|
|
60
|
+
declare function set<T, S = any>(compute: (this: S, self: S) => T): T;
|
|
47
61
|
/**
|
|
48
62
|
* Set a property with a non-function, non-Promise value.
|
|
49
63
|
*
|
package/dist/field/set.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { capture, event, listener } from "../observable.js";
|
|
2
|
-
import { access, update } from "../state.js";
|
|
2
|
+
import { access, compute, update } from "../state.js";
|
|
3
3
|
import { def } from "./def.js";
|
|
4
4
|
|
|
5
5
|
//#region src/field/set.ts
|
|
6
6
|
function set(value, argument) {
|
|
7
7
|
return def((key, subject) => {
|
|
8
8
|
if (value instanceof Promise) throw new TypeError(`Direct promises are not supported in set(${subject}.${key}). Use set(() => promise) instead.`);
|
|
9
|
+
if (typeof value == "function" && value.length > 0) {
|
|
10
|
+
compute.call(subject, value, key);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
9
13
|
const config = {
|
|
10
14
|
enumerable: false,
|
|
11
15
|
set: false
|
package/dist/field/set.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"set.js","names":[],"sources":["../../src/field/set.ts"],"sourcesContent":["import { listener, capture } from '../observable';\nimport { access, event, State, update } from '../state';\nimport { def } from './def';\n\ndeclare namespace set {\n type Callback<T, S = any> = (\n this: S,\n next: T,\n previous: T\n ) => ((next: T) => void) | Promise<any> | void | boolean;\n\n type Factory<T, S = any> = (this: S, property: string) => Promise<T> | T;\n}\n\n/**\n * Set a property as a placeholder, initially `undefined` but required.\n *\n * Property cannot be accessed until it is defined. If accessed while undefined, a hybrid\n * `Promise`/`Error` (aka: [Suspense](https://reactjs.org/docs/concurrent-mode-suspense.html)) will be thrown.\n *\n * Non-enumerable; writable only if `onUpdate` callback is provided.\n *\n * @param value - Starting value (undefined for suspense placeholder).\n * @param onUpdate - Callback run when property is set.\n */\nfunction set<T>(value?: undefined, onUpdate?: set.Callback<T>): T;\n\n/**\n * Set property with an async factory function.\n * If required is not defined, factory runs lazily on first access.\n * If async, or returns a promise, suspense is thrown upon access until resolved.\n *\n * Non-enumerable and read-only.\n *\n * @param factory - Zero-arg async callback to produce property value.\n * @param required - Pass `true` to run factory immediately and require value.\n */\nfunction set<T>(factory: () => T | Promise<T>, required?: true): T;\n\n/**\n * Set property with a lazy factory, no suspense.\n *\n * Non-enumerable and read-only.\n *\n * @param factory - Zero-arg callback to produce property value.\n * @param required - Pass `false` to allow undefined while pending.\n */\nfunction set<T>(\n factory: () => T | Promise<T>,\n required: boolean\n): T | undefined;\n\n/**\n * Set property with a factory and update callback.\n *\n * Non-enumerable but writable via the callback.\n *\n * @param factory - Callback to produce initial value.\n * @param onUpdate - Callback run when property is updated.\n */\nfunction set<T>(factory: () => T | Promise<T>, onUpdate: set.Callback<T>): T;\n\n/**\n * Set a property with a non-function, non-Promise value.\n *\n * Non-enumerable but writable. Unlike plain assignment (`= value`), this\n * property is excluded from snapshots and `ref(this)`.\n *\n * @param value - Starting value for property.\n * @param onUpdate - Optional callback run when property is set.\n */\n// TODO: if onUpdate is not defined, should this have behavior unique to simple assignment?\n// I'm thinking default behavior should be to assign value directly to property, without triggering any additional updates.\n// All this requires is a default callback which throws true, silent updates are already implemented.\nfunction set<T>(\n value: T extends Promise<any> ? never : T,\n onUpdate?: set.Callback<T>\n): T;\n\nfunction set<T = any>(value?: unknown, argument?: unknown): any {\n return def<T>((key, subject) => {\n if (value instanceof Promise)\n throw new TypeError(\n `Direct promises are not supported in set(${subject}.${key}). Use set(() => promise) instead.`\n );\n\n const config: State.Apply = {\n enumerable: false,\n set: false\n };\n\n let computed = false;\n\n // One-shot factory\n if (typeof value == 'function') {\n const factory = value.bind(subject, key)\n computed = true;\n\n function init() {\n let output: unknown;\n\n try {\n output = attempt(factory);\n } catch (err) {\n console.warn(\n `Generating initial value for ${subject}.${key} failed.`\n );\n throw err;\n }\n\n config.get = argument !== false;\n\n function assign(next: any, silent?: boolean) {\n if (typeof argument == 'function') subject[key] = next;\n else update(subject, key, next, silent);\n }\n\n if (output instanceof Promise)\n output.then(assign, (error) => {\n event(subject, key);\n config.get = () => {\n throw error;\n };\n });\n else assign(output, true);\n\n if (argument) return null;\n\n if (output instanceof Promise && argument !== false)\n return access(subject, key, true);\n\n return subject[key];\n }\n\n if (argument) {\n listener(subject, () => {\n init();\n return null;\n });\n } else {\n config.get = init;\n }\n } else if (value !== undefined) {\n config.value = value;\n }\n\n if (typeof argument == 'function') {\n let unset: ((next: T) => void) | undefined;\n\n config.set = function (this: any, value: any, previous: any) {\n capture((release) => {\n const returns = argument.call(this, value, previous);\n\n if (unset) unset(value);\n\n unset = (next: T) => {\n if (typeof returns == 'function') returns(next);\n release();\n };\n });\n };\n } else if (!computed)\n config.set = () => {\n config.get = undefined;\n config.set = undefined;\n };\n\n return config;\n });\n}\n\nfunction attempt(fn: () => any): any {\n function retry(err: unknown) {\n if (err instanceof Promise) return err.then(compute);\n else throw err;\n }\n\n function compute(): any {\n try {\n const output = fn();\n\n return output instanceof Promise ? output.catch(retry) : output;\n } catch (err) {\n return retry(err);\n }\n }\n\n return compute();\n}\n\nexport { set };\n"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"set.js","names":[],"sources":["../../src/field/set.ts"],"sourcesContent":["import { listener, capture } from '../observable';\nimport { access, compute, event, State, update } from '../state';\nimport { def } from './def';\n\ndeclare namespace set {\n type Callback<T, S = any> = (\n this: S,\n next: T,\n previous: T\n ) => ((next: T) => void) | Promise<any> | void | boolean;\n\n type Factory<T, S = any> = (this: S, property: string) => Promise<T> | T;\n}\n\n/**\n * Set a property as a placeholder, initially `undefined` but required.\n *\n * Property cannot be accessed until it is defined. If accessed while undefined, a hybrid\n * `Promise`/`Error` (aka: [Suspense](https://reactjs.org/docs/concurrent-mode-suspense.html)) will be thrown.\n *\n * Non-enumerable; writable only if `onUpdate` callback is provided.\n *\n * @param value - Starting value (undefined for suspense placeholder).\n * @param onUpdate - Callback run when property is set.\n */\nfunction set<T>(value?: undefined, onUpdate?: set.Callback<T>): T;\n\n/**\n * Set property with an async factory function.\n * If required is not defined, factory runs lazily on first access.\n * If async, or returns a promise, suspense is thrown upon access until resolved.\n *\n * Non-enumerable and read-only.\n *\n * @param factory - Zero-arg async callback to produce property value.\n * @param required - Pass `true` to run factory immediately and require value.\n */\nfunction set<T>(factory: () => T | Promise<T>, required?: true): T;\n\n/**\n * Set property with a lazy factory, no suspense.\n *\n * Non-enumerable and read-only.\n *\n * @param factory - Zero-arg callback to produce property value.\n * @param required - Pass `false` to allow undefined while pending.\n */\nfunction set<T>(\n factory: () => T | Promise<T>,\n required: boolean\n): T | undefined;\n\n/**\n * Set property with a factory and update callback.\n *\n * Non-enumerable but writable via the callback.\n *\n * @param factory - Callback to produce initial value.\n * @param onUpdate - Callback run when property is updated.\n */\nfunction set<T>(factory: () => T | Promise<T>, onUpdate: set.Callback<T>): T;\n\n/**\n * Define a reactive computed property - the instruction equivalent of a getter.\n *\n * Unlike a zero-arg factory (which runs once and caches), the compute function\n * re-runs whenever any managed property it reads is updated. It receives the\n * instance as both `this` and its first argument, so arrow functions work.\n *\n * Enumerable and read-only, matching a prototype getter. Because it assigns\n * through an instruction rather than a concrete getter, subclasses may refine\n * the property's type with `declare`.\n *\n * @param compute - Function of arity >= 1; receives the instance to derive from.\n */\nfunction set<T, S = any>(compute: (this: S, self: S) => T): T;\n\n/**\n * Set a property with a non-function, non-Promise value.\n *\n * Non-enumerable but writable. Unlike plain assignment (`= value`), this\n * property is excluded from snapshots and `ref(this)`.\n *\n * @param value - Starting value for property.\n * @param onUpdate - Optional callback run when property is set.\n */\n// TODO: if onUpdate is not defined, should this have behavior unique to simple assignment?\n// I'm thinking default behavior should be to assign value directly to property, without triggering any additional updates.\n// All this requires is a default callback which throws true, silent updates are already implemented.\nfunction set<T>(\n value: T extends Promise<any> ? never : T,\n onUpdate?: set.Callback<T>\n): T;\n\nfunction set<T = any>(value?: unknown, argument?: unknown): any {\n return def<T>((key, subject) => {\n if (value instanceof Promise)\n throw new TypeError(\n `Direct promises are not supported in set(${subject}.${key}). Use set(() => promise) instead.`\n );\n\n if (typeof value == 'function' && value.length > 0) {\n compute.call(subject, value as () => unknown, key);\n return;\n }\n\n const config: State.Apply = {\n enumerable: false,\n set: false\n };\n\n let computed = false;\n\n // One-shot factory\n if (typeof value == 'function') {\n const factory = value.bind(subject, key)\n computed = true;\n\n function init() {\n let output: unknown;\n\n try {\n output = attempt(factory);\n } catch (err) {\n console.warn(\n `Generating initial value for ${subject}.${key} failed.`\n );\n throw err;\n }\n\n config.get = argument !== false;\n\n function assign(next: any, silent?: boolean) {\n if (typeof argument == 'function') subject[key] = next;\n else update(subject, key, next, silent);\n }\n\n if (output instanceof Promise)\n output.then(assign, (error) => {\n event(subject, key);\n config.get = () => {\n throw error;\n };\n });\n else assign(output, true);\n\n if (argument) return null;\n\n if (output instanceof Promise && argument !== false)\n return access(subject, key, true);\n\n return subject[key];\n }\n\n if (argument) {\n listener(subject, () => {\n init();\n return null;\n });\n } else {\n config.get = init;\n }\n } else if (value !== undefined) {\n config.value = value;\n }\n\n if (typeof argument == 'function') {\n let unset: ((next: T) => void) | undefined;\n\n config.set = function (this: any, value: any, previous: any) {\n capture((release) => {\n const returns = argument.call(this, value, previous);\n\n if (unset) unset(value);\n\n unset = (next: T) => {\n if (typeof returns == 'function') returns(next);\n release();\n };\n });\n };\n } else if (!computed)\n config.set = () => {\n config.get = undefined;\n config.set = undefined;\n };\n\n return config;\n });\n}\n\nfunction attempt(fn: () => any): any {\n function retry(err: unknown) {\n if (err instanceof Promise) return err.then(compute);\n else throw err;\n }\n\n function compute(): any {\n try {\n const output = fn();\n\n return output instanceof Promise ? output.catch(retry) : output;\n } catch (err) {\n return retry(err);\n }\n }\n\n return compute();\n}\n\nexport { set };\n"],"mappings":";;;;;AA8FA,SAAS,IAAa,OAAiB,UAAyB;AAC9D,QAAO,KAAQ,KAAK,YAAY;AAC9B,MAAI,iBAAiB,QACnB,OAAM,IAAI,UACR,4CAA4C,QAAQ,GAAG,IAAI,oCAC5D;AAEH,MAAI,OAAO,SAAS,cAAc,MAAM,SAAS,GAAG;AAClD,WAAQ,KAAK,SAAS,OAAwB,IAAI;AAClD;;EAGF,MAAM,SAAsB;GAC1B,YAAY;GACZ,KAAK;GACN;EAED,IAAI,WAAW;AAGf,MAAI,OAAO,SAAS,YAAY;GAC9B,MAAM,UAAU,MAAM,KAAK,SAAS,IAAI;AACxC,cA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Z,UAAO,MAAM,IAAI;;;AAIrB,QAAO,SAAS"}
|
package/dist/state.d.ts
CHANGED
|
@@ -277,6 +277,15 @@ declare abstract class State {
|
|
|
277
277
|
*/
|
|
278
278
|
static on<T extends State>(this: State.Extends<T>, handler: State.Init<T> | State.On<T>): () => boolean;
|
|
279
279
|
}
|
|
280
|
+
/**
|
|
281
|
+
* Install a reactive computed property on a state instance, derived from a prototype
|
|
282
|
+
* getter or an arity-bearing `set` factory.
|
|
283
|
+
*
|
|
284
|
+
* The getter is invoked with the tracking proxy as both `this` and its first argument;
|
|
285
|
+
* reads of managed properties through it create subscriptions. Result is cached and
|
|
286
|
+
* emits a keyed event when stale.
|
|
287
|
+
*/
|
|
288
|
+
declare function compute(this: State, getter: (self: any) => unknown, key: string): void;
|
|
280
289
|
/**
|
|
281
290
|
* Define or update a managed property using a descriptor config.
|
|
282
291
|
* If the property already is managed, config will only accept value.
|
|
@@ -307,5 +316,5 @@ declare function unbind<T extends Function>(fn?: T): T | undefined;
|
|
|
307
316
|
*/
|
|
308
317
|
declare function parent(child: State, value?: State | null): State | null | undefined;
|
|
309
318
|
//#endregion
|
|
310
|
-
export { STORE, State, access, apply, event, parent, uid, unbind, update };
|
|
319
|
+
export { STORE, State, access, apply, compute, event, parent, uid, unbind, update };
|
|
311
320
|
//# sourceMappingURL=state.d.ts.map
|
package/dist/state.js
CHANGED
|
@@ -211,10 +211,12 @@ function bootstrap(T) {
|
|
|
211
211
|
};
|
|
212
212
|
}
|
|
213
213
|
/**
|
|
214
|
-
* Install a reactive computed property on a state instance, derived from a prototype
|
|
214
|
+
* Install a reactive computed property on a state instance, derived from a prototype
|
|
215
|
+
* getter or an arity-bearing `set` factory.
|
|
215
216
|
*
|
|
216
|
-
* The getter is invoked with the tracking proxy as `this
|
|
217
|
-
* through it create subscriptions. Result is cached and
|
|
217
|
+
* The getter is invoked with the tracking proxy as both `this` and its first argument;
|
|
218
|
+
* reads of managed properties through it create subscriptions. Result is cached and
|
|
219
|
+
* emits a keyed event when stale.
|
|
218
220
|
*/
|
|
219
221
|
function compute(getter, key) {
|
|
220
222
|
const store = STORE.get(this);
|
|
@@ -236,7 +238,7 @@ function compute(getter, key) {
|
|
|
236
238
|
const run = (initial) => {
|
|
237
239
|
let next;
|
|
238
240
|
try {
|
|
239
|
-
next = getter.call(proxy);
|
|
241
|
+
next = getter.call(proxy, proxy);
|
|
240
242
|
} catch (err) {
|
|
241
243
|
console.warn(`An exception was thrown while ${initial ? "initializing" : "refreshing"} ${this}.${key}.`);
|
|
242
244
|
if (initial) throw err;
|
|
@@ -420,5 +422,5 @@ function parent(child, value) {
|
|
|
420
422
|
}
|
|
421
423
|
|
|
422
424
|
//#endregion
|
|
423
|
-
export { STORE, State, access, apply, event, parent, uid, unbind, update };
|
|
425
|
+
export { STORE, State, access, apply, compute, event, parent, uid, unbind, update };
|
|
424
426
|
//# sourceMappingURL=state.js.map
|
package/dist/state.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.js","names":[],"sources":["../src/state.ts"],"sourcesContent":["import { Context } from './context';\nimport {\n event,\n listener,\n Observer,\n observer,\n pending,\n touch,\n watch\n} from './observable';\n\nconst define = Object.defineProperty;\n\n/** Register for all active states via string identifiers (usually unique). */\nconst ID = new WeakMap<State, string>();\n\n/** Internal state assigned to states. */\nconst STORE = new WeakMap<State, Record<string | number | symbol, unknown>>();\n\n/** External lifecycle listeners for any given State class. */\nconst SETUP = new WeakMap<State.Extends, Set<State.Init<any> | State.On<any>>>();\n\n/** Parent-child relationships. */\nconst PARENT = new WeakMap<State, State | null>();\n\n/** Reference bound instance methods, or their getter, to real one. */\nconst UNBIND = new WeakMap<any, any>();\n\n/** List of methods defined by a given type. */\nconst METHODS = new WeakMap<Function, Map<string, (value: any) => void>>();\n\n/** List of reactive getters defined by a given type. */\nconst GETTERS = new WeakMap<Function, Map<string, () => unknown>>();\n\n/** Stale flags for compute closures awaiting refresh on next access. */\nconst STALE = new WeakSet<() => void>();\n\ndeclare namespace State {\n /** Any type of State, using own class constructor as its identifier. */\n type Extends<T extends State = State> = (abstract new (...args: any[]) => T) &\n typeof State;\n\n /** A State constructor which may be instanciated. */\n type Type<T extends State = State> = (new (...args: State.Args<T>) => T) &\n Omit<typeof State, never>;\n\n /** State constructor arguments */\n type Args<T extends State = any> = (Args<T> | Init<T> | Assign<T> | void)[];\n\n /**\n * State constructor callback - runs during activation, in argument order,\n * before the `new()` lifecycle hook (so it may configure state `new()`\n * will observe). Returned function will run when state is destroyed.\n */\n type Init<T extends State = State> = (\n this: T,\n thisArg: T\n ) => Promise<void> | (() => void) | Args<T> | Assign<T> | void;\n\n /**\n * Lifecycle handlers for `State.on`, keyed by when they run. A bare `Init`\n * function passed to `on` is sugar for `{ before }`.\n */\n interface On<T extends State = State> {\n /**\n * Per-class setup, run once when the class is first bootstrapped - before\n * its members are classified and bound. Receives the class, so a handler\n * may inspect or reshape the prototype first. A handler registered on a\n * base class runs for each subclass too.\n */\n type?(type: State.Extends<T>): void;\n\n /**\n * Per-instance setup, run in the `prepare` phase before `observe` and the\n * `new()` hook. Equivalent to passing a bare function to `on`. May return a\n * cleanup, constructor args, or an assign overlay.\n */\n before?(this: T, thisArg: T): void | (() => void) | Promise<void> | Args<T> | Assign<T>;\n\n /**\n * Per-instance setup, run at the `new()` slot - after own values are\n * observed and constructor args applied. May return a cleanup function.\n */\n after?(this: T, self: T): void | (() => void);\n }\n\n /** Object overlay to override values and methods on a state. */\n type Assign<T> = Record<string, unknown> & {\n [K in Field<T>]?: T[K] extends (...args: infer A) => infer R\n ? (this: T, ...args: A) => R\n : T[K];\n };\n\n /** Subset of `keyof T` not defined by base State. **/\n type Field<T> = Exclude<keyof T, keyof State>;\n\n /** Any valid key for state, including but not limited to Field<T>. */\n type Event<T = State> = Field<T> | number | symbol | (string & {});\n\n /** Any event signal dispatched to listeners, including lifecycle meta events. */\n type Signal<T = State> = Event<T> | true | false | null;\n\n /** Export/Import compatible value for a given property in a State. */\n type Export<R> = R extends State\n ? Values<R>\n : R extends { get(): infer T }\n ? T\n : R;\n\n /**\n * Values from current state of given state.\n * Differs from `Values` as values here will drill\n * into \"real\" values held by exotics like ref.Object.\n */\n type Values<T> = { [P in Field<T>]: Export<T[P]> };\n\n /** Object comperable to data found in T. */\n type Partial<T> = { [P in Field<T>]?: Export<T[P]> };\n\n /** Value for a property applied by a state. */\n type Value<T extends State, K extends State.Event<T>> = K extends keyof T\n ? Export<T[K]>\n : unknown;\n\n type Setter<T> = (value: T, previous: T) => T | void;\n\n /** Descriptor config for a managed property. */\n type Apply<T = any> = {\n value?: T;\n get?: ((source: State) => T) | boolean;\n set?: Setter<T> | boolean;\n enumerable?: boolean;\n // destroy?: () => void;\n };\n\n /** Descriptor config for set() overload - enforces type when key is a known field. */\n type Define<T, K> = K extends Field<T> ? Apply<T[K] | Export<T[K]>> : Apply;\n\n type OnEvent<T extends State> = (\n this: T,\n key: Signal<T>,\n source: T\n ) => void | (() => void) | null;\n\n /** Exotic value, where actual value is contained within. */\n type Ref<T = any> = {\n (next: T): void;\n current: T | null;\n };\n\n /**\n * A callback function which is subscribed to parent and updates when accessed properties change.\n *\n * @param current - Current state of this state. This is a proxy which detects properties which\n * where accessed, and thus depended upon to stay current.\n *\n * @param update - Set of properties which have changed, and events fired, since last update.\n *\n * @returns A callback function which will be called when this effect is stale.\n */\n type Effect<T> = (\n this: T,\n current: T,\n update: readonly State.Event<T>[] | undefined\n ) => EffectCallback | Promise<void> | null | void;\n\n /**\n * A callback function returned by effect. Will be called when effect is stale.\n *\n * @param update - `true` if update is pending, `false` effect has been cancelled, `null` if state is destroyed.\n */\n type EffectCallback = (update: boolean | null) => void;\n\n /**\n * A list of keys updated, or events fired, since last update.\n * This may be awaited to get full list (same array) when update is settled.\n */\n type Updated<T extends State> = readonly Event<T>[] &\n PromiseLike<readonly Event<T>[]>;\n}\n\nabstract class State {\n /**\n * Loopback to instance of this state. This is useful when in a subscribed context,\n * to keep write access to `this` after a destructure. You can use it to read variables silently as well.\n **/\n declare is: this;\n\n constructor(...args: State.Args) {\n define(this, 'is', { value: this });\n init(this, args, this.new);\n }\n\n /**\n * Optional lifecycle hook called during State initialization.\n * Can return a cleanup function to run when state is destroyed.\n *\n * It is recommended you protect this method.\n */\n protected new?(): void | (() => void);\n\n /**\n * Pull current values from state. Flattens all states and exotic values recursively.\n *\n * @returns Object with all values from this state.\n **/\n get(): State.Values<this>;\n\n /**\n * Run a function to run automatically when accessed values change.\n *\n * @param effect Function to run, and whenever accessed values change.\n * If effect returns a function, it will be called when a change occurs (syncronously),\n * effect is cancelled, or parent state is destroyed.\n * @returns Function to cancel listener.\n */\n get(effect: State.Effect<this>): () => void;\n\n /**\n * Get value of a property. Will fetch underlying value from exotic values like ref.Object.\n *\n * Any value which implements `get()` (with no arguments) will be treated as such.\n *\n * @param key - Property to get value of.\n * @param required - If true, will throw an error if property is not available.\n * @returns Value of property.\n */\n get<T extends State.Event<this>>(\n key: T,\n required?: boolean\n ): State.Value<this, T>;\n\n /**\n * Check if state is destroyed.\n *\n * @param status - `null` to check if state is destroyed.\n * @returns `true` if state is destroyed, `false` otherwise.\n */\n get(status: null): boolean;\n\n /**\n * Callback when state is to be destroyed.\n *\n * @param callback - Function to call when state is destroyed.\n * @returns Function to cancel listener.\n */\n get(status: null, callback: () => void): () => void;\n\n /** Fetch State of type from context. Throws if not found. */\n get<T extends State>(type: State.Type<T>, required?: true): T;\n\n /** Fetch a State from context. Undefined if not found. */\n get<T extends State>(type: State.Type<T>, required: boolean): T | undefined;\n\n /**\n * Subscribe to State becoming available in context.\n *\n * Will search both up and downstream by default.\n * Normally you can ignore this because State you expect is rarely both.\n *\n * Specify downstream if you only want to watch for State in children, which can be useful if you expect multiple of the same State in different branches of the tree.\n *\n * @param type - Type of State to watch for.\n * @param callback - Function to call when State is found. Will be called immediately if State is already available.\n * @param downstream - If true, will only watch for State in children, if false will only for parents.\n * @returns Function to cancel listener.\n */\n get<T extends State>(\n type: State.Type<T>,\n callback: Context.Expect<T>,\n downstream?: boolean\n ): () => void;\n\n get(\n arg1?: State.Effect<this> | State.Type | string | null,\n arg2?: boolean | Context.Expect | (() => void),\n arg3?: boolean\n ) {\n const self = this.is;\n\n if (arg1 === undefined) return values(self);\n if (State.is(arg1)) return Context.get(self).get(arg1, arg2, arg3, self);\n if (typeof arg1 == 'function') return watch(self, unbind(arg1));\n if (typeof arg2 == 'function') return callback(self, arg2, arg1);\n if (arg1 === null) return observer(self) === null;\n return access(self, arg1, arg2);\n }\n\n /**\n * Get update in progress.\n *\n * @returns Promise which resolves object with updated values, `undefined` if there no update is pending.\n **/\n set(): State.Updated<this>;\n\n /**\n * Merge argument with current state, updating one or more properties at once.\n * Properties which are not managed by this state will be ignored.\n *\n * @param assign - Object with properties to update.\n * @param silent - If true, listeners will not be notified. If state is destroyed, will squash update without throwing.\n * @returns Array of keys updated, syncronously contains keys updated immediately and may be resolved (to itself) when all updates are settled.\n */\n set(assign?: State.Assign<this>, silent?: boolean): State.Updated<this>;\n\n /**\n * Call a function when update occurs.\n *\n * Given function is called for every assignment (which changes value) or explicit `set`.\n *\n * To run logic on final value only, callback may return a function. The same\n * function for one or more events will be called only once when update is settled.\n *\n * Return `null` from callback to stop listening.\n *\n * @param callback - Function to call when update occurs.\n * @returns Function to remove listener. Will return `true` if removed, `false` if inactive already.\n */\n set(callback: State.OnEvent<this>): () => boolean;\n\n /**\n * Push an update. This will not change the value of associated property.\n *\n * Useful where a property value internally has changed, but the object is the same.\n * For example: An array has pushed a new value, or a nested property is updated.\n *\n * You can also use this to dispatch arbitrary events.\n * Symbols are recommended as non-property events, however you can use any string.\n * If doing so, be sure to avoid collisions using property names. An easy way to do this is\n * to prefix an event with \"!\" and/or use dash-case. e.g. `set(\"!event\")` or `set(\"my-event\")`.\n *\n * @param key - Property or event to dispatch.\n * @returns Promise resolves an array of keys updated.\n */\n set(key: State.Event<this>): State.Updated<this>;\n\n /**\n * Declare an end to updates. This event is final and will freeze state.\n * This event can be watched for as well, to run cleanup logic and internally will remove all listeners.\n *\n * @param status - `null` to end updates.\n */\n set(status: null): void;\n\n /**\n * Register a callback for a specific property or event.\n *\n * Callback receives the key, current value, and source instance.\n *\n * @param event - Property or event to watch. If `null`, will callback on destroy.\n * @param callback - Function to call when event occurs.\n * @returns Function to remove listener.\n */\n set<K extends State.Event<this>>(\n event: K | null,\n callback: State.OnEvent<this>\n ): () => boolean;\n\n /**\n * Define or update a managed property using a descriptor config.\n * If the property already is managed, config will only accept value.\n * If the property does not exist, it will be created and made reactive.\n *\n * @param key - Property to define or update.\n * @param config - Descriptor config with value, get, set, enumerable, and/or destroy.\n * @returns Promise resolves an array of keys updated.\n */\n set<K extends State.Event<this>>(\n key: K,\n config: State.Define<this, K>\n ): State.Updated<this>;\n\n set(\n arg1?: State.OnEvent<this> | State.Assign<this> | State.Event<this> | null,\n arg2?: unknown\n ) {\n const self = this.is;\n\n if (typeof arg1 == 'function')\n return listener(self, (key) => {\n if (\n typeof key == 'string' ||\n typeof key == 'number' ||\n typeof key == 'symbol'\n )\n return arg1.call(self, key, self);\n });\n\n if (typeof arg2 == 'function')\n return callback(self, arg2, arg1 as State.Signal);\n\n if (arg1 && typeof arg1 == 'object') assign(self, arg1, arg2 === true);\n else if (arg2) apply(self, arg1 as string, arg2);\n else event(self, arg1);\n\n return pending(self) as State.Updated<this>;\n }\n\n /**\n * Iterate over managed properties in this instance of State.\n * Yeilds the key and current value for each property.\n */\n [Symbol.iterator](): Iterator<[string, unknown]> {\n return Object.entries(STORE.get(this.is)!)[Symbol.iterator]();\n }\n\n /**\n * Create and activate a new instance of this state.\n *\n * **Important** - Unlike `new this(...)` - this method also activates state.\n *\n * @param args - arguments sent to constructor\n */\n static new<T extends State>(this: State.Type<T>, ...args: State.Args<T>): T {\n const instance = new this(...args);\n event(instance);\n return instance;\n }\n\n /**\n * Static equivalent of `x instanceof this`.\n * Determines if provided class is a subtype of this one.\n * If so, language server will make available all static\n * methods and properties of this class.\n */\n static is<T extends State.Extends>(this: T, maybe: unknown): maybe is T {\n return (\n maybe === this ||\n (typeof maybe == 'function' && maybe.prototype instanceof this)\n );\n }\n\n /**\n * Register a lifecycle handler for this State and its subclasses.\n *\n * A bare function is per-instance setup run in the `prepare` phase (sugar for\n * `{ before }`); if it returns a function, that runs when the instance is\n * destroyed. Pass a {@link State.On} object to hook by cadence - `type`\n * (per-class, at bootstrap), `before` (per-instance, before `new()`), and\n * `after` (per-instance, at the `new()` slot).\n *\n * @returns Function to remove the handler.\n */\n static on<T extends State>(\n this: State.Extends<T>,\n handler: State.Init<T> | State.On<T>\n ) {\n let setup = SETUP.get(this);\n\n if (!setup) SETUP.set(this, (setup = new Set()));\n\n setup.add(handler);\n\n return () => setup.delete(handler);\n }\n}\n\ndefine(State.prototype, 'toString', {\n value() {\n return ID.get(this.is);\n }\n});\n\ndefine(State, 'toString', {\n value() {\n return this.name;\n }\n});\n\n/** Register a user OnEvent callback, preserving `this` and `source`. */\nfunction callback<T extends State>(\n self: T,\n cb: Function,\n select?: Observer.Signal | Set<Observer.Signal>\n) {\n return listener(self, (key) => cb.call(self, key, self), select);\n}\n\n/**\n * Apply state arguemnts, run callbacks and observe properties.\n * Accumulate and handle cleanup events.\n **/\nfunction init(state: State, ...args: State.Args) {\n const T = state.constructor as State.Extends;\n\n if (T === State) throw new Error('Cannot create base State.');\n\n const { before, after } = bootstrap(T);\n\n ID.set(state, `${T}-${uid()}`);\n STORE.set(state, {});\n\n function observe() {\n for (const key in state) {\n const desc = Object.getOwnPropertyDescriptor(state, key)!;\n if ('value' in desc) apply(state, key, desc, true);\n }\n }\n\n function register() {\n if (Context.get(state) === Context.root) return Context.root.add(state);\n }\n\n listener(state, () => {\n parent(state, null);\n\n const queue = [...before, observe, ...args, ...after, register];\n\n for (let i = 0; i < queue.length; i++) {\n const arg = queue[i];\n const out = typeof arg == 'function' ? arg.call(state, state) : arg;\n\n if (out instanceof Promise)\n out.catch((err) => {\n console.error(`Async error in constructor for ${state}:`);\n console.error(err);\n });\n else if (Array.isArray(out)) queue.splice(i + 1, 0, ...out);\n else if (typeof out == 'function') listener(state, out, null);\n else if (typeof out == 'object') assign(state, out, true);\n }\n\n return null;\n });\n}\n\n/**\n * Apply instructions and inherited event listeners. Ensure class metadata is ready.\n *\n * @param T - State class to bootstrap.\n * @return Array of init functions to run on instance, in order of class hierarchy.\n */\nfunction bootstrap(T: State.Extends) {\n const chain = [] as State.Extends[];\n const before = new Set<State.Init>();\n const after = new Set<State.Init>();\n const onType = new Set<NonNullable<State.On['type']>>();\n let keys = new Map<string, (value: any) => void>();\n let getters = new Map<string, () => unknown>();\n\n do {\n chain.unshift(T);\n T = Object.getPrototypeOf(T);\n } while (T.name);\n\n for (const type of chain) {\n for (const handler of SETUP.get(type) || [])\n if (typeof handler == 'function') before.add(handler);\n else {\n if (handler.before) before.add(handler.before);\n if (handler.after) after.add(handler.after);\n if (handler.type) onType.add(handler.type);\n }\n\n if (type === State) continue;\n\n if (METHODS.has(type)) {\n keys = METHODS.get(type)!;\n getters = GETTERS.get(type)!;\n continue;\n }\n\n for (const setupType of onType) setupType(type);\n\n METHODS.set(type, (keys = new Map(keys)));\n GETTERS.set(type, (getters = new Map(getters)));\n\n for (const [key, desc] of Object.entries(\n Object.getOwnPropertyDescriptors(type.prototype)\n )) {\n if (key == 'constructor' || !desc.configurable) continue;\n\n if (typeof desc.get == 'function') {\n if (desc.configurable && typeof desc.set != 'function')\n getters.set(key, desc.get);\n\n continue;\n }\n\n const { value } = desc;\n\n if (typeof value !== 'function') continue;\n\n function bind(this: State, original?: Function) {\n const { is } = this;\n\n if (is.hasOwnProperty(key) && !original) return value as Function;\n\n const fn = original || value;\n const bound = fn.bind(is);\n\n UNBIND.set(bound, fn);\n define(is, key, { value: bound, writable: true, configurable: true });\n\n return bound;\n }\n\n UNBIND.set(bind, value);\n\n keys.set(key, bind);\n define(type.prototype, key, { get: bind, set: bind });\n }\n }\n\n if (getters.size)\n before.add((self) => getters.forEach(compute, self));\n\n return { before, after };\n}\n\n/**\n * Install a reactive computed property on a state instance, derived from a prototype getter.\n *\n * The getter is invoked with the tracking proxy as `this`; reads of managed properties\n * through it create subscriptions. Result is cached and emits a keyed event when stale.\n */\nfunction compute(this: State, getter: () => unknown, key: string) {\n const store = STORE.get(this)!;\n let reset: (() => void) | undefined;\n let isAsync: boolean;\n let proxy: any;\n\n const connect = () => {\n reset = watch(\n this,\n (current) => {\n proxy = current;\n\n if (!(key in store) || STALE.delete(run)) run(!reset);\n\n return (didUpdate) => {\n if (didUpdate) {\n STALE.add(run);\n event(this, key, true);\n }\n };\n },\n false\n );\n };\n\n const run = (initial?: boolean) => {\n let next: unknown;\n\n try {\n next = getter.call(proxy);\n } catch (err) {\n console.warn(\n `An exception was thrown while ${initial ? 'initializing' : 'refreshing'\n } ${this}.${key}.`\n );\n\n if (initial) throw err;\n\n console.error(err);\n }\n\n update(this, key, next, !isAsync);\n };\n\n apply(\n this,\n key,\n {\n enumerable: true,\n set: false,\n get: () => {\n if (!proxy) {\n if (observer(this) === null) return store[key];\n\n connect();\n isAsync = true;\n }\n\n if (STALE.delete(run)) run();\n\n return access(this, key, !proxy);\n }\n },\n true\n );\n}\n\n/**\n * Define or update a managed property using a descriptor config.\n * If the property already is managed, config will only accept value.\n * If the property does not exist, it will be created and made reactive.\n *\n * @param state - State to apply property to.\n * @param key - Property to define or update.\n * @param config - Descriptor config with value, get, set, enumerable, and/or destroy.\n * @param silent - If an update does occur, listeners will not be refreshed automatically.\n */\nfunction apply(\n state: State,\n key: string,\n config: State.Apply,\n silent?: boolean\n) {\n const desc = Object.getOwnPropertyDescriptor(state, key);\n\n if (desc && 'get' in desc) {\n if (Object.keys(config).some((k) => k != 'value'))\n throw new Error(`Property ${key} on ${state} is already defined.`);\n if ('value' in config) update(state, key, config.value, silent);\n return;\n }\n\n const adopt = config.value instanceof State && child(state);\n\n function set(value: unknown, silent?: boolean) {\n if (!update(state, key, value, silent)) return;\n if (adopt) adopt(value);\n }\n\n define(state, key, {\n configurable: true,\n enumerable: config.enumerable !== false,\n get(this: State) {\n const value =\n typeof config.get == 'function'\n ? config.get(this)\n : access(state, key, config.get);\n\n return touch(this, key, value);\n },\n set(next: any, silent?: boolean) {\n if (config.set === false)\n throw new Error(`${state}.${String(key)} is read-only.`);\n\n if (typeof config.set == 'function')\n try {\n const output = config.set(next, STORE.get(state)![key]);\n if (output !== undefined) next = output;\n } catch (err: unknown) {\n if (err === false) return;\n if (err === true) {\n set(next, true);\n return;\n }\n throw err;\n }\n\n set(next, silent);\n }\n });\n\n if ('value' in config) set(config.value, silent);\n}\n\nfunction child(state: State) {\n let cleanup: (() => void) | undefined;\n const ctx = Context.get(state);\n\n function reset() {\n if (cleanup) cleanup();\n cleanup = undefined;\n }\n\n listener(state, reset, null);\n\n return (value: unknown) => {\n reset();\n\n if (!(value instanceof State)) return;\n\n const remove = ctx.add(value);\n\n if (parent(value) === undefined) {\n parent(value, state);\n cleanup = () => {\n cancel();\n remove();\n event(value, null);\n };\n const cancel = listener(state, cleanup, null);\n } else {\n cleanup = remove;\n }\n\n event(value);\n };\n}\n\n/** Currently accumulating export. Stores real values of placeholder properties such as ref() or child states. */\nlet EXPORT: Map<any, any> | undefined;\n\nfunction values<T extends State>(state: T): State.Values<T> {\n const values = {} as any;\n let notRecursive;\n\n if (!EXPORT) {\n notRecursive = true;\n EXPORT = new Map([[state, values]]);\n }\n\n for (let [key, value] of state) {\n if (EXPORT.has(value)) value = EXPORT.get(value);\n else if (\n value &&\n typeof value == 'object' &&\n 'get' in value &&\n typeof value.get === 'function'\n )\n EXPORT.set(value, (value = value.get()));\n\n values[key] = value;\n }\n\n if (notRecursive) EXPORT = undefined;\n\n return Object.freeze(values);\n}\n\nfunction access(state: State, property: string, required?: boolean) {\n const store = STORE.get(state)!;\n\n if (property in store || required === false) {\n const value = store[property];\n\n if (value !== undefined || !required) return value;\n }\n\n if (METHODS.get(state.constructor)!.has(property))\n return unbind((state as any)[property]);\n\n if (observer(state) === null) return undefined;\n\n const error = new Error(`${state}.${property} is not yet available.`);\n const promise = new Promise<any>((resolve, reject) => {\n listener(state, (key) => {\n if (key === property) {\n resolve(store[key]);\n return null;\n }\n\n if (key === null) {\n reject(new Error(`${state} is destroyed.`));\n }\n });\n });\n\n throw Object.assign(promise, {\n toString: () => String(error),\n name: 'Suspense',\n message: error.message,\n stack: error.stack\n });\n}\n\nfunction assign(state: State, data: State.Assign<State>, silent?: boolean) {\n if (!silent) event(state);\n\n const methods = METHODS.get(state.constructor)!;\n\n for (const key in data) {\n const bind = methods.get(key);\n\n if (bind) bind.call(state, data[key]);\n else if (key in state && key !== 'is') {\n const desc = Object.getOwnPropertyDescriptor(state, key)!;\n const set = desc && (desc.set as (value: any, silent?: boolean) => void);\n\n if (set) {\n set.call(state, data[key], silent);\n } else {\n (state as any)[key] = data[key];\n }\n }\n }\n}\n\n/**\n * Update a property on a state instance and notify listeners.\n *\n * This is used internally to update properties, but can also be used to update properties which are not managed by state, or to update values without triggering setters.\n *\n * If `silent` is true, the update will not dispatch events and will return `false` instead of throwing if state is destroyed.\n */\nfunction update<T>(\n state: State,\n key: State.Event<T>,\n value: T,\n silent?: boolean\n) {\n if (observer(state) === null) {\n if (silent) return false;\n throw new Error(\n `Tried to update ${state}.${String(key)} but state is destroyed.`\n );\n }\n\n const store = STORE.get(state)!;\n\n if (key in store && value === store[key]) return false;\n\n store[key] = value;\n\n if (!silent) event(state, key);\n\n return true;\n}\n\n/** Random alphanumberic of length 6; always starts with a letter. */\nfunction uid() {\n return (0.278 + Math.random() * 0.722)\n .toString(36)\n .substring(2, 8)\n .toUpperCase();\n}\n\nfunction unbind<T extends Function>(fn: T): T;\nfunction unbind<T extends Function>(fn?: T): T | undefined;\nfunction unbind(fn?: Function) {\n return UNBIND.get(fn) || fn;\n}\n\n/**\n * Get or set a parent on given state. May only be assigned once; ignores new value.\n * Returns parent of child, or `undefined` if not assigned yet.\n */\nfunction parent(child: State, value?: State | null) {\n if (arguments.length > 1 && !PARENT.has(child)) PARENT.set(child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EACd,CAAC;;AAGJ,SAAS,OAAO,OAAc,MAA2B,QAAkB;AACzE,KAAI,CAAC,OAAQ,OAAM,MAAM;CAEzB,MAAM,UAAU,QAAQ,IAAI,MAAM,YAAY;AAE9C,MAAK,MAAM,OAAO,MAAM;EACtB,MAAM,OAAO,QAAQ,IAAI,IAAI;AAE7B,MAAI,KAAM,MAAK,KAAK,OAAO,KAAK,KAAK;WAC5B,OAAO,SAAS,QAAQ,MAAM;GACrC,MAAM,OAAO,OAAO,yBAAyB,OAAO,IAAI;GACxD,MAAM,MAAM,QAAS,KAAK;AAE1B,OAAI,IACF,KAAI,KAAK,OAAO,KAAK,MAAM,OAAO;OAElC,CAAC,MAAc,OAAO,KAAK;;;;;;;;;;;AAanC,SAAS,OACP,OACA,KACA,OACA,QACA;AACA,KAAI,SAAS,MAAM,KAAK,MAAM;AAC5B,MAAI,OAAQ,QAAO;AACnB,QAAM,IAAI,MACR,mBAAmB,MAAM,GAAG,OAAO,IAAI,CAAC,0BACzC;;CAGH,MAAM,QAAQ,MAAM,IAAI,MAAM;AAE9B,KAAI,OAAO,SAAS,UAAU,MAAM,KAAM,QAAO;AAEjD,OAAM,OAAO;AAEb,KAAI,CAAC,OAAQ,OAAM,OAAO,IAAI;AAE9B,QAAO;;;AAIT,SAAS,MAAM;AACb,SAAQ,OAAQ,KAAK,QAAQ,GAAG,MAC7B,SAAS,GAAG,CACZ,UAAU,GAAG,EAAE,CACf,aAAa;;AAKlB,SAAS,OAAO,IAAe;AAC7B,QAAO,OAAO,IAAI,GAAG,IAAI;;;;;;AAO3B,SAAS,OAAO,OAAc,OAAsB;AAClD,KAAI,UAAU,SAAS,KAAK,CAAC,OAAO,IAAI,MAAM,CAAE,QAAO,IAAI,OAAO,MAAO;AACzE,QAAO,OAAO,IAAI,MAAM"}
|
|
1
|
+
{"version":3,"file":"state.js","names":[],"sources":["../src/state.ts"],"sourcesContent":["import { Context } from './context';\nimport {\n event,\n listener,\n Observer,\n observer,\n pending,\n touch,\n watch\n} from './observable';\n\nconst define = Object.defineProperty;\n\n/** Register for all active states via string identifiers (usually unique). */\nconst ID = new WeakMap<State, string>();\n\n/** Internal state assigned to states. */\nconst STORE = new WeakMap<State, Record<string | number | symbol, unknown>>();\n\n/** External lifecycle listeners for any given State class. */\nconst SETUP = new WeakMap<State.Extends, Set<State.Init<any> | State.On<any>>>();\n\n/** Parent-child relationships. */\nconst PARENT = new WeakMap<State, State | null>();\n\n/** Reference bound instance methods, or their getter, to real one. */\nconst UNBIND = new WeakMap<any, any>();\n\n/** List of methods defined by a given type. */\nconst METHODS = new WeakMap<Function, Map<string, (value: any) => void>>();\n\n/** List of reactive getters defined by a given type. */\nconst GETTERS = new WeakMap<Function, Map<string, () => unknown>>();\n\n/** Stale flags for compute closures awaiting refresh on next access. */\nconst STALE = new WeakSet<() => void>();\n\ndeclare namespace State {\n /** Any type of State, using own class constructor as its identifier. */\n type Extends<T extends State = State> = (abstract new (...args: any[]) => T) &\n typeof State;\n\n /** A State constructor which may be instanciated. */\n type Type<T extends State = State> = (new (...args: State.Args<T>) => T) &\n Omit<typeof State, never>;\n\n /** State constructor arguments */\n type Args<T extends State = any> = (Args<T> | Init<T> | Assign<T> | void)[];\n\n /**\n * State constructor callback - runs during activation, in argument order,\n * before the `new()` lifecycle hook (so it may configure state `new()`\n * will observe). Returned function will run when state is destroyed.\n */\n type Init<T extends State = State> = (\n this: T,\n thisArg: T\n ) => Promise<void> | (() => void) | Args<T> | Assign<T> | void;\n\n /**\n * Lifecycle handlers for `State.on`, keyed by when they run. A bare `Init`\n * function passed to `on` is sugar for `{ before }`.\n */\n interface On<T extends State = State> {\n /**\n * Per-class setup, run once when the class is first bootstrapped - before\n * its members are classified and bound. Receives the class, so a handler\n * may inspect or reshape the prototype first. A handler registered on a\n * base class runs for each subclass too.\n */\n type?(type: State.Extends<T>): void;\n\n /**\n * Per-instance setup, run in the `prepare` phase before `observe` and the\n * `new()` hook. Equivalent to passing a bare function to `on`. May return a\n * cleanup, constructor args, or an assign overlay.\n */\n before?(this: T, thisArg: T): void | (() => void) | Promise<void> | Args<T> | Assign<T>;\n\n /**\n * Per-instance setup, run at the `new()` slot - after own values are\n * observed and constructor args applied. May return a cleanup function.\n */\n after?(this: T, self: T): void | (() => void);\n }\n\n /** Object overlay to override values and methods on a state. */\n type Assign<T> = Record<string, unknown> & {\n [K in Field<T>]?: T[K] extends (...args: infer A) => infer R\n ? (this: T, ...args: A) => R\n : T[K];\n };\n\n /** Subset of `keyof T` not defined by base State. **/\n type Field<T> = Exclude<keyof T, keyof State>;\n\n /** Any valid key for state, including but not limited to Field<T>. */\n type Event<T = State> = Field<T> | number | symbol | (string & {});\n\n /** Any event signal dispatched to listeners, including lifecycle meta events. */\n type Signal<T = State> = Event<T> | true | false | null;\n\n /** Export/Import compatible value for a given property in a State. */\n type Export<R> = R extends State\n ? Values<R>\n : R extends { get(): infer T }\n ? T\n : R;\n\n /**\n * Values from current state of given state.\n * Differs from `Values` as values here will drill\n * into \"real\" values held by exotics like ref.Object.\n */\n type Values<T> = { [P in Field<T>]: Export<T[P]> };\n\n /** Object comperable to data found in T. */\n type Partial<T> = { [P in Field<T>]?: Export<T[P]> };\n\n /** Value for a property applied by a state. */\n type Value<T extends State, K extends State.Event<T>> = K extends keyof T\n ? Export<T[K]>\n : unknown;\n\n type Setter<T> = (value: T, previous: T) => T | void;\n\n /** Descriptor config for a managed property. */\n type Apply<T = any> = {\n value?: T;\n get?: ((source: State) => T) | boolean;\n set?: Setter<T> | boolean;\n enumerable?: boolean;\n // destroy?: () => void;\n };\n\n /** Descriptor config for set() overload - enforces type when key is a known field. */\n type Define<T, K> = K extends Field<T> ? Apply<T[K] | Export<T[K]>> : Apply;\n\n type OnEvent<T extends State> = (\n this: T,\n key: Signal<T>,\n source: T\n ) => void | (() => void) | null;\n\n /** Exotic value, where actual value is contained within. */\n type Ref<T = any> = {\n (next: T): void;\n current: T | null;\n };\n\n /**\n * A callback function which is subscribed to parent and updates when accessed properties change.\n *\n * @param current - Current state of this state. This is a proxy which detects properties which\n * where accessed, and thus depended upon to stay current.\n *\n * @param update - Set of properties which have changed, and events fired, since last update.\n *\n * @returns A callback function which will be called when this effect is stale.\n */\n type Effect<T> = (\n this: T,\n current: T,\n update: readonly State.Event<T>[] | undefined\n ) => EffectCallback | Promise<void> | null | void;\n\n /**\n * A callback function returned by effect. Will be called when effect is stale.\n *\n * @param update - `true` if update is pending, `false` effect has been cancelled, `null` if state is destroyed.\n */\n type EffectCallback = (update: boolean | null) => void;\n\n /**\n * A list of keys updated, or events fired, since last update.\n * This may be awaited to get full list (same array) when update is settled.\n */\n type Updated<T extends State> = readonly Event<T>[] &\n PromiseLike<readonly Event<T>[]>;\n}\n\nabstract class State {\n /**\n * Loopback to instance of this state. This is useful when in a subscribed context,\n * to keep write access to `this` after a destructure. You can use it to read variables silently as well.\n **/\n declare is: this;\n\n constructor(...args: State.Args) {\n define(this, 'is', { value: this });\n init(this, args, this.new);\n }\n\n /**\n * Optional lifecycle hook called during State initialization.\n * Can return a cleanup function to run when state is destroyed.\n *\n * It is recommended you protect this method.\n */\n protected new?(): void | (() => void);\n\n /**\n * Pull current values from state. Flattens all states and exotic values recursively.\n *\n * @returns Object with all values from this state.\n **/\n get(): State.Values<this>;\n\n /**\n * Run a function to run automatically when accessed values change.\n *\n * @param effect Function to run, and whenever accessed values change.\n * If effect returns a function, it will be called when a change occurs (syncronously),\n * effect is cancelled, or parent state is destroyed.\n * @returns Function to cancel listener.\n */\n get(effect: State.Effect<this>): () => void;\n\n /**\n * Get value of a property. Will fetch underlying value from exotic values like ref.Object.\n *\n * Any value which implements `get()` (with no arguments) will be treated as such.\n *\n * @param key - Property to get value of.\n * @param required - If true, will throw an error if property is not available.\n * @returns Value of property.\n */\n get<T extends State.Event<this>>(\n key: T,\n required?: boolean\n ): State.Value<this, T>;\n\n /**\n * Check if state is destroyed.\n *\n * @param status - `null` to check if state is destroyed.\n * @returns `true` if state is destroyed, `false` otherwise.\n */\n get(status: null): boolean;\n\n /**\n * Callback when state is to be destroyed.\n *\n * @param callback - Function to call when state is destroyed.\n * @returns Function to cancel listener.\n */\n get(status: null, callback: () => void): () => void;\n\n /** Fetch State of type from context. Throws if not found. */\n get<T extends State>(type: State.Type<T>, required?: true): T;\n\n /** Fetch a State from context. Undefined if not found. */\n get<T extends State>(type: State.Type<T>, required: boolean): T | undefined;\n\n /**\n * Subscribe to State becoming available in context.\n *\n * Will search both up and downstream by default.\n * Normally you can ignore this because State you expect is rarely both.\n *\n * Specify downstream if you only want to watch for State in children, which can be useful if you expect multiple of the same State in different branches of the tree.\n *\n * @param type - Type of State to watch for.\n * @param callback - Function to call when State is found. Will be called immediately if State is already available.\n * @param downstream - If true, will only watch for State in children, if false will only for parents.\n * @returns Function to cancel listener.\n */\n get<T extends State>(\n type: State.Type<T>,\n callback: Context.Expect<T>,\n downstream?: boolean\n ): () => void;\n\n get(\n arg1?: State.Effect<this> | State.Type | string | null,\n arg2?: boolean | Context.Expect | (() => void),\n arg3?: boolean\n ) {\n const self = this.is;\n\n if (arg1 === undefined) return values(self);\n if (State.is(arg1)) return Context.get(self).get(arg1, arg2, arg3, self);\n if (typeof arg1 == 'function') return watch(self, unbind(arg1));\n if (typeof arg2 == 'function') return callback(self, arg2, arg1);\n if (arg1 === null) return observer(self) === null;\n return access(self, arg1, arg2);\n }\n\n /**\n * Get update in progress.\n *\n * @returns Promise which resolves object with updated values, `undefined` if there no update is pending.\n **/\n set(): State.Updated<this>;\n\n /**\n * Merge argument with current state, updating one or more properties at once.\n * Properties which are not managed by this state will be ignored.\n *\n * @param assign - Object with properties to update.\n * @param silent - If true, listeners will not be notified. If state is destroyed, will squash update without throwing.\n * @returns Array of keys updated, syncronously contains keys updated immediately and may be resolved (to itself) when all updates are settled.\n */\n set(assign?: State.Assign<this>, silent?: boolean): State.Updated<this>;\n\n /**\n * Call a function when update occurs.\n *\n * Given function is called for every assignment (which changes value) or explicit `set`.\n *\n * To run logic on final value only, callback may return a function. The same\n * function for one or more events will be called only once when update is settled.\n *\n * Return `null` from callback to stop listening.\n *\n * @param callback - Function to call when update occurs.\n * @returns Function to remove listener. Will return `true` if removed, `false` if inactive already.\n */\n set(callback: State.OnEvent<this>): () => boolean;\n\n /**\n * Push an update. This will not change the value of associated property.\n *\n * Useful where a property value internally has changed, but the object is the same.\n * For example: An array has pushed a new value, or a nested property is updated.\n *\n * You can also use this to dispatch arbitrary events.\n * Symbols are recommended as non-property events, however you can use any string.\n * If doing so, be sure to avoid collisions using property names. An easy way to do this is\n * to prefix an event with \"!\" and/or use dash-case. e.g. `set(\"!event\")` or `set(\"my-event\")`.\n *\n * @param key - Property or event to dispatch.\n * @returns Promise resolves an array of keys updated.\n */\n set(key: State.Event<this>): State.Updated<this>;\n\n /**\n * Declare an end to updates. This event is final and will freeze state.\n * This event can be watched for as well, to run cleanup logic and internally will remove all listeners.\n *\n * @param status - `null` to end updates.\n */\n set(status: null): void;\n\n /**\n * Register a callback for a specific property or event.\n *\n * Callback receives the key, current value, and source instance.\n *\n * @param event - Property or event to watch. If `null`, will callback on destroy.\n * @param callback - Function to call when event occurs.\n * @returns Function to remove listener.\n */\n set<K extends State.Event<this>>(\n event: K | null,\n callback: State.OnEvent<this>\n ): () => boolean;\n\n /**\n * Define or update a managed property using a descriptor config.\n * If the property already is managed, config will only accept value.\n * If the property does not exist, it will be created and made reactive.\n *\n * @param key - Property to define or update.\n * @param config - Descriptor config with value, get, set, enumerable, and/or destroy.\n * @returns Promise resolves an array of keys updated.\n */\n set<K extends State.Event<this>>(\n key: K,\n config: State.Define<this, K>\n ): State.Updated<this>;\n\n set(\n arg1?: State.OnEvent<this> | State.Assign<this> | State.Event<this> | null,\n arg2?: unknown\n ) {\n const self = this.is;\n\n if (typeof arg1 == 'function')\n return listener(self, (key) => {\n if (\n typeof key == 'string' ||\n typeof key == 'number' ||\n typeof key == 'symbol'\n )\n return arg1.call(self, key, self);\n });\n\n if (typeof arg2 == 'function')\n return callback(self, arg2, arg1 as State.Signal);\n\n if (arg1 && typeof arg1 == 'object') assign(self, arg1, arg2 === true);\n else if (arg2) apply(self, arg1 as string, arg2);\n else event(self, arg1);\n\n return pending(self) as State.Updated<this>;\n }\n\n /**\n * Iterate over managed properties in this instance of State.\n * Yeilds the key and current value for each property.\n */\n [Symbol.iterator](): Iterator<[string, unknown]> {\n return Object.entries(STORE.get(this.is)!)[Symbol.iterator]();\n }\n\n /**\n * Create and activate a new instance of this state.\n *\n * **Important** - Unlike `new this(...)` - this method also activates state.\n *\n * @param args - arguments sent to constructor\n */\n static new<T extends State>(this: State.Type<T>, ...args: State.Args<T>): T {\n const instance = new this(...args);\n event(instance);\n return instance;\n }\n\n /**\n * Static equivalent of `x instanceof this`.\n * Determines if provided class is a subtype of this one.\n * If so, language server will make available all static\n * methods and properties of this class.\n */\n static is<T extends State.Extends>(this: T, maybe: unknown): maybe is T {\n return (\n maybe === this ||\n (typeof maybe == 'function' && maybe.prototype instanceof this)\n );\n }\n\n /**\n * Register a lifecycle handler for this State and its subclasses.\n *\n * A bare function is per-instance setup run in the `prepare` phase (sugar for\n * `{ before }`); if it returns a function, that runs when the instance is\n * destroyed. Pass a {@link State.On} object to hook by cadence - `type`\n * (per-class, at bootstrap), `before` (per-instance, before `new()`), and\n * `after` (per-instance, at the `new()` slot).\n *\n * @returns Function to remove the handler.\n */\n static on<T extends State>(\n this: State.Extends<T>,\n handler: State.Init<T> | State.On<T>\n ) {\n let setup = SETUP.get(this);\n\n if (!setup) SETUP.set(this, (setup = new Set()));\n\n setup.add(handler);\n\n return () => setup.delete(handler);\n }\n}\n\ndefine(State.prototype, 'toString', {\n value() {\n return ID.get(this.is);\n }\n});\n\ndefine(State, 'toString', {\n value() {\n return this.name;\n }\n});\n\n/** Register a user OnEvent callback, preserving `this` and `source`. */\nfunction callback<T extends State>(\n self: T,\n cb: Function,\n select?: Observer.Signal | Set<Observer.Signal>\n) {\n return listener(self, (key) => cb.call(self, key, self), select);\n}\n\n/**\n * Apply state arguemnts, run callbacks and observe properties.\n * Accumulate and handle cleanup events.\n **/\nfunction init(state: State, ...args: State.Args) {\n const T = state.constructor as State.Extends;\n\n if (T === State) throw new Error('Cannot create base State.');\n\n const { before, after } = bootstrap(T);\n\n ID.set(state, `${T}-${uid()}`);\n STORE.set(state, {});\n\n function observe() {\n for (const key in state) {\n const desc = Object.getOwnPropertyDescriptor(state, key)!;\n if ('value' in desc) apply(state, key, desc, true);\n }\n }\n\n function register() {\n if (Context.get(state) === Context.root) return Context.root.add(state);\n }\n\n listener(state, () => {\n parent(state, null);\n\n const queue = [...before, observe, ...args, ...after, register];\n\n for (let i = 0; i < queue.length; i++) {\n const arg = queue[i];\n const out = typeof arg == 'function' ? arg.call(state, state) : arg;\n\n if (out instanceof Promise)\n out.catch((err) => {\n console.error(`Async error in constructor for ${state}:`);\n console.error(err);\n });\n else if (Array.isArray(out)) queue.splice(i + 1, 0, ...out);\n else if (typeof out == 'function') listener(state, out, null);\n else if (typeof out == 'object') assign(state, out, true);\n }\n\n return null;\n });\n}\n\n/**\n * Apply instructions and inherited event listeners. Ensure class metadata is ready.\n *\n * @param T - State class to bootstrap.\n * @return Array of init functions to run on instance, in order of class hierarchy.\n */\nfunction bootstrap(T: State.Extends) {\n const chain = [] as State.Extends[];\n const before = new Set<State.Init>();\n const after = new Set<State.Init>();\n const onType = new Set<NonNullable<State.On['type']>>();\n let keys = new Map<string, (value: any) => void>();\n let getters = new Map<string, () => unknown>();\n\n do {\n chain.unshift(T);\n T = Object.getPrototypeOf(T);\n } while (T.name);\n\n for (const type of chain) {\n for (const handler of SETUP.get(type) || [])\n if (typeof handler == 'function') before.add(handler);\n else {\n if (handler.before) before.add(handler.before);\n if (handler.after) after.add(handler.after);\n if (handler.type) onType.add(handler.type);\n }\n\n if (type === State) continue;\n\n if (METHODS.has(type)) {\n keys = METHODS.get(type)!;\n getters = GETTERS.get(type)!;\n continue;\n }\n\n for (const setupType of onType) setupType(type);\n\n METHODS.set(type, (keys = new Map(keys)));\n GETTERS.set(type, (getters = new Map(getters)));\n\n for (const [key, desc] of Object.entries(\n Object.getOwnPropertyDescriptors(type.prototype)\n )) {\n if (key == 'constructor' || !desc.configurable) continue;\n\n if (typeof desc.get == 'function') {\n if (desc.configurable && typeof desc.set != 'function')\n getters.set(key, desc.get);\n\n continue;\n }\n\n const { value } = desc;\n\n if (typeof value !== 'function') continue;\n\n function bind(this: State, original?: Function) {\n const { is } = this;\n\n if (is.hasOwnProperty(key) && !original) return value as Function;\n\n const fn = original || value;\n const bound = fn.bind(is);\n\n UNBIND.set(bound, fn);\n define(is, key, { value: bound, writable: true, configurable: true });\n\n return bound;\n }\n\n UNBIND.set(bind, value);\n\n keys.set(key, bind);\n define(type.prototype, key, { get: bind, set: bind });\n }\n }\n\n if (getters.size)\n before.add((self) => getters.forEach(compute, self));\n\n return { before, after };\n}\n\n/**\n * Install a reactive computed property on a state instance, derived from a prototype\n * getter or an arity-bearing `set` factory.\n *\n * The getter is invoked with the tracking proxy as both `this` and its first argument;\n * reads of managed properties through it create subscriptions. Result is cached and\n * emits a keyed event when stale.\n */\nfunction compute(this: State, getter: (self: any) => unknown, key: string) {\n const store = STORE.get(this)!;\n let reset: (() => void) | undefined;\n let isAsync: boolean;\n let proxy: any;\n\n const connect = () => {\n reset = watch(\n this,\n (current) => {\n proxy = current;\n\n if (!(key in store) || STALE.delete(run)) run(!reset);\n\n return (didUpdate) => {\n if (didUpdate) {\n STALE.add(run);\n event(this, key, true);\n }\n };\n },\n false\n );\n };\n\n const run = (initial?: boolean) => {\n let next: unknown;\n\n try {\n next = getter.call(proxy, proxy);\n } catch (err) {\n console.warn(\n `An exception was thrown while ${initial ? 'initializing' : 'refreshing'\n } ${this}.${key}.`\n );\n\n if (initial) throw err;\n\n console.error(err);\n }\n\n update(this, key, next, !isAsync);\n };\n\n apply(\n this,\n key,\n {\n enumerable: true,\n set: false,\n get: () => {\n if (!proxy) {\n if (observer(this) === null) return store[key];\n\n connect();\n isAsync = true;\n }\n\n if (STALE.delete(run)) run();\n\n return access(this, key, !proxy);\n }\n },\n true\n );\n}\n\n/**\n * Define or update a managed property using a descriptor config.\n * If the property already is managed, config will only accept value.\n * If the property does not exist, it will be created and made reactive.\n *\n * @param state - State to apply property to.\n * @param key - Property to define or update.\n * @param config - Descriptor config with value, get, set, enumerable, and/or destroy.\n * @param silent - If an update does occur, listeners will not be refreshed automatically.\n */\nfunction apply(\n state: State,\n key: string,\n config: State.Apply,\n silent?: boolean\n) {\n const desc = Object.getOwnPropertyDescriptor(state, key);\n\n if (desc && 'get' in desc) {\n if (Object.keys(config).some((k) => k != 'value'))\n throw new Error(`Property ${key} on ${state} is already defined.`);\n if ('value' in config) update(state, key, config.value, silent);\n return;\n }\n\n const adopt = config.value instanceof State && child(state);\n\n function set(value: unknown, silent?: boolean) {\n if (!update(state, key, value, silent)) return;\n if (adopt) adopt(value);\n }\n\n define(state, key, {\n configurable: true,\n enumerable: config.enumerable !== false,\n get(this: State) {\n const value =\n typeof config.get == 'function'\n ? config.get(this)\n : access(state, key, config.get);\n\n return touch(this, key, value);\n },\n set(next: any, silent?: boolean) {\n if (config.set === false)\n throw new Error(`${state}.${String(key)} is read-only.`);\n\n if (typeof config.set == 'function')\n try {\n const output = config.set(next, STORE.get(state)![key]);\n if (output !== undefined) next = output;\n } catch (err: unknown) {\n if (err === false) return;\n if (err === true) {\n set(next, true);\n return;\n }\n throw err;\n }\n\n set(next, silent);\n }\n });\n\n if ('value' in config) set(config.value, silent);\n}\n\nfunction child(state: State) {\n let cleanup: (() => void) | undefined;\n const ctx = Context.get(state);\n\n function reset() {\n if (cleanup) cleanup();\n cleanup = undefined;\n }\n\n listener(state, reset, null);\n\n return (value: unknown) => {\n reset();\n\n if (!(value instanceof State)) return;\n\n const remove = ctx.add(value);\n\n if (parent(value) === undefined) {\n parent(value, state);\n cleanup = () => {\n cancel();\n remove();\n event(value, null);\n };\n const cancel = listener(state, cleanup, null);\n } else {\n cleanup = remove;\n }\n\n event(value);\n };\n}\n\n/** Currently accumulating export. Stores real values of placeholder properties such as ref() or child states. */\nlet EXPORT: Map<any, any> | undefined;\n\nfunction values<T extends State>(state: T): State.Values<T> {\n const values = {} as any;\n let notRecursive;\n\n if (!EXPORT) {\n notRecursive = true;\n EXPORT = new Map([[state, values]]);\n }\n\n for (let [key, value] of state) {\n if (EXPORT.has(value)) value = EXPORT.get(value);\n else if (\n value &&\n typeof value == 'object' &&\n 'get' in value &&\n typeof value.get === 'function'\n )\n EXPORT.set(value, (value = value.get()));\n\n values[key] = value;\n }\n\n if (notRecursive) EXPORT = undefined;\n\n return Object.freeze(values);\n}\n\nfunction access(state: State, property: string, required?: boolean) {\n const store = STORE.get(state)!;\n\n if (property in store || required === false) {\n const value = store[property];\n\n if (value !== undefined || !required) return value;\n }\n\n if (METHODS.get(state.constructor)!.has(property))\n return unbind((state as any)[property]);\n\n if (observer(state) === null) return undefined;\n\n const error = new Error(`${state}.${property} is not yet available.`);\n const promise = new Promise<any>((resolve, reject) => {\n listener(state, (key) => {\n if (key === property) {\n resolve(store[key]);\n return null;\n }\n\n if (key === null) {\n reject(new Error(`${state} is destroyed.`));\n }\n });\n });\n\n throw Object.assign(promise, {\n toString: () => String(error),\n name: 'Suspense',\n message: error.message,\n stack: error.stack\n });\n}\n\nfunction assign(state: State, data: State.Assign<State>, silent?: boolean) {\n if (!silent) event(state);\n\n const methods = METHODS.get(state.constructor)!;\n\n for (const key in data) {\n const bind = methods.get(key);\n\n if (bind) bind.call(state, data[key]);\n else if (key in state && key !== 'is') {\n const desc = Object.getOwnPropertyDescriptor(state, key)!;\n const set = desc && (desc.set as (value: any, silent?: boolean) => void);\n\n if (set) {\n set.call(state, data[key], silent);\n } else {\n (state as any)[key] = data[key];\n }\n }\n }\n}\n\n/**\n * Update a property on a state instance and notify listeners.\n *\n * This is used internally to update properties, but can also be used to update properties which are not managed by state, or to update values without triggering setters.\n *\n * If `silent` is true, the update will not dispatch events and will return `false` instead of throwing if state is destroyed.\n */\nfunction update<T>(\n state: State,\n key: State.Event<T>,\n value: T,\n silent?: boolean\n) {\n if (observer(state) === null) {\n if (silent) return false;\n throw new Error(\n `Tried to update ${state}.${String(key)} but state is destroyed.`\n );\n }\n\n const store = STORE.get(state)!;\n\n if (key in store && value === store[key]) return false;\n\n store[key] = value;\n\n if (!silent) event(state, key);\n\n return true;\n}\n\n/** Random alphanumberic of length 6; always starts with a letter. */\nfunction uid() {\n return (0.278 + Math.random() * 0.722)\n .toString(36)\n .substring(2, 8)\n .toUpperCase();\n}\n\nfunction unbind<T extends Function>(fn: T): T;\nfunction unbind<T extends Function>(fn?: T): T | undefined;\nfunction unbind(fn?: Function) {\n return UNBIND.get(fn) || fn;\n}\n\n/**\n * Get or set a parent on given state. May only be assigned once; ignores new value.\n * Returns parent of child, or `undefined` if not assigned yet.\n */\nfunction parent(child: State, value?: State | null) {\n if (arguments.length > 1 && !PARENT.has(child)) PARENT.set(child, value!);\n return PARENT.get(child);\n}\n\nexport { event, unbind, State, parent, STORE, uid, access, update, apply, compute };\n"],"mappings":";;;;AAWA,MAAM,SAAS,OAAO;;AAGtB,MAAM,qBAAK,IAAI,SAAwB;;AAGvC,MAAM,wBAAQ,IAAI,SAA2D;;AAG7E,MAAM,wBAAQ,IAAI,SAA8D;;AAGhF,MAAM,yBAAS,IAAI,SAA8B;;AAGjD,MAAM,yBAAS,IAAI,SAAmB;;AAGtC,MAAM,0BAAU,IAAI,SAAsD;;AAG1E,MAAM,0BAAU,IAAI,SAA+C;;AAGnE,MAAM,wBAAQ,IAAI,SAAqB;AAkJvC,IAAe,QAAf,MAAe,MAAM;CAOnB,YAAY,GAAG,MAAkB;AAC/B,SAAO,MAAM,MAAM,EAAE,OAAO,MAAM,CAAC;AACnC,OAAK,MAAM,MAAM,KAAK,IAAI;;CAmF5B,IACE,MACA,MACA,MACA;EACA,MAAM,OAAO,KAAK;AAElB,MAAI,SAAS,OAAW,QAAO,OAAO,KAAK;AAC3C,MAAI,MAAM,GAAG,KAAK,CAAE,QAAO,QAAQ,IAA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