shelving 1.191.0 → 1.191.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/package.json +1 -1
- package/react/useStore.js +1 -2
- package/store/Store.d.ts +10 -2
- package/store/Store.js +10 -0
package/package.json
CHANGED
package/react/useStore.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { useSyncExternalStore } from "react";
|
|
2
|
-
import { NONE } from "../util/constants.js";
|
|
3
2
|
import { BLACKHOLE } from "../util/function.js";
|
|
4
3
|
import { runSequence } from "../util/sequence.js";
|
|
5
4
|
import { useProps } from "./useProps.js";
|
|
@@ -9,7 +8,7 @@ export function useStore(store) {
|
|
|
9
8
|
// Update `internals` if `store` changes.
|
|
10
9
|
if (store !== internals.store || !internals.subscribe || !internals.getSnapshot) {
|
|
11
10
|
internals.subscribe = onStoreChange => (store ? runSequence(store, onStoreChange, onStoreChange) : BLACKHOLE);
|
|
12
|
-
internals.getSnapshot = () =>
|
|
11
|
+
internals.getSnapshot = () => store?.snapshot;
|
|
13
12
|
internals.store = store;
|
|
14
13
|
}
|
|
15
14
|
useSyncExternalStore(internals.subscribe, internals.getSnapshot);
|
package/store/Store.d.ts
CHANGED
|
@@ -34,6 +34,10 @@ export type StoreReducer<I, O, A extends Arguments = []> = (value: O, ...args: A
|
|
|
34
34
|
export declare class Store<T, TT = T> implements AsyncIterable<T, void, void>, AsyncDisposable {
|
|
35
35
|
/** Deferred sequence this store uses to issue values as they change. */
|
|
36
36
|
readonly next: DeferredSequence<T, void, void>;
|
|
37
|
+
/**
|
|
38
|
+
* Snapshot returns either the current reason or the current value (or `NONE` if reason is unset).
|
|
39
|
+
*/
|
|
40
|
+
get snapshot(): unknown;
|
|
37
41
|
/**
|
|
38
42
|
* Store is considered to be "loading" if it has no value or error.
|
|
39
43
|
* - Calling `this.value` will throw `this.reason` if there's an error reason set, or a `Promise` if there's no value set.
|
|
@@ -106,20 +110,24 @@ export declare class Store<T, TT = T> implements AsyncIterable<T, void, void>, A
|
|
|
106
110
|
through(sequence: AsyncIterable<TT>): AsyncIterable<TT>;
|
|
107
111
|
/**
|
|
108
112
|
* Call a callback and save the returned value to this store.
|
|
113
|
+
* - If the callback returns an async value, it is awaited and values/errors will be saved.
|
|
109
114
|
*/
|
|
110
115
|
call<A extends Arguments>(callback: StoreCallback<TT, A>, ...args: A): Promise<boolean> | boolean;
|
|
111
116
|
/**
|
|
112
117
|
* Send the current value to a callback and save the returned value to this store.
|
|
118
|
+
* - If the callback returns an async value, it is awaited and values/errors will be saved.
|
|
113
119
|
*/
|
|
114
120
|
reduce<A extends Arguments>(reducer: StoreReducer<TT, T, A>, ...args: A): Promise<boolean> | boolean;
|
|
115
121
|
/**
|
|
116
122
|
* Run a callback and ignore any returned value.
|
|
123
|
+
* - If the callback returns an async value, it is awaited and errors will be saved.
|
|
117
124
|
*/
|
|
118
|
-
run<A extends Arguments>(callback: (...args: A) => void
|
|
125
|
+
run<A extends Arguments>(callback: (...args: A) => void, ...args: A): Promise<boolean> | boolean;
|
|
119
126
|
/**
|
|
120
127
|
* Send the current value to a callback and ignore any returned value.
|
|
128
|
+
* - If the callback returns an async value, it is awaited and errors will be saved.
|
|
121
129
|
*/
|
|
122
|
-
send<A extends Arguments>(callback: (value: T, ...args: A) => void
|
|
130
|
+
send<A extends Arguments>(callback: (value: T, ...args: A) => void, ...args: A): Promise<boolean> | boolean;
|
|
123
131
|
/**
|
|
124
132
|
* Await an async value and save it to this store.
|
|
125
133
|
* - Saves the resolved value.
|
package/store/Store.js
CHANGED
|
@@ -26,6 +26,12 @@ import { getStarter } from "../util/start.js";
|
|
|
26
26
|
export class Store {
|
|
27
27
|
/** Deferred sequence this store uses to issue values as they change. */
|
|
28
28
|
next = new DeferredSequence();
|
|
29
|
+
/**
|
|
30
|
+
* Snapshot returns either the current reason or the current value (or `NONE` if reason is unset).
|
|
31
|
+
*/
|
|
32
|
+
get snapshot() {
|
|
33
|
+
return this._reason !== undefined ? this._reason : this._value;
|
|
34
|
+
}
|
|
29
35
|
/**
|
|
30
36
|
* Store is considered to be "loading" if it has no value or error.
|
|
31
37
|
* - Calling `this.value` will throw `this.reason` if there's an error reason set, or a `Promise` if there's no value set.
|
|
@@ -165,6 +171,7 @@ export class Store {
|
|
|
165
171
|
}
|
|
166
172
|
/**
|
|
167
173
|
* Call a callback and save the returned value to this store.
|
|
174
|
+
* - If the callback returns an async value, it is awaited and values/errors will be saved.
|
|
168
175
|
*/
|
|
169
176
|
call(callback, ...args) {
|
|
170
177
|
try {
|
|
@@ -181,18 +188,21 @@ export class Store {
|
|
|
181
188
|
}
|
|
182
189
|
/**
|
|
183
190
|
* Send the current value to a callback and save the returned value to this store.
|
|
191
|
+
* - If the callback returns an async value, it is awaited and values/errors will be saved.
|
|
184
192
|
*/
|
|
185
193
|
reduce(reducer, ...args) {
|
|
186
194
|
return this.call(reducer, this.value, ...args);
|
|
187
195
|
}
|
|
188
196
|
/**
|
|
189
197
|
* Run a callback and ignore any returned value.
|
|
198
|
+
* - If the callback returns an async value, it is awaited and errors will be saved.
|
|
190
199
|
*/
|
|
191
200
|
run(callback, ...args) {
|
|
192
201
|
return this.call(_callSkipped, callback, ...args);
|
|
193
202
|
}
|
|
194
203
|
/**
|
|
195
204
|
* Send the current value to a callback and ignore any returned value.
|
|
205
|
+
* - If the callback returns an async value, it is awaited and errors will be saved.
|
|
196
206
|
*/
|
|
197
207
|
send(callback, ...args) {
|
|
198
208
|
return this.call(_callSkipped, callback, this.value, ...args);
|