@mmstack/primitives 20.5.8 → 20.5.10
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/fesm2022/mmstack-primitives.mjs +46 -10
- package/fesm2022/mmstack-primitives.mjs.map +1 -1
- package/index.d.ts +52 -6
- package/package.json +1 -1
|
@@ -2405,8 +2405,49 @@ function signalFromEvent(target, eventName, initial, projectOrOpt, maybeOpt) {
|
|
|
2405
2405
|
return untracked(() => state.asReadonly());
|
|
2406
2406
|
}
|
|
2407
2407
|
|
|
2408
|
-
|
|
2409
|
-
|
|
2408
|
+
/**
|
|
2409
|
+
* Runtime marker + compile-time brand for an opaque value. A `const`-declared `Symbol`
|
|
2410
|
+
* has a `unique symbol` type, so the same symbol serves as both the property key written
|
|
2411
|
+
* by {@link opaque} and the type-level brand carried by {@link Opaque}.
|
|
2412
|
+
*/
|
|
2413
|
+
const OPAQUE = Symbol('@mmstack/primitives::store/OPAQUE');
|
|
2414
|
+
/**
|
|
2415
|
+
* Marks a plain object as opaque so {@link store} treats it as an indivisible leaf
|
|
2416
|
+
* (returned whole, never deep-proxied) — the same way it treats a `Date` or `RegExp`.
|
|
2417
|
+
* The marker is a non-enumerable symbol, so it never appears in spreads or iteration.
|
|
2418
|
+
* Idempotent. Call before freezing (`defineProperty` fails on a frozen object).
|
|
2419
|
+
*
|
|
2420
|
+
* @example
|
|
2421
|
+
* const s = store({ config: opaque({ theme: 'dark', nested: { a: 1 } }) });
|
|
2422
|
+
* s.config(); // the whole object, not a child store
|
|
2423
|
+
* s.config.set(opaque({ theme: 'light', nested: { a: 2 } }));
|
|
2424
|
+
*/
|
|
2425
|
+
function opaque(value) {
|
|
2426
|
+
if (value[OPAQUE] !== true)
|
|
2427
|
+
Object.defineProperty(value, OPAQUE, { value: true, enumerable: false });
|
|
2428
|
+
return value;
|
|
2429
|
+
}
|
|
2430
|
+
/**
|
|
2431
|
+
* Type guard companion to {@link opaque}: returns `true` when `value` carries the
|
|
2432
|
+
* {@link OPAQUE} brand, narrowing it to {@link Opaque}. This is the same check the
|
|
2433
|
+
* store uses to route opaque values to its leaf branch (alongside `Date`/`RegExp`).
|
|
2434
|
+
*
|
|
2435
|
+
* @internal Exposed for advanced/niche interop only — not part of the supported public
|
|
2436
|
+
* surface and may change without a major version bump. Reach for {@link opaque} for
|
|
2437
|
+
* normal usage.
|
|
2438
|
+
*
|
|
2439
|
+
* @example
|
|
2440
|
+
* if (isOpaque(value)) {
|
|
2441
|
+
* // value: Opaque<object> — `store` would treat it as an indivisible leaf
|
|
2442
|
+
* }
|
|
2443
|
+
*/
|
|
2444
|
+
function isOpaque(value) {
|
|
2445
|
+
return (typeof value === 'object' &&
|
|
2446
|
+
value !== null &&
|
|
2447
|
+
value[OPAQUE] === true);
|
|
2448
|
+
}
|
|
2449
|
+
const IS_STORE = Symbol('@mmstack/primitives::store/IS_STORE');
|
|
2450
|
+
const SCOPE_PARENT = Symbol('@mmstack/primitives::store/SCOPE_PARENT');
|
|
2410
2451
|
/**
|
|
2411
2452
|
* @internal
|
|
2412
2453
|
* Test-only handle on the proxy cache (deliberately NOT re-exported from the public barrel).
|
|
@@ -2440,7 +2481,7 @@ function isStore(value) {
|
|
|
2440
2481
|
value[IS_STORE] === true);
|
|
2441
2482
|
}
|
|
2442
2483
|
function isRecord(value) {
|
|
2443
|
-
if (value === null || typeof value !== 'object')
|
|
2484
|
+
if (value === null || typeof value !== 'object' || isOpaque(value))
|
|
2444
2485
|
return false;
|
|
2445
2486
|
const proto = Object.getPrototypeOf(value);
|
|
2446
2487
|
return proto === Object.prototype || proto === null;
|
|
@@ -2767,12 +2808,7 @@ function scopedStore(parent, seed, kind, injector) {
|
|
|
2767
2808
|
return hasOwnKey(localValue(), prop) || hasOwnKey(parentValue(), prop);
|
|
2768
2809
|
},
|
|
2769
2810
|
ownKeys() {
|
|
2770
|
-
return
|
|
2771
|
-
...new Set([
|
|
2772
|
-
...Reflect.ownKeys(parentValue()),
|
|
2773
|
-
...Reflect.ownKeys(localValue()),
|
|
2774
|
-
]),
|
|
2775
|
-
];
|
|
2811
|
+
return Reflect.ownKeys(untracked(view));
|
|
2776
2812
|
},
|
|
2777
2813
|
getOwnPropertyDescriptor(_, prop) {
|
|
2778
2814
|
if (hasOwnKey(localValue(), prop) || hasOwnKey(parentValue(), prop))
|
|
@@ -3283,5 +3319,5 @@ function withHistory(sourceOrValue, opt) {
|
|
|
3283
3319
|
* Generated bundle index. Do not edit.
|
|
3284
3320
|
*/
|
|
3285
3321
|
|
|
3286
|
-
export { batteryStatus, chunked, clipboard, combineWith, debounce, debounced, derived, distinct, elementSize, elementVisibility, filter, filterWith, focusWithin, geolocation, idle, indexArray, isDerivation, isMutable, isStore, keyArray, map, mapArray, mapObject, mediaQuery, mousePosition, mutable, mutableStore, nestedEffect, networkStatus, orientation, pageVisibility, pairwise, pipeable, piped, pooled, pooledArray, pooledMap, pooledSet, prefersDarkMode, prefersReducedMotion, scan, scrollPosition, select, sensor, sensors, signalFromEvent, startWith, store, stored, tabSync, tap, throttle, throttled, toFakeDerivation, toFakeSignalDerivation, toStore, toWritable, until, windowSize, withHistory };
|
|
3322
|
+
export { batteryStatus, chunked, clipboard, combineWith, debounce, debounced, derived, distinct, elementSize, elementVisibility, filter, filterWith, focusWithin, geolocation, idle, indexArray, isDerivation, isMutable, isOpaque, isStore, keyArray, map, mapArray, mapObject, mediaQuery, mousePosition, mutable, mutableStore, nestedEffect, networkStatus, opaque, orientation, pageVisibility, pairwise, pipeable, piped, pooled, pooledArray, pooledMap, pooledSet, prefersDarkMode, prefersReducedMotion, scan, scrollPosition, select, sensor, sensors, signalFromEvent, startWith, store, stored, tabSync, tap, throttle, throttled, toFakeDerivation, toFakeSignalDerivation, toStore, toWritable, until, windowSize, withHistory };
|
|
3287
3323
|
//# sourceMappingURL=mmstack-primitives.mjs.map
|