@reckona/mreact-reactive-core 0.0.187 → 0.0.189

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/selector.js CHANGED
@@ -4,7 +4,7 @@ import { untrack } from "./untrack.js";
4
4
  /** Creates keyed boolean cells that update only for the previous and next selected keys. */
5
5
  export function selector(source, options) {
6
6
  const usesDefaultEquality = options?.equals === undefined;
7
- const equals = options?.equals ?? (defaultSelectorEquality);
7
+ const equals = options?.equals ?? defaultSelectorEquality;
8
8
  const sources = new Map();
9
9
  let current = untrack(() => source.get());
10
10
  const disposeSourceEffect = effect(() => {
@@ -1 +1 @@
1
- {"version":3,"file":"selector.js","sourceRoot":"","sources":["../src/selector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAuBvC,4FAA4F;AAC5F,MAAM,UAAU,QAAQ,CACtB,MAA4B,EAC5B,OAAiE;IAEjE,MAAM,mBAAmB,GAAG,OAAO,EAAE,MAAM,KAAK,SAAS,CAAC;IAC1D,MAAM,MAAM,GAAG,OAAO,EAAE,MAAM,KAAI,uBAAqC,CAAA,CAAC;IACxE,MAAM,OAAO,GAAG,IAAI,GAAG,EAA8B,CAAC;IACtD,IAAI,OAAO,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC;IAE1C,MAAM,mBAAmB,GAAG,MAAM,CAAC,GAAG,EAAE;QACtC,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,EAAE,CAAC;QAE1B,IAAI,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE,CAAC;YAC7B,OAAO;QACT,CAAC;QAED,MAAM,QAAQ,GAAG,OAAO,CAAC;QACzB,OAA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BAAqB;IAC5B,IAAI,IAAI,CAAC,WAAW,KAAK,IAAI,IAAI,IAAI,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;QAC9D,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC9B,CAAC;AACH,CAAC;AAED,SAAS,oBAAoB,CAC3B,cAAgD,EAChD,QAAiB;IAEjB,IACE,cAAc,KAAK,SAAS;QAC5B,cAAc,CAAC,QAAQ,KAAK,QAAQ,EACpC,CAAC;QACD,OAAO;IACT,CAAC;IAED,cAAc,CAAC,QAAQ,GAAG,QAAQ,CAAC;IACnC,MAAM,SAAS,GAAG,cAAc,CAAC,SAAS,CAAC;IAE3C,IAAI,OAAO,SAAS,KAAK,UAAU,EAAE,CAAC;QACpC,SAAS,CAAC,QAAQ,CAAC,CAAC;IACtB,CAAC;SAAM,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;QACnC,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;YACjC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACrB,CAAC;IACH,CAAC;IAED,iBAAiB,CAAC,cAAc,CAAC,CAAC;AACpC,CAAC","sourcesContent":["import { effect } from \"./effect.js\";\nimport { notifySubscribers, trackSource } from \"./tracking.js\";\nimport { untrack } from \"./untrack.js\";\nimport type { Source } from \"./state.js\";\nimport type { ReadonlyCell } from \"./types.js\";\n\n/** Equality function used by selector keys. */\nexport type SelectorEquality<TValue, TKey> = (value: TValue, key: TKey) => boolean;\ntype SelectorCallback = (selected: boolean) => void;\ntype SelectorCallbacks = SelectorCallback | Set<SelectorCallback>;\n\n/** A keyed boolean selector with an explicit disposer for the source subscription. */\nexport interface Selector<TValue, TKey = TValue> {\n (key: TKey): boolean;\n subscribe(key: TKey, listener: (selected: boolean) => void): () => void;\n dispose(): void;\n}\n\ninterface SelectorSource<TKey> extends Source {\n callbacks?: SelectorCallbacks | undefined;\n key: TKey;\n owner: Map<TKey, SelectorSource<TKey>>;\n selected: boolean;\n}\n\n/** Creates keyed boolean cells that update only for the previous and next selected keys. */\nexport function selector<TValue, TKey = TValue>(\n source: ReadonlyCell<TValue>,\n options?: { equals?: SelectorEquality<TValue, TKey> | undefined },\n): Selector<TValue, TKey> {\n const usesDefaultEquality = options?.equals === undefined;\n const equals = options?.equals ?? defaultSelectorEquality<TValue, TKey>;\n const sources = new Map<TKey, SelectorSource<TKey>>();\n let current = untrack(() => source.get());\n\n const disposeSourceEffect = effect(() => {\n const next = source.get();\n\n if (Object.is(current, next)) {\n return;\n }\n\n const previous = current;\n current = next;\n\n if (usesDefaultEquality) {\n updateSelectorSource(sources.get(previous as unknown as TKey), false);\n updateSelectorSource(sources.get(next as unknown as TKey), true);\n return;\n }\n\n for (const selectorSource of sources.values()) {\n const nextSelected =\n equals(next, selectorSource.key) === true;\n\n updateSelectorSource(selectorSource, nextSelected);\n }\n });\n\n function getOrCreateSelectorSource(key: TKey): SelectorSource<TKey> {\n let selectorSource = sources.get(key);\n\n if (selectorSource === undefined) {\n selectorSource = {\n key,\n onNoSubscribers: cleanupSelectorSource,\n owner: sources,\n selected: equals(current, key) === true,\n subscribers: null,\n };\n sources.set(key, selectorSource);\n }\n\n return selectorSource;\n }\n\n const select = ((key: TKey): boolean => {\n const selectorSource = getOrCreateSelectorSource(key);\n\n trackSource(selectorSource);\n return selectorSource.selected;\n }) as Selector<TValue, TKey>;\n\n select.subscribe = (key, listener) => {\n const selectorSource = getOrCreateSelectorSource(key);\n const callbacks = selectorSource.callbacks;\n\n if (callbacks === undefined) {\n selectorSource.callbacks = listener;\n } else if (typeof callbacks === \"function\") {\n if (callbacks !== listener) {\n selectorSource.callbacks = new Set([callbacks, listener]);\n }\n } else {\n callbacks.add(listener);\n }\n\n return () => {\n const currentCallbacks = selectorSource.callbacks;\n\n if (currentCallbacks === listener) {\n selectorSource.callbacks = undefined;\n } else if (currentCallbacks instanceof Set) {\n currentCallbacks.delete(listener);\n\n if (currentCallbacks.size === 0) {\n selectorSource.callbacks = undefined;\n }\n }\n\n cleanupSelectorSource.call(selectorSource);\n };\n };\n\n select.dispose = () => {\n disposeSourceEffect();\n sources.clear();\n };\n\n return select;\n}\n\nfunction defaultSelectorEquality<TValue, TKey>(value: TValue, key: TKey): boolean {\n return Object.is(value, key);\n}\n\nfunction cleanupSelectorSource<TKey>(this: SelectorSource<TKey>): void {\n if (this.subscribers === null && this.callbacks === undefined) {\n this.owner.delete(this.key);\n }\n}\n\nfunction updateSelectorSource<TKey>(\n selectorSource: SelectorSource<TKey> | undefined,\n selected: boolean,\n): void {\n if (\n selectorSource === undefined ||\n selectorSource.selected === selected\n ) {\n return;\n }\n\n selectorSource.selected = selected;\n const callbacks = selectorSource.callbacks;\n\n if (typeof callbacks === \"function\") {\n callbacks(selected);\n } else if (callbacks !== undefined) {\n for (const callback of callbacks) {\n callback(selected);\n }\n }\n\n notifySubscribers(selectorSource);\n}\n"]}
1
+ {"version":3,"file":"selector.js","sourceRoot":"","sources":["../src/selector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAuBvC,4FAA4F;AAC5F,MAAM,UAAU,QAAQ,CACtB,MAA4B,EAC5B,OAAiE;IAEjE,MAAM,mBAAmB,GAAG,OAAO,EAAE,MAAM,KAAK,SAAS,CAAC;IAC1D,MAAM,MAAM,GAAG,OAAO,EAAE,MAAM,IAAI,uBAAqC,CAAC;IACxE,MAAM,OAAO,GAAG,IAAI,GAAG,EAA8B,CAAC;IACtD,IAAI,OAAO,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC;IAE1C,MAAM,mBAAmB,GAAG,MAAM,CAAC,GAAG,EAAE;QACtC,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,E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,CAAC;AAChB,CAAC;AAED,SAAS,uBAAuB,CAAe,KAAa,EAAE,GAAS;IACrE,OAAO,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AAC/B,CAAC;AAED,SAAS,qBAAqB;IAC5B,IAAI,IAAI,CAAC,WAAW,KAAK,IAAI,IAAI,IAAI,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;QAC9D,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC9B,CAAC;AACH,CAAC;AAED,SAAS,oBAAoB,CAC3B,cAAgD,EAChD,QAAiB;IAEjB,IACE,cAAc,KAAK,SAAS;QAC5B,cAAc,CAAC,QAAQ,KAAK,QAAQ,EACpC,CAAC;QACD,OAAO;IACT,CAAC;IAED,cAAc,CAAC,QAAQ,GAAG,QAAQ,CAAC;IACnC,MAAM,SAAS,GAAG,cAAc,CAAC,SAAS,CAAC;IAE3C,IAAI,OAAO,SAAS,KAAK,UAAU,EAAE,CAAC;QACpC,SAAS,CAAC,QAAQ,CAAC,CAAC;IACtB,CAAC;SAAM,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;QACnC,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;YACjC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACrB,CAAC;IACH,CAAC;IAED,iBAAiB,CAAC,cAAc,CAAC,CAAC;AACpC,CAAC","sourcesContent":["import { effect } from \"./effect.js\";\nimport { notifySubscribers, trackSource } from \"./tracking.js\";\nimport { untrack } from \"./untrack.js\";\nimport type { Source } from \"./state.js\";\nimport type { ReadonlyCell } from \"./types.js\";\n\n/** Equality function used by selector keys. */\nexport type SelectorEquality<TValue, TKey> = (value: TValue, key: TKey) => boolean;\ntype SelectorCallback = (selected: boolean) => void;\ntype SelectorCallbacks = SelectorCallback | Set<SelectorCallback>;\n\n/** A keyed boolean selector with an explicit disposer for the source subscription. */\nexport interface Selector<TValue, TKey = TValue> {\n (key: TKey): boolean;\n subscribe(key: TKey, listener: (selected: boolean) => void): () => void;\n dispose(): void;\n}\n\ninterface SelectorSource<TKey> extends Source {\n callbacks?: SelectorCallbacks | undefined;\n key: TKey;\n owner: Map<TKey, SelectorSource<TKey>>;\n selected: boolean;\n}\n\n/** Creates keyed boolean cells that update only for the previous and next selected keys. */\nexport function selector<TValue, TKey = TValue>(\n source: ReadonlyCell<TValue>,\n options?: { equals?: SelectorEquality<TValue, TKey> | undefined },\n): Selector<TValue, TKey> {\n const usesDefaultEquality = options?.equals === undefined;\n const equals = options?.equals ?? defaultSelectorEquality<TValue, TKey>;\n const sources = new Map<TKey, SelectorSource<TKey>>();\n let current = untrack(() => source.get());\n\n const disposeSourceEffect = effect(() => {\n const next = source.get();\n\n if (Object.is(current, next)) {\n return;\n }\n\n const previous = current;\n current = next;\n\n if (usesDefaultEquality) {\n updateSelectorSource(sources.get(previous as unknown as TKey), false);\n updateSelectorSource(sources.get(next as unknown as TKey), true);\n return;\n }\n\n for (const selectorSource of sources.values()) {\n const nextSelected =\n equals(next, selectorSource.key) === true;\n\n updateSelectorSource(selectorSource, nextSelected);\n }\n });\n\n function getOrCreateSelectorSource(key: TKey): SelectorSource<TKey> {\n let selectorSource = sources.get(key);\n\n if (selectorSource === undefined) {\n selectorSource = {\n key,\n onNoSubscribers: cleanupSelectorSource,\n owner: sources,\n selected: equals(current, key) === true,\n subscribers: null,\n };\n sources.set(key, selectorSource);\n }\n\n return selectorSource;\n }\n\n const select = ((key: TKey): boolean => {\n const selectorSource = getOrCreateSelectorSource(key);\n\n trackSource(selectorSource);\n return selectorSource.selected;\n }) as Selector<TValue, TKey>;\n\n select.subscribe = (key, listener) => {\n const selectorSource = getOrCreateSelectorSource(key);\n const callbacks = selectorSource.callbacks;\n\n if (callbacks === undefined) {\n selectorSource.callbacks = listener;\n } else if (typeof callbacks === \"function\") {\n if (callbacks !== listener) {\n selectorSource.callbacks = new Set([callbacks, listener]);\n }\n } else {\n callbacks.add(listener);\n }\n\n return () => {\n const currentCallbacks = selectorSource.callbacks;\n\n if (currentCallbacks === listener) {\n selectorSource.callbacks = undefined;\n } else if (currentCallbacks instanceof Set) {\n currentCallbacks.delete(listener);\n\n if (currentCallbacks.size === 0) {\n selectorSource.callbacks = undefined;\n }\n }\n\n cleanupSelectorSource.call(selectorSource);\n };\n };\n\n select.dispose = () => {\n disposeSourceEffect();\n sources.clear();\n };\n\n return select;\n}\n\nfunction defaultSelectorEquality<TValue, TKey>(value: TValue, key: TKey): boolean {\n return Object.is(value, key);\n}\n\nfunction cleanupSelectorSource<TKey>(this: SelectorSource<TKey>): void {\n if (this.subscribers === null && this.callbacks === undefined) {\n this.owner.delete(this.key);\n }\n}\n\nfunction updateSelectorSource<TKey>(\n selectorSource: SelectorSource<TKey> | undefined,\n selected: boolean,\n): void {\n if (\n selectorSource === undefined ||\n selectorSource.selected === selected\n ) {\n return;\n }\n\n selectorSource.selected = selected;\n const callbacks = selectorSource.callbacks;\n\n if (typeof callbacks === \"function\") {\n callbacks(selected);\n } else if (callbacks !== undefined) {\n for (const callback of callbacks) {\n callback(selected);\n }\n }\n\n notifySubscribers(selectorSource);\n}\n"]}
package/dist/state.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"state.js","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,sBAAsB,CAAC;AAEvE,wEAAwE;AACxE,6EAA6E;AAC7E,+BAA+B;AAC/B,+BAA+B,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAgCjD,MAAM,CAAC,MAAM,YAAY,GAQrB;IACF,aAAa,EAAE,IAAI;IACnB,UAAU,EAAE,CAAC;IACb,YAAY,EAAE,SAAS;IACvB,gBAAgB,EAAE,KAAK;IACvB,iBAAiB,EAAE,CAAC;IACpB,iBAAiB,EAAE,CAAC;IACpB,eAAe,EAAE,IAAI,GAAG,EAAE;CAC3B,CAAC","sourcesContent":["import { warnOnDuplicateReactiveCoreCopy } from \"./duplicate-guard.js\";\n\n// This module holds the per-copy reactive runtime identity, so a second\n// evaluation in the same browser page is exactly the duplication that breaks\n// cross-package cell tracking.\nwarnOnDuplicateReactiveCoreCopy(import.meta.url);\n\nexport interface Source {\n // null while nothing subscribes, the computation itself while exactly one\n // does, and a Set from the second subscriber on (kept as a Set until it\n // empties back to null). Most sources never allocate a Set at all, and hot\n // write sites can gate on a null check instead of a Set.size accessor.\n subscribers: ReactiveComputation | Set<ReactiveComputation> | null;\n onNoSubscribers?: (() => void) | undefined;\n trackedBy?: ReactiveComputation | undefined;\n trackedVersion?: number | undefined;\n}\n\nexport interface ReactiveComputation {\n readonly id: number;\n deps: Set<Source>;\n orderedDeps?: Source[] | undefined;\n trackingAddedDeps?: Source[] | undefined;\n trackingCount?: number | undefined;\n trackingOrderedIndex?: number | undefined;\n trackingOrderedMismatch?: boolean | undefined;\n trackingTouchedDeps?: Source[] | undefined;\n trackingVersion?: number | undefined;\n disposed: boolean;\n queued: boolean;\n markDirty(): void;\n run(): void;\n dispose(): void;\n}\n\nexport type Tracker = ReactiveComputation | null;\n\nexport const runtimeState: {\n activeTracker: Tracker;\n batchDepth: number;\n cleanupOwner: ((dispose: () => void) => void) | undefined;\n flushingComputed: boolean;\n nextComputationId: number;\n notificationDepth: number;\n pendingComputed: Set<ReactiveComputation>;\n} = {\n activeTracker: null,\n batchDepth: 0,\n cleanupOwner: undefined,\n flushingComputed: false,\n nextComputationId: 0,\n notificationDepth: 0,\n pendingComputed: new Set(),\n};\n"]}
1
+ {"version":3,"file":"state.js","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,sBAAsB,CAAC;AAEvE,wEAAwE;AACxE,6EAA6E;AAC7E,+BAA+B;AAC/B,+BAA+B,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;AAgCjD,MAAM,CAAC,MAAM,YAAY,GAQrB;IACF,aAAa,EAAE,IAAI;IACnB,UAAU,EAAE,CAAC;IACb,YAAY,EAAE,SAAS;IACvB,gBAAgB,EAAE,KAAK;IACvB,iBAAiB,EAAE,CAAC;IACpB,iBAAiB,EAAE,CAAC;IACpB,eAAe,EAAE,IAAI,GAAG,EAAE;CAC3B,CAAC","sourcesContent":["import { warnOnDuplicateReactiveCoreCopy } from \"./duplicate-guard.js\";\n\n// This module holds the per-copy reactive runtime identity, so a second\n// evaluation in the same browser page is exactly the duplication that breaks\n// cross-package cell tracking.\nwarnOnDuplicateReactiveCoreCopy(import.meta.url);\n\nexport interface Source {\n // null while nothing subscribes, the computation itself while exactly one\n // does, and a Set from the second subscriber on (kept as a Set until it\n // empties back to null). Most sources never allocate a Set at all, and hot\n // write sites can gate on a null check instead of a Set.size accessor.\n subscribers: ReactiveComputation | Set<ReactiveComputation> | null;\n onNoSubscribers?: (() => void) | undefined;\n trackedBy?: ReactiveComputation | undefined;\n trackedVersion?: number | undefined;\n}\n\nexport interface ReactiveComputation {\n readonly id: number;\n deps: Set<Source>;\n orderedDeps?: Source[] | undefined;\n trackingAddedDeps?: Source[] | undefined;\n trackingCount?: number | undefined;\n trackingOrderedIndex?: number | undefined;\n trackingOrderedMismatch?: boolean | undefined;\n trackingTouchedDeps?: Source[] | undefined;\n trackingVersion?: number | undefined;\n disposed: boolean;\n queued: boolean;\n markDirty(): void;\n run(): void;\n dispose(): void;\n}\n\nexport type Tracker = ReactiveComputation | null;\n\nexport const runtimeState: {\n activeTracker: Tracker;\n batchDepth: number;\n cleanupOwner: ((dispose: () => void) => void) | undefined;\n flushingComputed: boolean;\n nextComputationId: number;\n notificationDepth: number;\n pendingComputed: Set<ReactiveComputation>;\n} = {\n activeTracker: null,\n batchDepth: 0,\n cleanupOwner: undefined,\n flushingComputed: false,\n nextComputationId: 0,\n notificationDepth: 0,\n pendingComputed: new Set(),\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reckona/mreact-reactive-core",
3
- "version": "0.0.187",
3
+ "version": "0.0.189",
4
4
  "description": "Fine-grained reactive primitives used across mreact.",
5
5
  "keywords": [
6
6
  "jsx",