@livequery/react 1.0.95 → 1.0.97
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.js +1 -1
- package/build/hooks/createStaticContext.js +1 -1
- package/build/index.d.ts +6 -6
- package/build/index.js +6 -6
- package/build/useCollectionData.d.ts +5 -29
- package/build/useCollectionData.js +23 -5
- package/build/useDocumentData.d.ts +1 -1
- package/build/useDocumentData.js +1 -1
- package/package.json +2 -2
package/build/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from "./useDocumentData";
|
|
2
|
-
export * from './useCollectionData';
|
|
3
|
-
export * from './useMonitor';
|
|
4
|
-
export * from "./LiveQueryContext";
|
|
5
|
-
export * from './hooks/createContextFromHook';
|
|
6
|
-
export * from './hooks/createStaticContext';
|
|
1
|
+
export * from "./useDocumentData.js";
|
|
2
|
+
export * from './useCollectionData.js';
|
|
3
|
+
export * from './useMonitor.js';
|
|
4
|
+
export * from "./LiveQueryContext.js";
|
|
5
|
+
export * from './hooks/createContextFromHook.js';
|
|
6
|
+
export * from './hooks/createStaticContext.js';
|
package/build/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from "./useDocumentData";
|
|
2
|
-
export * from './useCollectionData';
|
|
3
|
-
export * from './useMonitor';
|
|
4
|
-
export * from "./LiveQueryContext";
|
|
5
|
-
export * from './hooks/createContextFromHook';
|
|
6
|
-
export * from './hooks/createStaticContext';
|
|
1
|
+
export * from "./useDocumentData.js";
|
|
2
|
+
export * from './useCollectionData.js';
|
|
3
|
+
export * from './useMonitor.js';
|
|
4
|
+
export * from "./LiveQueryContext.js";
|
|
5
|
+
export * from './hooks/createContextFromHook.js';
|
|
6
|
+
export * from './hooks/createStaticContext.js';
|
|
@@ -1,36 +1,12 @@
|
|
|
1
1
|
import { LivequeryBaseEntity, QueryOption } from "@livequery/types";
|
|
2
|
-
import { CollectionOption } from "@livequery/client";
|
|
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
|
filters: Partial<QueryOption<T>>;
|
|
6
6
|
load_all: boolean;
|
|
7
7
|
};
|
|
8
|
-
export
|
|
9
|
-
id: string;
|
|
10
|
-
}>(ref: string | undefined | '' | null | false, collection_options?: Partial<useCollectionDataOptions<T>>) => {
|
|
11
|
-
filters: Partial<QueryOption<T>>;
|
|
12
|
-
loading: boolean;
|
|
8
|
+
export type CollectionData<T extends LivequeryBaseEntity> = (CollectionStream<T> & Pick<CollectionObservable<T>, 'add' | 'fetch_more' | 'filter' | 'reload' | 'reset' | 'trigger' | 'update' | '$changes'> & {
|
|
13
9
|
empty: boolean;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
};
|
|
18
|
-
}>(payload: Partial<T>) => Promise<R>;
|
|
19
|
-
fetch_more: () => void;
|
|
20
|
-
filter: (filters: Partial<QueryOption<T>>) => void;
|
|
21
|
-
reload: () => void;
|
|
22
|
-
reset: () => void;
|
|
23
|
-
trigger: <R_1>(name: string, payload?: object | undefined, trigger_document_id?: string | undefined, query?: {
|
|
24
|
-
[key: string]: string | number | boolean;
|
|
25
|
-
} | undefined) => Promise<R_1 | undefined>;
|
|
26
|
-
update: <R_2 = {
|
|
27
|
-
data: {
|
|
28
|
-
item: T;
|
|
29
|
-
};
|
|
30
|
-
}>({ id: update_payload_id, ...payload }: Partial<T>) => Promise<R_2 | undefined>;
|
|
31
|
-
$changes: import("rxjs").Subject<import("@livequery/types").UpdatedData<T>>;
|
|
32
|
-
items: import("@livequery/client").SmartQueryItem<T>[];
|
|
33
|
-
error?: import("@livequery/types").ErrorInfo | undefined;
|
|
34
|
-
has_more: boolean;
|
|
35
|
-
options: Partial<QueryOption<T>>;
|
|
36
|
-
};
|
|
10
|
+
});
|
|
11
|
+
export type CollectionRef = string | undefined | '' | null | false;
|
|
12
|
+
export declare const useCollectionData: <T extends LivequeryBaseEntity>(ref: CollectionRef, collection_options?: Partial<useCollectionDataOptions<T>>) => CollectionData<T>;
|
|
@@ -1,16 +1,34 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useEffect, useMemo } from "react";
|
|
3
|
-
import { useLiveQueryContext } from "./LiveQueryContext";
|
|
4
|
-
import { useObservable } from "./useObservable";
|
|
3
|
+
import { useLiveQueryContext } from "./LiveQueryContext.js";
|
|
4
|
+
import { useObservable } from "./useObservable.js";
|
|
5
5
|
import { CollectionObservable } from "@livequery/client";
|
|
6
|
+
import { Subject } from 'rxjs';
|
|
6
7
|
function assert(fn, thiss) {
|
|
7
8
|
return (fn || (() => { })).bind(thiss);
|
|
8
9
|
}
|
|
9
10
|
export const useCollectionData = (ref, collection_options = {}) => {
|
|
11
|
+
if (typeof window == 'undefined') {
|
|
12
|
+
return {
|
|
13
|
+
$changes: new Subject(),
|
|
14
|
+
add: (() => { }),
|
|
15
|
+
empty: false,
|
|
16
|
+
filter: (() => { }),
|
|
17
|
+
fetch_more: (() => { }),
|
|
18
|
+
filters: {},
|
|
19
|
+
has_more: false,
|
|
20
|
+
items: [],
|
|
21
|
+
reload: (() => { }),
|
|
22
|
+
reset: (() => { }),
|
|
23
|
+
trigger: (() => { }),
|
|
24
|
+
update: (() => { }),
|
|
25
|
+
loading: false
|
|
26
|
+
};
|
|
27
|
+
}
|
|
10
28
|
const { transporter } = useLiveQueryContext();
|
|
11
29
|
const client = useMemo(() => new CollectionObservable(ref, { transporter, ...collection_options }), [ref]);
|
|
12
30
|
const stream = useObservable(client, {
|
|
13
|
-
|
|
31
|
+
filters: {},
|
|
14
32
|
items: [],
|
|
15
33
|
has_more: false,
|
|
16
34
|
loading: collection_options.lazy ? false : true,
|
|
@@ -28,9 +46,8 @@ export const useCollectionData = (ref, collection_options = {}) => {
|
|
|
28
46
|
collection_options.load_all && !loading && has_more && items.length > 0 && client?.fetch_more();
|
|
29
47
|
}, [loading]);
|
|
30
48
|
const empty = !!(ref && !error && items.length == 0 && !loading);
|
|
31
|
-
|
|
49
|
+
const result = {
|
|
32
50
|
...stream,
|
|
33
|
-
filters: stream.options,
|
|
34
51
|
loading: !!stream.loading,
|
|
35
52
|
empty,
|
|
36
53
|
add: assert(client?.add, client),
|
|
@@ -42,4 +59,5 @@ export const useCollectionData = (ref, collection_options = {}) => {
|
|
|
42
59
|
update: assert(client?.update, client),
|
|
43
60
|
$changes: client?.$changes
|
|
44
61
|
};
|
|
62
|
+
return result;
|
|
45
63
|
};
|
|
@@ -7,7 +7,7 @@ export declare const useDocumentData: <T extends {
|
|
|
7
7
|
id: string;
|
|
8
8
|
}>(ref: string | undefined | '' | null | false, options?: useDocumentDataOptions) => {
|
|
9
9
|
item: import("@livequery/client").SmartQueryItem<T>;
|
|
10
|
-
loading: boolean;
|
|
10
|
+
loading: boolean | undefined;
|
|
11
11
|
error: import("@livequery/types").ErrorInfo | undefined;
|
|
12
12
|
reload: () => void;
|
|
13
13
|
$changes: import("rxjs").Subject<import("@livequery/types").UpdatedData<T>>;
|
package/build/useDocumentData.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useCollectionData } from "./useCollectionData";
|
|
2
|
+
import { useCollectionData } from "./useCollectionData.js";
|
|
3
3
|
export const useDocumentData = (ref, options) => {
|
|
4
4
|
const { items, loading, error, reload, $changes } = useCollectionData(ref, options);
|
|
5
5
|
return {
|
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.97",
|
|
8
8
|
"description": "",
|
|
9
9
|
"main": "build/index.js",
|
|
10
10
|
"types": "build/index.d.ts",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"build/**/*"
|
|
13
13
|
],
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@livequery/client": "^1.0.
|
|
15
|
+
"@livequery/client": "^1.0.93"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"@livequery/types": "^1.0.82",
|