@mmstack/primitives 19.3.8 → 19.3.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 +1 -1
- package/lib/store.d.ts +50 -4
- package/package.json +1 -1
|
@@ -2402,8 +2402,49 @@ function signalFromEvent(target, eventName, initial, projectOrOpt, maybeOpt) {
|
|
|
2402
2402
|
return untracked(() => state.asReadonly());
|
|
2403
2403
|
}
|
|
2404
2404
|
|
|
2405
|
-
|
|
2406
|
-
|
|
2405
|
+
/**
|
|
2406
|
+
* Runtime marker + compile-time brand for an opaque value. A `const`-declared `Symbol`
|
|
2407
|
+
* has a `unique symbol` type, so the same symbol serves as both the property key written
|
|
2408
|
+
* by {@link opaque} and the type-level brand carried by {@link Opaque}.
|
|
2409
|
+
*/
|
|
2410
|
+
const OPAQUE = Symbol('@mmstack/primitives::store/OPAQUE');
|
|
2411
|
+
/**
|
|
2412
|
+
* Marks a plain object as opaque so {@link store} treats it as an indivisible leaf
|
|
2413
|
+
* (returned whole, never deep-proxied) — the same way it treats a `Date` or `RegExp`.
|
|
2414
|
+
* The marker is a non-enumerable symbol, so it never appears in spreads or iteration.
|
|
2415
|
+
* Idempotent. Call before freezing (`defineProperty` fails on a frozen object).
|
|
2416
|
+
*
|
|
2417
|
+
* @example
|
|
2418
|
+
* const s = store({ config: opaque({ theme: 'dark', nested: { a: 1 } }) });
|
|
2419
|
+
* s.config(); // the whole object, not a child store
|
|
2420
|
+
* s.config.set(opaque({ theme: 'light', nested: { a: 2 } }));
|
|
2421
|
+
*/
|
|
2422
|
+
function opaque(value) {
|
|
2423
|
+
if (value[OPAQUE] !== true)
|
|
2424
|
+
Object.defineProperty(value, OPAQUE, { value: true, enumerable: false });
|
|
2425
|
+
return value;
|
|
2426
|
+
}
|
|
2427
|
+
/**
|
|
2428
|
+
* Type guard companion to {@link opaque}: returns `true` when `value` carries the
|
|
2429
|
+
* {@link OPAQUE} brand, narrowing it to {@link Opaque}. This is the same check the
|
|
2430
|
+
* store uses to route opaque values to its leaf branch (alongside `Date`/`RegExp`).
|
|
2431
|
+
*
|
|
2432
|
+
* @internal Exposed for advanced/niche interop only — not part of the supported public
|
|
2433
|
+
* surface and may change without a major version bump. Reach for {@link opaque} for
|
|
2434
|
+
* normal usage.
|
|
2435
|
+
*
|
|
2436
|
+
* @example
|
|
2437
|
+
* if (isOpaque(value)) {
|
|
2438
|
+
* // value: Opaque<object> — `store` would treat it as an indivisible leaf
|
|
2439
|
+
* }
|
|
2440
|
+
*/
|
|
2441
|
+
function isOpaque(value) {
|
|
2442
|
+
return (typeof value === 'object' &&
|
|
2443
|
+
value !== null &&
|
|
2444
|
+
value[OPAQUE] === true);
|
|
2445
|
+
}
|
|
2446
|
+
const IS_STORE = Symbol('@mmstack/primitives::store/IS_STORE');
|
|
2447
|
+
const SCOPE_PARENT = Symbol('@mmstack/primitives::store/SCOPE_PARENT');
|
|
2407
2448
|
/**
|
|
2408
2449
|
* @internal
|
|
2409
2450
|
* Test-only handle on the proxy cache (deliberately NOT re-exported from the public barrel).
|
|
@@ -2437,7 +2478,7 @@ function isStore(value) {
|
|
|
2437
2478
|
value[IS_STORE] === true);
|
|
2438
2479
|
}
|
|
2439
2480
|
function isRecord(value) {
|
|
2440
|
-
if (value === null || typeof value !== 'object')
|
|
2481
|
+
if (value === null || typeof value !== 'object' || isOpaque(value))
|
|
2441
2482
|
return false;
|
|
2442
2483
|
const proto = Object.getPrototypeOf(value);
|
|
2443
2484
|
return proto === Object.prototype || proto === null;
|
|
@@ -2764,12 +2805,7 @@ function scopedStore(parent, seed, kind, injector) {
|
|
|
2764
2805
|
return hasOwnKey(localValue(), prop) || hasOwnKey(parentValue(), prop);
|
|
2765
2806
|
},
|
|
2766
2807
|
ownKeys() {
|
|
2767
|
-
return
|
|
2768
|
-
...new Set([
|
|
2769
|
-
...Reflect.ownKeys(parentValue()),
|
|
2770
|
-
...Reflect.ownKeys(localValue()),
|
|
2771
|
-
]),
|
|
2772
|
-
];
|
|
2808
|
+
return Reflect.ownKeys(untracked(view));
|
|
2773
2809
|
},
|
|
2774
2810
|
getOwnPropertyDescriptor(_, prop) {
|
|
2775
2811
|
if (hasOwnKey(localValue(), prop) || hasOwnKey(parentValue(), prop))
|
|
@@ -3273,5 +3309,5 @@ function withHistory(sourceOrValue, opt) {
|
|
|
3273
3309
|
* Generated bundle index. Do not edit.
|
|
3274
3310
|
*/
|
|
3275
3311
|
|
|
3276
|
-
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 };
|
|
3312
|
+
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 };
|
|
3277
3313
|
//# sourceMappingURL=mmstack-primitives.mjs.map
|