@livequery/react 1.0.94 → 1.0.96
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/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,7 +1,7 @@
|
|
|
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
6
|
function assert(fn, thiss) {
|
|
7
7
|
return (fn || (() => { })).bind(thiss);
|
|
@@ -9,7 +9,13 @@ function assert(fn, thiss) {
|
|
|
9
9
|
export const useCollectionData = (ref, collection_options = {}) => {
|
|
10
10
|
const { transporter } = useLiveQueryContext();
|
|
11
11
|
const client = useMemo(() => new CollectionObservable(ref, { transporter, ...collection_options }), [ref]);
|
|
12
|
-
const stream = useObservable(client, {
|
|
12
|
+
const stream = useObservable(client, {
|
|
13
|
+
options: {},
|
|
14
|
+
items: [],
|
|
15
|
+
has_more: false,
|
|
16
|
+
loading: collection_options.lazy ? false : true,
|
|
17
|
+
error: undefined
|
|
18
|
+
});
|
|
13
19
|
const { loading, has_more, items, error } = stream;
|
|
14
20
|
useEffect(() => {
|
|
15
21
|
try {
|
|
@@ -21,11 +27,12 @@ export const useCollectionData = (ref, collection_options = {}) => {
|
|
|
21
27
|
useEffect(() => {
|
|
22
28
|
collection_options.load_all && !loading && has_more && items.length > 0 && client?.fetch_more();
|
|
23
29
|
}, [loading]);
|
|
30
|
+
const empty = !!(ref && !error && items.length == 0 && !loading);
|
|
24
31
|
return {
|
|
25
32
|
...stream,
|
|
26
33
|
filters: stream.options,
|
|
27
34
|
loading: !!stream.loading,
|
|
28
|
-
empty
|
|
35
|
+
empty,
|
|
29
36
|
add: assert(client?.add, client),
|
|
30
37
|
fetch_more: assert(client?.fetch_more, client),
|
|
31
38
|
filter: assert(client?.filter, client),
|
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 {
|