@livequery/react 1.0.105 → 1.0.106

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.
@@ -13,29 +13,30 @@ export const useCollectionData = (ref, collection_options = {}) => {
13
13
  items: [],
14
14
  has_more: false,
15
15
  loading: collection_options.lazy ? false : !!ref,
16
- error: undefined
16
+ error: undefined,
17
+ loaded: false
17
18
  });
18
- const [n, sn] = useState(0);
19
+ const n = useRef(0);
19
20
  const collection_ref = useRef();
20
21
  useEffect(() => {
21
22
  if (!ref || typeof window == 'undefined')
22
23
  return;
23
24
  const collection = collection_ref.current = new CollectionObservable(ref, { transporter, ...collection_options });
25
+ n.current = 0;
24
26
  const subscription = collection.subscribe(data => {
25
27
  collection_options.load_all && data.loading == false && data.has_more && collection?.fetch_more();
26
- ss(data);
27
- sn(Math.random());
28
+ n.current++;
29
+ ss({ ...data, loaded: true });
28
30
  });
29
31
  !collection_options?.lazy && collection?.fetch_more();
30
32
  return () => subscription.unsubscribe();
31
33
  }, [ref, collection_options?.lazy]);
32
34
  const client = collection_ref.current;
33
- const loaded = n > 0;
34
- const empty = loaded && !stream.loading && stream.items.length == 0;
35
+ const empty = stream.loaded && !stream.loading && stream.items.length == 0;
35
36
  const result = {
36
37
  ...stream,
37
38
  error: stream.error,
38
- loading: !!stream.loading,
39
+ loading: !!stream.loading || (!collection_options?.lazy && !!ref && n.current == 0),
39
40
  empty,
40
41
  add: assert(client?.add, client),
41
42
  fetch_more: assert(client?.fetch_more, client),
@@ -45,7 +46,6 @@ export const useCollectionData = (ref, collection_options = {}) => {
45
46
  trigger: assert(client?.trigger, client),
46
47
  update: assert(client?.update, client),
47
48
  $changes: client?.$changes || new Subject(),
48
- loaded
49
49
  };
50
50
  return result;
51
51
  };
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.105",
7
+ "version": "1.0.106",
8
8
  "description": "",
9
9
  "main": "build/index.js",
10
10
  "types": "build/index.d.ts",