@livequery/react 1.0.88 → 1.0.91
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.
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { LivequeryBaseEntity, QueryOption } from "@livequery/types";
|
|
2
|
-
import { CollectionOption, SmartQueryItem } from "@livequery/client";
|
|
3
|
-
import { Subject } from 'rxjs';
|
|
2
|
+
import { CollectionObservable, CollectionOption, SmartQueryItem } from "@livequery/client";
|
|
4
3
|
export type useCollectionDataOptions<T extends LivequeryBaseEntity = LivequeryBaseEntity> = CollectionOption<T> & {
|
|
5
4
|
lazy?: boolean;
|
|
6
5
|
filters: Partial<QueryOption<T>>;
|
|
@@ -8,29 +7,12 @@ export type useCollectionDataOptions<T extends LivequeryBaseEntity = LivequeryBa
|
|
|
8
7
|
};
|
|
9
8
|
export declare const useCollectionData: <T extends {
|
|
10
9
|
id: string;
|
|
11
|
-
}>(ref: string | undefined | '' | null |
|
|
10
|
+
}>(ref: string | undefined | '' | null | false, collection_options?: Partial<useCollectionDataOptions<T>>) => CollectionObservable<T> & {
|
|
12
11
|
items: SmartQueryItem<T>[];
|
|
13
|
-
|
|
14
|
-
error: import("@livequery/types").ErrorInfo | null | undefined;
|
|
12
|
+
error?: import("@livequery/types").ErrorInfo | undefined;
|
|
15
13
|
has_more: boolean;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
item: T;
|
|
21
|
-
};
|
|
22
|
-
}>(payload: Partial<T>) => Promise<R>;
|
|
23
|
-
fetch_more: () => void;
|
|
24
|
-
filter: (filters: Partial<QueryOption<T>>) => void;
|
|
25
|
-
reload: () => void;
|
|
26
|
-
reset: () => void;
|
|
27
|
-
trigger: <R_1>(name: string, payload?: object | undefined, trigger_document_id?: string | undefined, query?: {
|
|
28
|
-
[key: string]: string | number | boolean;
|
|
29
|
-
} | undefined) => Promise<R_1 | undefined>;
|
|
30
|
-
update: <R_2 = {
|
|
31
|
-
data: {
|
|
32
|
-
item: T;
|
|
33
|
-
};
|
|
34
|
-
}>({ id: update_payload_id, ...payload }: Partial<T>) => Promise<R_2 | undefined>;
|
|
35
|
-
$changes: Subject<import("@livequery/types").UpdatedData<T>>;
|
|
14
|
+
loading?: boolean | undefined;
|
|
15
|
+
options: Partial<QueryOption<T>>;
|
|
16
|
+
} & {
|
|
17
|
+
empty: boolean | "" | null | undefined;
|
|
36
18
|
};
|
|
@@ -3,16 +3,14 @@ import { useEffect, useMemo } from "react";
|
|
|
3
3
|
import { useLiveQueryContext } from "./LiveQueryContext";
|
|
4
4
|
import { useObservable } from "./useObservable";
|
|
5
5
|
import { CollectionObservable } from "@livequery/client";
|
|
6
|
-
import { Subject } from 'rxjs';
|
|
7
6
|
function assert(fn, thiss) {
|
|
8
7
|
return (fn || (() => { })).bind(thiss);
|
|
9
8
|
}
|
|
10
9
|
export const useCollectionData = (ref, collection_options = {}) => {
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const { loading, has_more, error, items, options } = data;
|
|
10
|
+
const { transporter } = useLiveQueryContext();
|
|
11
|
+
const client = useMemo(() => new CollectionObservable(ref, { transporter, ...collection_options }), [ref]);
|
|
12
|
+
const stream = useObservable(client, { options: {}, items: [], has_more: false, loading: false, error: undefined });
|
|
13
|
+
const { loading, has_more, items } = stream;
|
|
16
14
|
useEffect(() => {
|
|
17
15
|
try {
|
|
18
16
|
ref && !collection_options?.lazy && client?.fetch_more();
|
|
@@ -21,24 +19,9 @@ export const useCollectionData = (ref, collection_options = {}) => {
|
|
|
21
19
|
}
|
|
22
20
|
}, [ref]);
|
|
23
21
|
useEffect(() => {
|
|
24
|
-
|
|
22
|
+
collection_options.load_all && !loading && has_more && items.length > 0 && client?.fetch_more();
|
|
25
23
|
}, [loading]);
|
|
26
|
-
return {
|
|
27
|
-
items
|
|
28
|
-
|
|
29
|
-
error,
|
|
30
|
-
has_more,
|
|
31
|
-
empty: ref && !error && items.length == 0 && loading === false,
|
|
32
|
-
filters: (options || {}),
|
|
33
|
-
add: assert(client?.add, client),
|
|
34
|
-
fetch_more: () => {
|
|
35
|
-
alert('Fetch more');
|
|
36
|
-
},
|
|
37
|
-
filter: assert(client?.filter, client),
|
|
38
|
-
reload: assert(client?.reload, client),
|
|
39
|
-
reset: assert(client?.reset, client),
|
|
40
|
-
trigger: assert(client?.trigger, client),
|
|
41
|
-
update: assert(client?.update, client),
|
|
42
|
-
$changes: client?.$changes || new Subject()
|
|
43
|
-
};
|
|
24
|
+
return Object.assign(client, stream, {
|
|
25
|
+
empty: ref && !stream.error && stream.items.length == 0 && !stream.loading
|
|
26
|
+
});
|
|
44
27
|
};
|
|
@@ -5,10 +5,10 @@ export type useDocumentDataOptions<T extends LivequeryBaseEntity = LivequeryBase
|
|
|
5
5
|
};
|
|
6
6
|
export declare const useDocumentData: <T extends {
|
|
7
7
|
id: string;
|
|
8
|
-
}>(ref: string | undefined | '' | null |
|
|
8
|
+
}>(ref: string | undefined | '' | null | false, options?: useDocumentDataOptions) => {
|
|
9
9
|
item: import("@livequery/client").SmartQueryItem<T>;
|
|
10
10
|
loading: boolean | undefined;
|
|
11
|
-
error: import("@livequery/types").ErrorInfo |
|
|
11
|
+
error: import("@livequery/types").ErrorInfo | undefined;
|
|
12
12
|
reload: () => void;
|
|
13
13
|
$changes: import("rxjs").Subject<import("@livequery/types").UpdatedData<T>>;
|
|
14
14
|
};
|
package/build/useObservable.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Observable } from 'rxjs';
|
|
2
|
-
export declare const useObservable: <T>(o: Observable<T> | null, default_value
|
|
2
|
+
export declare const useObservable: <T>(o: Observable<T> | null, default_value: T) => T;
|
package/build/useObservable.js
CHANGED
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"url": "https://github.com/livequery/react"
|
|
5
5
|
},
|
|
6
6
|
"type": "module",
|
|
7
|
-
"version": "1.0.
|
|
7
|
+
"version": "1.0.91",
|
|
8
8
|
"description": "",
|
|
9
9
|
"main": "build/index.js",
|
|
10
10
|
"types": "build/index.d.ts",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"react": "^17.0.2"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
|
-
"react": "^
|
|
23
|
+
"react": "^18.0.0"
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
26
|
"test": "echo \"Error: no test specified\" && exit 1",
|