@mmstack/primitives 19.4.0 → 19.4.2
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/README.md +8 -5
- package/fesm2022/mmstack-primitives.mjs +526 -242
- package/fesm2022/mmstack-primitives.mjs.map +1 -1
- package/index.d.ts +2 -2
- package/lib/chunked.d.ts +2 -2
- package/lib/concurrent/pausable.d.ts +3 -2
- package/lib/concurrent/start-transition.d.ts +5 -0
- package/lib/concurrent/transaction.d.ts +5 -0
- package/lib/effect/index.d.ts +1 -0
- package/lib/get-signal-equality.d.ts +1 -1
- package/lib/mutable.d.ts +1 -1
- package/lib/pipeable/{pipeble.d.ts → pipeable.d.ts} +1 -1
- package/lib/pipeable/public_api.d.ts +1 -1
- package/lib/pipeable/types.d.ts +1 -1
- package/lib/sensors/battery-status.d.ts +2 -1
- package/lib/sensors/clipboard.d.ts +2 -1
- package/lib/sensors/element-size.d.ts +2 -4
- package/lib/sensors/element-visibility.d.ts +2 -4
- package/lib/sensors/focus-within.d.ts +2 -1
- package/lib/sensors/geolocation.d.ts +2 -3
- package/lib/sensors/idle.d.ts +6 -4
- package/lib/sensors/index.d.ts +1 -0
- package/lib/sensors/media-query.d.ts +4 -3
- package/lib/sensors/mouse-position.d.ts +6 -7
- package/lib/sensors/network-status.d.ts +8 -3
- package/lib/sensors/orientation.d.ts +9 -2
- package/lib/sensors/page-visibility.d.ts +4 -2
- package/lib/sensors/scroll-position.d.ts +10 -18
- package/lib/sensors/sensor-options.d.ts +25 -0
- package/lib/sensors/sensor.d.ts +15 -30
- package/lib/sensors/window-size.d.ts +3 -6
- package/lib/store/store.d.ts +4 -4
- package/lib/stored.d.ts +4 -3
- package/lib/{tabSync.d.ts → tab-sync.d.ts} +9 -4
- package/lib/throttled.d.ts +2 -0
- package/lib/to-writable.d.ts +4 -0
- package/package.json +1 -1
package/lib/store/store.d.ts
CHANGED
|
@@ -68,7 +68,7 @@ export type Opaque<T> = T & {
|
|
|
68
68
|
readonly [OPAQUE]: true;
|
|
69
69
|
};
|
|
70
70
|
/** @internal Strips the opaque brand from the value a leaf signal carries. */
|
|
71
|
-
export type
|
|
71
|
+
export type UnwrapOpaque<T> = T extends {
|
|
72
72
|
readonly [OPAQUE]: true;
|
|
73
73
|
} ? Omit<T, typeof OPAQUE> : T;
|
|
74
74
|
type BaseType = string | number | boolean | symbol | bigint | undefined | null | Function | Date | RegExp | {
|
|
@@ -155,15 +155,15 @@ type MutableSignalStoreObject<T> = Simplify<Readonly<{
|
|
|
155
155
|
<L extends AnyRecord>(props: L): MutableSignalStore<Simplify<Omit<NonNullable<T>, keyof L> & L>>;
|
|
156
156
|
};
|
|
157
157
|
}>;
|
|
158
|
-
export type SignalStore<T> = Signal<
|
|
158
|
+
export type SignalStore<T> = Signal<UnwrapOpaque<T>> & (IsAny<T> extends true ? SignalStoreObject<T> : NonNullable<T> extends BaseType ? {
|
|
159
159
|
readonly [LEAF]: () => boolean;
|
|
160
160
|
} : NonNullable<T> extends any[] ? SignalArrayStore<NonNullable<T>> : SignalStoreObject<T>);
|
|
161
|
-
export type WritableSignalStore<T> = WritableSignal<
|
|
161
|
+
export type WritableSignalStore<T> = WritableSignal<UnwrapOpaque<T>> & {
|
|
162
162
|
readonly asReadonlyStore: () => SignalStore<T>;
|
|
163
163
|
} & (IsAny<T> extends true ? WritableSignalStoreObject<T> : NonNullable<T> extends BaseType ? {
|
|
164
164
|
readonly [LEAF]: () => boolean;
|
|
165
165
|
} : NonNullable<T> extends any[] ? WritableArrayStore<NonNullable<T>> : WritableSignalStoreObject<T>);
|
|
166
|
-
export type MutableSignalStore<T> = MutableSignal<
|
|
166
|
+
export type MutableSignalStore<T> = MutableSignal<UnwrapOpaque<T>> & {
|
|
167
167
|
readonly asReadonlyStore: () => SignalStore<T>;
|
|
168
168
|
} & (IsAny<T> extends true ? MutableSignalStoreObject<T> : NonNullable<T> extends BaseType ? {
|
|
169
169
|
readonly [LEAF]: () => boolean;
|
package/lib/stored.d.ts
CHANGED
|
@@ -95,8 +95,8 @@ export type StoredSignal<T> = WritableSignal<T> & {
|
|
|
95
95
|
*
|
|
96
96
|
* @template T The type of value held by the signal and stored (after serialization).
|
|
97
97
|
* @param fallback The default value of type `T` to use when no value is found in storage
|
|
98
|
-
* or when deserialization fails.
|
|
99
|
-
*
|
|
98
|
+
* or when deserialization fails. A stored value (including a legitimate `null` for a
|
|
99
|
+
* nullable `T`) always round-trips; the fallback only surfaces when the entry is absent.
|
|
100
100
|
* @param options Configuration options (`CreateStoredOptions<T>`). Requires at least the `key`.
|
|
101
101
|
* @returns A `StoredSignal<T>` instance. This signal behaves like a standard `WritableSignal<T>`,
|
|
102
102
|
* but its value is persisted. It includes a `.clear()` method to remove the item from storage
|
|
@@ -109,7 +109,8 @@ export type StoredSignal<T> = WritableSignal<T> & {
|
|
|
109
109
|
* - **Error Handling:** Catches and logs errors during serialization/deserialization in dev mode.
|
|
110
110
|
* - **Tab Sync:** If `syncTabs` is true, listens to `storage` events to keep the signal value
|
|
111
111
|
* consistent across browser tabs using the same key. Cleanup is handled automatically
|
|
112
|
-
* using `DestroyRef`.
|
|
112
|
+
* using `DestroyRef`. Web Storage only: the `storage` event never fires for custom `store`
|
|
113
|
+
* adapters, so `syncTabs` has no effect with one.
|
|
113
114
|
* - **Removal:** Use the `.clear()` method on the returned signal to remove the item from storage.
|
|
114
115
|
* Setting the signal to the fallback value will store the fallback value, not remove the item.
|
|
115
116
|
*
|
|
@@ -1,16 +1,21 @@
|
|
|
1
|
-
import { type WritableSignal } from '@angular/core';
|
|
1
|
+
import { type OnDestroy, type WritableSignal } from '@angular/core';
|
|
2
2
|
import * as i0 from "@angular/core";
|
|
3
|
-
export declare class MessageBus {
|
|
3
|
+
export declare class MessageBus implements OnDestroy {
|
|
4
4
|
private readonly channel;
|
|
5
5
|
private readonly listeners;
|
|
6
6
|
subscribe<T>(id: string, listener: (data: T) => void): {
|
|
7
7
|
unsub: () => void;
|
|
8
8
|
post: (value: T) => void;
|
|
9
9
|
};
|
|
10
|
-
|
|
10
|
+
ngOnDestroy(): void;
|
|
11
11
|
static ɵfac: i0.ɵɵFactoryDeclaration<MessageBus, never>;
|
|
12
12
|
static ɵprov: i0.ɵɵInjectableDeclaration<MessageBus>;
|
|
13
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* @deprecated The generated id hashes the call-site stack line, which collides when a shared
|
|
16
|
+
* helper calls {@link tabSync} for multiple signals and diverges across minified builds during
|
|
17
|
+
* a rolling deploy. Pass an explicit `{ id }` instead.
|
|
18
|
+
*/
|
|
14
19
|
export declare function generateDeterministicID(): string;
|
|
15
20
|
type LegacySyncSignalOptions = {
|
|
16
21
|
id?: string;
|
|
@@ -19,7 +24,7 @@ export type SyncSignalOptions = {
|
|
|
19
24
|
id: string;
|
|
20
25
|
};
|
|
21
26
|
/**
|
|
22
|
-
* @example tabSync(signal('dark), {id: 'theme})
|
|
27
|
+
* @example tabSync(signal('dark'), { id: 'theme' })
|
|
23
28
|
*/
|
|
24
29
|
export declare function tabSync<T extends WritableSignal<any>>(sig: T, opt: SyncSignalOptions | string): T;
|
|
25
30
|
/**
|
package/lib/throttled.d.ts
CHANGED
|
@@ -28,6 +28,8 @@ export type CreateThrottledOptions<T> = CreateSignalOptions<T> & {
|
|
|
28
28
|
/**
|
|
29
29
|
* If `true`, the throttled signal emits the latest pending value at the end
|
|
30
30
|
* of each cooldown window (only when at least one write occurred during it).
|
|
31
|
+
* Note: with both `leading` and `trailing` set to `false` the throttled view
|
|
32
|
+
* never updates (writes still reach `.original`).
|
|
31
33
|
* @default true
|
|
32
34
|
*/
|
|
33
35
|
trailing?: boolean;
|
package/lib/to-writable.d.ts
CHANGED
|
@@ -31,6 +31,10 @@ export declare function toWritable<T>(source: Signal<T>, set: (value: T) => void
|
|
|
31
31
|
/**
|
|
32
32
|
* If `true` (the default), the returned signal will be a computed signal that depends on the source signal.
|
|
33
33
|
* If `false`, the returned signal will be a direct wrapper around the source signal without creating a new computed signal.
|
|
34
|
+
*
|
|
35
|
+
* CAUTION: with `pure: false` the `set`/`update`/`asReadonly` methods are patched directly
|
|
36
|
+
* onto the signal object you passed in — every other holder of that signal sees it become
|
|
37
|
+
* writable. Only use it with a signal you created and own exclusively.
|
|
34
38
|
* @default true
|
|
35
39
|
*/
|
|
36
40
|
pure?: boolean;
|