@cripty2001/utils 0.0.169 → 0.0.170
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/Dispatcher.d.ts +1 -0
- package/dist/Dispatcher.js +1 -0
- package/dist/Searcher/index.d.ts +0 -2
- package/dist/Searcher/index.js +17 -19
- package/dist/react-whispr.d.ts +6 -4
- package/dist/react-whispr.js +29 -8
- package/package.json +1 -1
package/dist/Dispatcher.d.ts
CHANGED
|
@@ -29,6 +29,7 @@ export declare class Dispatcher<I, O> {
|
|
|
29
29
|
*
|
|
30
30
|
* @remarks If the debounce interval is 0, the function will be called synchronously, as a Whispr listener would do.
|
|
31
31
|
* @remarks The value is deep checked for equality. The function will be called only if the value changed deeply
|
|
32
|
+
* @remarks Data updating flag is set in a synchronous way. This means that in the event your DEBOUNCE_INTERVAL is near infinity, you still get the data set to updating true immediately when you update the value. It just wait like this forever
|
|
32
33
|
*/
|
|
33
34
|
constructor(value: Whispr<I>, f: DispatcherFunction<I, O>, DEBOUNCE_INTERVAL?: number);
|
|
34
35
|
private reset;
|
package/dist/Dispatcher.js
CHANGED
|
@@ -21,6 +21,7 @@ class Dispatcher {
|
|
|
21
21
|
*
|
|
22
22
|
* @remarks If the debounce interval is 0, the function will be called synchronously, as a Whispr listener would do.
|
|
23
23
|
* @remarks The value is deep checked for equality. The function will be called only if the value changed deeply
|
|
24
|
+
* @remarks Data updating flag is set in a synchronous way. This means that in the event your DEBOUNCE_INTERVAL is near infinity, you still get the data set to updating true immediately when you update the value. It just wait like this forever
|
|
24
25
|
*/
|
|
25
26
|
constructor(value, f, DEBOUNCE_INTERVAL = 200) {
|
|
26
27
|
// Initing state
|
package/dist/Searcher/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Whispr } from "@cripty2001/whispr";
|
|
2
1
|
export type SearcherData<T> = {
|
|
3
2
|
queries: string[];
|
|
4
3
|
doc: T;
|
|
@@ -9,4 +8,3 @@ export declare class Searcher<T> {
|
|
|
9
8
|
search(query: string): SearcherData<T>[];
|
|
10
9
|
updateData(data: SearcherData<T>[]): void;
|
|
11
10
|
}
|
|
12
|
-
export declare function useSearcher_w<T>(data: Whispr<SearcherData<T>[]>, query: Whispr<string>): Whispr<SearcherData<T>[]>;
|
package/dist/Searcher/index.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Searcher = void 0;
|
|
4
|
-
exports.useSearcher_w = useSearcher_w;
|
|
5
|
-
const whispr_1 = require("@cripty2001/whispr");
|
|
6
4
|
class Searcher {
|
|
7
5
|
data = [];
|
|
8
6
|
constructor(data) {
|
|
@@ -18,20 +16,20 @@ class Searcher {
|
|
|
18
16
|
}
|
|
19
17
|
}
|
|
20
18
|
exports.Searcher = Searcher;
|
|
21
|
-
function useSearcher_w(data
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
19
|
+
// export function useSearcher_w<T>(data: Whispr<SearcherData<T>[]>, query: Whispr<string>): Whispr<SearcherData<T>[]> {
|
|
20
|
+
// const searcher = new Searcher<T>(data.value);
|
|
21
|
+
// let unsubscribe_q: () => void = () => { }
|
|
22
|
+
// let unsubscribe_d: () => void = () => { }
|
|
23
|
+
// const [toReturn, setToReturn] = Whispr.create<SearcherData<T>[]>([], () => {
|
|
24
|
+
// unsubscribe_q();
|
|
25
|
+
// unsubscribe_d();
|
|
26
|
+
// })
|
|
27
|
+
// unsubscribe_q = query.subscribe((q) => {
|
|
28
|
+
// let result = searcher.search(q);
|
|
29
|
+
// setToReturn(result);
|
|
30
|
+
// }, true)
|
|
31
|
+
// unsubscribe_d = data.subscribe((d) => {
|
|
32
|
+
// searcher.updateData(d);
|
|
33
|
+
// }, true)
|
|
34
|
+
// return toReturn
|
|
35
|
+
// }
|
package/dist/react-whispr.d.ts
CHANGED
|
@@ -119,11 +119,13 @@ export declare function useRelTime(_data: number | Date): string;
|
|
|
119
119
|
/**
|
|
120
120
|
* React shorthand for the Searcher
|
|
121
121
|
* @param data The data to search on
|
|
122
|
-
* @
|
|
123
|
-
*
|
|
124
|
-
*
|
|
122
|
+
* @return An arra containing
|
|
123
|
+
* - The current query (updated synchronously with the user input)
|
|
124
|
+
* - The function to set the query (aka the one to put onto the input element)
|
|
125
|
+
* - The filtered data
|
|
126
|
+
* - A boolean indicating if the search is pending
|
|
125
127
|
*/
|
|
126
|
-
export declare function useSearcher<T>(data: SearcherData<T>[], q: string)
|
|
128
|
+
export declare function useSearcher<T extends JSONEncodable>(data: SearcherData<T>[]): [string, (q: string) => void, SearcherData<T>[], boolean];
|
|
127
129
|
/**
|
|
128
130
|
* A react ref hook with safe lazy initialization, ready for safe side effects.
|
|
129
131
|
* @remarks The initialization function will only be called once, and the result will be stored in the ref.
|
package/dist/react-whispr.js
CHANGED
|
@@ -274,15 +274,36 @@ function getRelTimeFormat(_diff) {
|
|
|
274
274
|
/**
|
|
275
275
|
* React shorthand for the Searcher
|
|
276
276
|
* @param data The data to search on
|
|
277
|
-
* @
|
|
278
|
-
*
|
|
279
|
-
*
|
|
277
|
+
* @return An arra containing
|
|
278
|
+
* - The current query (updated synchronously with the user input)
|
|
279
|
+
* - The function to set the query (aka the one to put onto the input element)
|
|
280
|
+
* - The filtered data
|
|
281
|
+
* - A boolean indicating if the search is pending
|
|
280
282
|
*/
|
|
281
|
-
function useSearcher(data
|
|
282
|
-
const
|
|
283
|
-
const
|
|
284
|
-
|
|
285
|
-
|
|
283
|
+
function useSearcher(data) {
|
|
284
|
+
const [pending, setPending] = (0, react_1.useState)(false);
|
|
285
|
+
const [results, setResults] = (0, react_1.useState)({
|
|
286
|
+
results: [],
|
|
287
|
+
_meta: {
|
|
288
|
+
ts: 0,
|
|
289
|
+
config: { q: "" }
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
const searcher = (0, react_1.useRef)(new Searcher_1.Searcher(data));
|
|
293
|
+
(0, react_1.useEffect)(() => {
|
|
294
|
+
searcher.current.updateData(data);
|
|
295
|
+
}, [data]);
|
|
296
|
+
const [q, setQ] = useAsyncInput(results, setResults, async ({ q }) => {
|
|
297
|
+
return {
|
|
298
|
+
results: searcher.current.search(q)
|
|
299
|
+
};
|
|
300
|
+
}, setPending);
|
|
301
|
+
return [
|
|
302
|
+
q.q,
|
|
303
|
+
(q) => setQ(draft => { draft.q = q; }),
|
|
304
|
+
results.results,
|
|
305
|
+
pending
|
|
306
|
+
];
|
|
286
307
|
}
|
|
287
308
|
/**
|
|
288
309
|
* A react ref hook with safe lazy initialization, ready for safe side effects.
|
package/package.json
CHANGED