@cripty2001/utils 0.0.167 → 0.0.168
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/dist/react-whispr.d.ts +2 -1
- package/dist/react-whispr.js +8 -3
- package/package.json +1 -1
package/dist/react-whispr.d.ts
CHANGED
|
@@ -161,6 +161,7 @@ export type AsyncInputValue<C extends Record<string, JSONEncodable>, R extends R
|
|
|
161
161
|
* @param value - Current external value containing both result data and metadata with config/timestamp. Metadata should be considered opaque, and always carried araoud as they are
|
|
162
162
|
* @param setValue - Callback to update external value when async operations complete
|
|
163
163
|
* @param handler - Async function that computes results from config.
|
|
164
|
+
* @param setPending? - Callback to check if the async operation is in flight or ended. If this is called with false, setValue has already been called with the latest result. To avoid concurrency problems, setValue is always called BEFORE calling this with false. No assumption be made for call with true. Please note that this function may be called rapidly even without real updates. The only assumption that should be made about this is the fact that once it is called with false, the value is guaranteed to be the latest reported one, until a call with true. A call with true may means that the value is outdated, or maybe no. There is simply no guarantee about the result when this value is true.
|
|
164
165
|
*
|
|
165
166
|
* @returns Array containing:
|
|
166
167
|
* - `value`: Current config (updates synchronously with user input)
|
|
@@ -193,7 +194,7 @@ export type AsyncInputValue<C extends Record<string, JSONEncodable>, R extends R
|
|
|
193
194
|
* The returned `result` will lag behind `value` during async processing. Consider showing a loader or some other similar indication
|
|
194
195
|
* Handler is NOT reactive. Conceptually it is a pure function that derives an async status from the value input, so there is no reason for it to be reactive, and this saves a lot heachaches with react reactivity loops.
|
|
195
196
|
*/
|
|
196
|
-
export declare function useAsyncInput<C extends Record<string, JSONEncodable>, R extends Record<string, JSONEncodable>>(value: AsyncInputValue<C, R>, setValue: (value: AsyncInputValue<C, R>) => void, handler: (config: C) => Promise<R
|
|
197
|
+
export declare function useAsyncInput<C extends Record<string, JSONEncodable>, R extends Record<string, JSONEncodable>>(value: AsyncInputValue<C, R>, setValue: (value: AsyncInputValue<C, R>) => void, handler: (config: C) => Promise<R>, setPending: (pending: boolean) => void): [
|
|
197
198
|
value: C,
|
|
198
199
|
setValue: (updater: (draft: C) => C | void) => void,
|
|
199
200
|
result: R | null
|
package/dist/react-whispr.js
CHANGED
|
@@ -321,6 +321,7 @@ function useSafeRef(value) {
|
|
|
321
321
|
* @param value - Current external value containing both result data and metadata with config/timestamp. Metadata should be considered opaque, and always carried araoud as they are
|
|
322
322
|
* @param setValue - Callback to update external value when async operations complete
|
|
323
323
|
* @param handler - Async function that computes results from config.
|
|
324
|
+
* @param setPending? - Callback to check if the async operation is in flight or ended. If this is called with false, setValue has already been called with the latest result. To avoid concurrency problems, setValue is always called BEFORE calling this with false. No assumption be made for call with true. Please note that this function may be called rapidly even without real updates. The only assumption that should be made about this is the fact that once it is called with false, the value is guaranteed to be the latest reported one, until a call with true. A call with true may means that the value is outdated, or maybe no. There is simply no guarantee about the result when this value is true.
|
|
324
325
|
*
|
|
325
326
|
* @returns Array containing:
|
|
326
327
|
* - `value`: Current config (updates synchronously with user input)
|
|
@@ -353,11 +354,14 @@ function useSafeRef(value) {
|
|
|
353
354
|
* The returned `result` will lag behind `value` during async processing. Consider showing a loader or some other similar indication
|
|
354
355
|
* Handler is NOT reactive. Conceptually it is a pure function that derives an async status from the value input, so there is no reason for it to be reactive, and this saves a lot heachaches with react reactivity loops.
|
|
355
356
|
*/
|
|
356
|
-
function useAsyncInput(value, setValue, handler) {
|
|
357
|
+
function useAsyncInput(value, setValue, handler, setPending) {
|
|
357
358
|
const [meta, setMeta] = (0, react_1.useState)({
|
|
358
359
|
config: value._meta.config,
|
|
359
360
|
ts: value._meta.ts
|
|
360
361
|
});
|
|
362
|
+
(0, react_1.useEffect)(() => {
|
|
363
|
+
setPending(true);
|
|
364
|
+
}, [meta, setPending]);
|
|
361
365
|
(0, react_1.useEffect)(() => {
|
|
362
366
|
if (value._meta.ts > meta.ts) {
|
|
363
367
|
setMeta(value._meta);
|
|
@@ -378,9 +382,10 @@ function useAsyncInput(value, setValue, handler) {
|
|
|
378
382
|
if (result === null)
|
|
379
383
|
return;
|
|
380
384
|
if (result._meta.ts <= value._meta.ts)
|
|
381
|
-
return;
|
|
385
|
+
return setPending(false); // Value is already updated, but we still need to clear the pending state. Also, we can't just update the value, as it will cause loops.
|
|
382
386
|
setValue(result);
|
|
383
|
-
|
|
387
|
+
setPending(false);
|
|
388
|
+
}, [result, value, setValue, setPending]);
|
|
384
389
|
const returnedSetValue = (0, react_1.useCallback)((updater) => {
|
|
385
390
|
const cloned = structuredClone(meta.config);
|
|
386
391
|
const new_data = updater(cloned);
|
package/package.json
CHANGED