@livequery/react 1.0.93 → 1.0.95

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.
@@ -8,6 +8,7 @@ export type useCollectionDataOptions<T extends LivequeryBaseEntity = LivequeryBa
8
8
  export declare const useCollectionData: <T extends {
9
9
  id: string;
10
10
  }>(ref: string | undefined | '' | null | false, collection_options?: Partial<useCollectionDataOptions<T>>) => {
11
+ filters: Partial<QueryOption<T>>;
11
12
  loading: boolean;
12
13
  empty: boolean;
13
14
  add: <R = {
@@ -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, { options: {}, items: [], has_more: false, loading: false, error: undefined });
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,10 +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,
33
+ filters: stream.options,
26
34
  loading: !!stream.loading,
27
- empty: !!(ref && !error && items.length == 0 && loading === false),
35
+ empty,
28
36
  add: assert(client?.add, client),
29
37
  fetch_more: assert(client?.fetch_more, client),
30
38
  filter: assert(client?.filter, client),
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.93",
7
+ "version": "1.0.95",
8
8
  "description": "",
9
9
  "main": "build/index.js",
10
10
  "types": "build/index.d.ts",