opshot 0.5.2 → 0.6.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/README.md +83 -24
- package/dist/chunk-4JZIOHSP.js +768 -0
- package/dist/createMutableState-DJ9dmpR-.d.ts +36 -0
- package/dist/index.d.ts +52 -76
- package/dist/index.js +7 -1254
- package/dist/react.d.ts +23 -0
- package/dist/react.js +517 -0
- package/package.json +10 -1
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sets when a state's window flushes. Call `flush` once.
|
|
3
|
+
*
|
|
4
|
+
* @param flush - Delivers pending operations.
|
|
5
|
+
* @returns Nothing.
|
|
6
|
+
*/
|
|
7
|
+
type EmissionScheduler = (flush: () => void) => void;
|
|
8
|
+
/**
|
|
9
|
+
* Options for `createMutableState`.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* createMutableState({ count: 0 }, { emitOn, strict: false })
|
|
13
|
+
*/
|
|
14
|
+
interface MutableStateOptions {
|
|
15
|
+
/**
|
|
16
|
+
* When the window flushes for all writes. Defaults to a microtask.
|
|
17
|
+
*/
|
|
18
|
+
readonly emitOn?: EmissionScheduler;
|
|
19
|
+
/**
|
|
20
|
+
* When true, throws at a dangerous edge, at the cause. Defaults to true.
|
|
21
|
+
*/
|
|
22
|
+
readonly strict?: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Creates a mutable state object.
|
|
26
|
+
*
|
|
27
|
+
* `ignore()` marks an object so every edge to it is untracked. `unsafeTrack()` marks an object so a node entering while marked, or entering beneath an exempt node, is exempt from strict.
|
|
28
|
+
*
|
|
29
|
+
* @typeParam T - State shape.
|
|
30
|
+
* @param properties - Initial fields.
|
|
31
|
+
* @param options - Creation options.
|
|
32
|
+
* @returns The state.
|
|
33
|
+
*/
|
|
34
|
+
declare function createMutableState<T extends object>(properties: T, options?: MutableStateOptions): T;
|
|
35
|
+
|
|
36
|
+
export { type EmissionScheduler as E, type MutableStateOptions as M, createMutableState as c };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,39 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Sets when a state's window flushes. Call `flush` once.
|
|
5
|
-
*
|
|
6
|
-
* @param flush - Delivers pending operations.
|
|
7
|
-
* @returns Nothing.
|
|
8
|
-
*/
|
|
9
|
-
type EmissionScheduler = (flush: () => void) => void;
|
|
10
|
-
/**
|
|
11
|
-
* Options for `createMutableState`.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* createMutableState({ count: 0 }, { emitOn, strict: false })
|
|
15
|
-
*/
|
|
16
|
-
interface MutableStateOptions {
|
|
17
|
-
/**
|
|
18
|
-
* When the window flushes for all writes. Defaults to a microtask.
|
|
19
|
-
*/
|
|
20
|
-
readonly emitOn?: EmissionScheduler;
|
|
21
|
-
/**
|
|
22
|
-
* When true, throws at a dangerous edge, at the cause. Defaults to true.
|
|
23
|
-
*/
|
|
24
|
-
readonly strict?: boolean;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Creates a mutable state object.
|
|
28
|
-
*
|
|
29
|
-
* `ignore()` marks an object so every edge to it is untracked. `unsafeTrack()` marks an object so a node entering while marked, or entering beneath an exempt node, is exempt from strict.
|
|
30
|
-
*
|
|
31
|
-
* @typeParam T - State shape.
|
|
32
|
-
* @param properties - Initial fields.
|
|
33
|
-
* @param options - Creation options.
|
|
34
|
-
* @returns The state.
|
|
35
|
-
*/
|
|
36
|
-
declare function createMutableState<T extends object>(properties: T, options?: MutableStateOptions): T;
|
|
1
|
+
export { E as EmissionScheduler, M as MutableStateOptions, c as createMutableState } from './createMutableState-DJ9dmpR-.js';
|
|
37
2
|
|
|
38
3
|
/**
|
|
39
4
|
* Returns a stable identity key for a value.
|
|
@@ -59,34 +24,61 @@ declare function isSameIdentity(first: object, second: object): boolean;
|
|
|
59
24
|
*/
|
|
60
25
|
declare function isState(value: unknown): value is object;
|
|
61
26
|
|
|
62
|
-
|
|
63
|
-
* A change to one key of a node.
|
|
64
|
-
*
|
|
65
|
-
* @example
|
|
66
|
-
* { node, key: "count", before: 0, after: 1, meta: undefined }
|
|
67
|
-
*/
|
|
68
|
-
interface Operation {
|
|
27
|
+
interface OperationBase<M> {
|
|
69
28
|
/**
|
|
70
|
-
* Node that changed.
|
|
29
|
+
* Node that changed; writes through it are tracked.
|
|
71
30
|
*/
|
|
72
|
-
readonly node:
|
|
31
|
+
readonly node: Record<string, unknown>;
|
|
73
32
|
/**
|
|
74
33
|
* Key that changed.
|
|
75
34
|
*/
|
|
76
35
|
readonly key: string;
|
|
77
36
|
/**
|
|
78
|
-
*
|
|
37
|
+
* Meta of the batch the write was made in.
|
|
79
38
|
*/
|
|
80
|
-
readonly
|
|
39
|
+
readonly meta: M;
|
|
40
|
+
}
|
|
41
|
+
interface AddOperation<M = unknown> extends OperationBase<M> {
|
|
81
42
|
/**
|
|
82
|
-
*
|
|
43
|
+
* The key was absent before.
|
|
83
44
|
*/
|
|
84
|
-
readonly
|
|
45
|
+
readonly kind: "add";
|
|
85
46
|
/**
|
|
86
|
-
*
|
|
47
|
+
* Value after.
|
|
87
48
|
*/
|
|
88
|
-
readonly
|
|
49
|
+
readonly after: unknown;
|
|
89
50
|
}
|
|
51
|
+
interface ChangeOperation<M = unknown> extends OperationBase<M> {
|
|
52
|
+
/**
|
|
53
|
+
* The key held a value before and after.
|
|
54
|
+
*/
|
|
55
|
+
readonly kind: "change";
|
|
56
|
+
/**
|
|
57
|
+
* Value before.
|
|
58
|
+
*/
|
|
59
|
+
readonly before: unknown;
|
|
60
|
+
/**
|
|
61
|
+
* Value after.
|
|
62
|
+
*/
|
|
63
|
+
readonly after: unknown;
|
|
64
|
+
}
|
|
65
|
+
interface DeleteOperation<M = unknown> extends OperationBase<M> {
|
|
66
|
+
/**
|
|
67
|
+
* The key is absent after.
|
|
68
|
+
*/
|
|
69
|
+
readonly kind: "delete";
|
|
70
|
+
/**
|
|
71
|
+
* Value before.
|
|
72
|
+
*/
|
|
73
|
+
readonly before: unknown;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* A change to one key of a node.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* { kind: "change", node, key: "count", before: 0, after: 1, meta: undefined }
|
|
80
|
+
*/
|
|
81
|
+
type Operation<M = unknown> = AddOperation<M> | ChangeOperation<M> | DeleteOperation<M>;
|
|
90
82
|
|
|
91
83
|
/**
|
|
92
84
|
* Marks an object so every edge to it is untracked in every state.
|
|
@@ -231,49 +223,33 @@ declare class TrackedSet<T> {
|
|
|
231
223
|
*
|
|
232
224
|
* @param operations - Operations for the change.
|
|
233
225
|
*/
|
|
234
|
-
type StateListener = (operations: ReadonlyArray<Operation
|
|
226
|
+
type StateListener<M = unknown> = (operations: ReadonlyArray<Operation<M>>) => void;
|
|
235
227
|
|
|
236
228
|
/**
|
|
237
229
|
* Listens for changes to a state.
|
|
238
230
|
*
|
|
231
|
+
* @typeParam M - Meta type the caller asserts for the state's batches.
|
|
239
232
|
* @param state - State to listen to.
|
|
240
233
|
* @param listener - Called on each change.
|
|
241
234
|
* @returns Unsubscribe function.
|
|
242
235
|
*/
|
|
243
|
-
declare function subscribe(state: object, listener: StateListener): () => void;
|
|
236
|
+
declare function subscribe<M = unknown>(state: object, listener: StateListener<M>): () => void;
|
|
244
237
|
|
|
245
238
|
/**
|
|
246
239
|
* Runs writes carrying `meta`.
|
|
240
|
+
* A callback that returns a promise throws: the meta covers only what runs before its first await.
|
|
247
241
|
*
|
|
248
242
|
* @param callback - Function that writes any states.
|
|
249
243
|
* @param meta - Carried by each write's operation.
|
|
250
244
|
*/
|
|
251
|
-
declare function batch(callback: () => void, meta?: unknown): void;
|
|
245
|
+
declare function batch(callback: () => void | undefined, meta?: unknown): void;
|
|
252
246
|
|
|
253
247
|
/**
|
|
254
|
-
* Ends
|
|
248
|
+
* Ends each state's window now, delivering the operations gathered so far.
|
|
255
249
|
*
|
|
256
250
|
* @param state - State to flush.
|
|
251
|
+
* @param states - Further states, flushed in order.
|
|
257
252
|
*/
|
|
258
|
-
declare function flush(state: object): void;
|
|
259
|
-
|
|
260
|
-
/**
|
|
261
|
-
* Wraps a component so it re-renders only when fields it read change.
|
|
262
|
-
*
|
|
263
|
-
* @typeParam P - Props type.
|
|
264
|
-
* @param Component - Component to wrap.
|
|
265
|
-
* @returns The wrapped component.
|
|
266
|
-
*/
|
|
267
|
-
declare function scope<P extends object>(Component: ComponentType<P>): FC<P>;
|
|
268
|
-
|
|
269
|
-
/**
|
|
270
|
-
* Creates mutable state for a component.
|
|
271
|
-
*
|
|
272
|
-
* @typeParam T - State shape.
|
|
273
|
-
* @param properties - Initial fields, or a function that returns them.
|
|
274
|
-
* @param options - Creation options.
|
|
275
|
-
* @returns The state.
|
|
276
|
-
*/
|
|
277
|
-
declare function useMutableState<T extends object>(properties: (() => T) | T, options?: MutableStateOptions): T;
|
|
253
|
+
declare function flush(state: object, ...states: ReadonlyArray<object>): void;
|
|
278
254
|
|
|
279
|
-
export { type
|
|
255
|
+
export { type AddOperation, type ChangeOperation, type DeleteOperation, type Operation, type StateListener, TrackedDate, TrackedMap, TrackedSet, batch, flush, identify, ignore, isSameIdentity, isState, subscribe, unsafeTrack };
|