@livequery/react 1.0.110 → 2.0.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/build/LiveQueryContext.d.ts +0 -1
- package/build/hooks/createContextFromHook.d.ts +1 -1
- package/build/hooks/createStaticContext.d.ts +0 -1
- package/build/useCollectionData.d.ts +6 -6
- package/build/useCollectionData.js +9 -5
- package/build/useDocumentData.d.ts +5 -9
- package/build/useDocumentData.js +2 -2
- package/package.json +6 -4
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import React, { PropsWithChildren } from 'react';
|
|
2
|
-
export declare const createContextFromHook: <T, K>(fn: ((props: T) => K) | (() => K)) => [() => K, ({ children, ...props }:
|
|
2
|
+
export declare const createContextFromHook: <T, K>(fn: ((props: T) => K) | (() => K)) => [() => K, ({ children, ...props }: PropsWithChildren<T>) => React.JSX.Element];
|
|
@@ -2,14 +2,14 @@ import { LivequeryBaseEntity, QueryOption } from "@livequery/types";
|
|
|
2
2
|
import { CollectionObservable, CollectionOption, CollectionStream } from "@livequery/client";
|
|
3
3
|
export type useCollectionDataOptions<T extends LivequeryBaseEntity = LivequeryBaseEntity> = CollectionOption<T> & {
|
|
4
4
|
lazy?: boolean;
|
|
5
|
-
|
|
5
|
+
options: Partial<QueryOption<T>>;
|
|
6
6
|
load_all: boolean;
|
|
7
7
|
};
|
|
8
|
-
export type
|
|
8
|
+
export type CollectionRef = string | undefined | '' | null | false;
|
|
9
|
+
export type CollectionData<T extends LivequeryBaseEntity> = (CollectionStream<T> & Pick<CollectionObservable<T>, 'add' | 'fetch_more' | 'fetch_prev' | 'reset' | 'trigger' | 'update' | '$changes' | 'filter'> & {
|
|
9
10
|
empty: boolean;
|
|
10
11
|
loaded: boolean;
|
|
12
|
+
ref: CollectionRef;
|
|
13
|
+
filters: CollectionStream<T>['options'];
|
|
11
14
|
});
|
|
12
|
-
export
|
|
13
|
-
export declare const useCollectionData: <T extends LivequeryBaseEntity>(ref: CollectionRef, collection_options?: Partial<useCollectionDataOptions<T>> & {
|
|
14
|
-
vkl?: any;
|
|
15
|
-
}) => CollectionData<T>;
|
|
15
|
+
export declare const useCollectionData: <T extends LivequeryBaseEntity>(ref: CollectionRef, collection_options?: Partial<useCollectionDataOptions<T>>) => CollectionData<T>;
|
|
@@ -11,12 +11,12 @@ export const useCollectionData = (ref, collection_options = {}) => {
|
|
|
11
11
|
const { transporter } = useLiveQueryContext();
|
|
12
12
|
const n = useRef(0);
|
|
13
13
|
const lazy = collection_options.lazy;
|
|
14
|
-
const [
|
|
14
|
+
const [, set_version] = useState(0);
|
|
15
15
|
const client = useSyncMemo(() => {
|
|
16
16
|
const client = new CollectionObservable(ref, { transporter, ...collection_options });
|
|
17
17
|
n.current = 0;
|
|
18
18
|
const subscription = client.subscribe(data => {
|
|
19
|
-
if (collection_options.load_all && data.
|
|
19
|
+
if (collection_options.load_all && data.paging.has?.next) {
|
|
20
20
|
client.fetch_more();
|
|
21
21
|
}
|
|
22
22
|
else {
|
|
@@ -30,19 +30,23 @@ export const useCollectionData = (ref, collection_options = {}) => {
|
|
|
30
30
|
return [client, () => subscription.unsubscribe()];
|
|
31
31
|
}, [ref]);
|
|
32
32
|
const loaded = n.current > 0;
|
|
33
|
-
const
|
|
33
|
+
const $ = client.$.getValue();
|
|
34
|
+
const empty = loaded && !$.loading && $.items.length == 0;
|
|
34
35
|
const result = {
|
|
35
|
-
|
|
36
|
+
...$,
|
|
36
37
|
loaded,
|
|
37
38
|
empty,
|
|
39
|
+
filters: $.options,
|
|
38
40
|
add: assert(client?.add, client),
|
|
39
41
|
fetch_more: assert(client?.fetch_more, client),
|
|
42
|
+
fetch_prev: assert(client?.fetch_prev, client),
|
|
40
43
|
filter: assert(client?.filter, client),
|
|
41
|
-
|
|
44
|
+
// fetch_around_cursor: assert(client?.fetch_around_cursor, client),
|
|
42
45
|
reset: assert(client?.reset, client),
|
|
43
46
|
trigger: assert(client?.trigger, client),
|
|
44
47
|
update: assert(client?.update, client),
|
|
45
48
|
$changes: client?.$changes || new Subject(),
|
|
49
|
+
ref
|
|
46
50
|
};
|
|
47
51
|
return result;
|
|
48
52
|
};
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useCollectionDataOptions } from "./useCollectionData.js";
|
|
2
2
|
import { LivequeryBaseEntity } from "@livequery/types";
|
|
3
|
-
export type useDocumentDataOptions<T extends LivequeryBaseEntity = LivequeryBaseEntity> = Omit<
|
|
4
|
-
|
|
5
|
-
};
|
|
6
|
-
export declare const useDocumentData: <T extends {
|
|
7
|
-
id: string;
|
|
8
|
-
}>(ref: string | undefined | '' | null | false, options?: useDocumentDataOptions) => {
|
|
3
|
+
export type useDocumentDataOptions<T extends LivequeryBaseEntity = LivequeryBaseEntity> = Partial<Omit<useCollectionDataOptions<T>, 'filters'>>;
|
|
4
|
+
export declare const useDocumentData: <T extends LivequeryBaseEntity>(ref: string | undefined | "" | null | false, config?: useDocumentDataOptions<T>) => {
|
|
9
5
|
item: import("@livequery/client").SmartQueryItem<T>;
|
|
10
|
-
loading:
|
|
11
|
-
error:
|
|
6
|
+
loading: import("@livequery/client").LoadingIndicator | undefined;
|
|
7
|
+
error: boolean | undefined;
|
|
12
8
|
$changes: import("rxjs").Subject<import("@livequery/types").UpdatedData<T>>;
|
|
13
9
|
};
|
package/build/useDocumentData.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useCollectionData } from "./useCollectionData.js";
|
|
3
|
-
export const useDocumentData = (ref,
|
|
4
|
-
const { items, loading, error, $changes } = useCollectionData(ref,
|
|
3
|
+
export const useDocumentData = (ref, config = {}) => {
|
|
4
|
+
const { items, loading, error, $changes } = useCollectionData(ref, config);
|
|
5
5
|
return {
|
|
6
6
|
item: items[0],
|
|
7
7
|
loading,
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"url": "https://github.com/livequery/react"
|
|
5
5
|
},
|
|
6
6
|
"type": "module",
|
|
7
|
-
"version": "
|
|
7
|
+
"version": "2.0.0",
|
|
8
8
|
"description": "",
|
|
9
9
|
"main": "build/index.js",
|
|
10
10
|
"types": "build/index.d.ts",
|
|
@@ -12,12 +12,14 @@
|
|
|
12
12
|
"build/**/*"
|
|
13
13
|
],
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@livequery/client": "^
|
|
15
|
+
"@livequery/client": "^2.0.0",
|
|
16
|
+
"rxjs": "^7.8.1"
|
|
16
17
|
},
|
|
17
18
|
"devDependencies": {
|
|
18
|
-
"@livequery/types": "^
|
|
19
|
+
"@livequery/types": "^2.0.0",
|
|
19
20
|
"@types/react": "^17.0.11",
|
|
20
|
-
"react": "^17.0.2"
|
|
21
|
+
"react": "^17.0.2",
|
|
22
|
+
"typescript": "5.5.2"
|
|
21
23
|
},
|
|
22
24
|
"peerDependencies": {
|
|
23
25
|
"react": "^18.0.0"
|