@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.
@@ -1,3 +1,3 @@
1
1
  "use client";
2
- import { createContextFromHook } from './hooks/createContextFromHook';
2
+ import { createContextFromHook } from './hooks/createContextFromHook.js';
3
3
  export const [useLiveQueryContext, LiveQueryContextProvider] = createContextFromHook((props) => props);
@@ -1,3 +1,3 @@
1
1
  "use client";
2
- import { createContextFromHook } from './createContextFromHook';
2
+ import { createContextFromHook } from './createContextFromHook.js';
3
3
  export const createStaticContext = () => createContextFromHook((props) => props.value);
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, { 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,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: !!(ref && !error && items.length == 0 && loading === false),
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),
@@ -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.94",
7
+ "version": "1.0.96",
8
8
  "description": "",
9
9
  "main": "build/index.js",
10
10
  "types": "build/index.d.ts",