@livequery/react 1.0.91 → 1.0.93

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,5 +1,5 @@
1
1
  import { LivequeryBaseEntity, QueryOption } from "@livequery/types";
2
- import { CollectionObservable, CollectionOption, SmartQueryItem } from "@livequery/client";
2
+ import { CollectionOption } from "@livequery/client";
3
3
  export type useCollectionDataOptions<T extends LivequeryBaseEntity = LivequeryBaseEntity> = CollectionOption<T> & {
4
4
  lazy?: boolean;
5
5
  filters: Partial<QueryOption<T>>;
@@ -7,12 +7,29 @@ export type useCollectionDataOptions<T extends LivequeryBaseEntity = LivequeryBa
7
7
  };
8
8
  export declare const useCollectionData: <T extends {
9
9
  id: string;
10
- }>(ref: string | undefined | '' | null | false, collection_options?: Partial<useCollectionDataOptions<T>>) => CollectionObservable<T> & {
11
- items: SmartQueryItem<T>[];
10
+ }>(ref: string | undefined | '' | null | false, collection_options?: Partial<useCollectionDataOptions<T>>) => {
11
+ loading: boolean;
12
+ empty: boolean;
13
+ add: <R = {
14
+ data: {
15
+ item: T;
16
+ };
17
+ }>(payload: Partial<T>) => Promise<R>;
18
+ fetch_more: () => void;
19
+ filter: (filters: Partial<QueryOption<T>>) => void;
20
+ reload: () => void;
21
+ reset: () => void;
22
+ trigger: <R_1>(name: string, payload?: object | undefined, trigger_document_id?: string | undefined, query?: {
23
+ [key: string]: string | number | boolean;
24
+ } | undefined) => Promise<R_1 | undefined>;
25
+ update: <R_2 = {
26
+ data: {
27
+ item: T;
28
+ };
29
+ }>({ id: update_payload_id, ...payload }: Partial<T>) => Promise<R_2 | undefined>;
30
+ $changes: import("rxjs").Subject<import("@livequery/types").UpdatedData<T>>;
31
+ items: import("@livequery/client").SmartQueryItem<T>[];
12
32
  error?: import("@livequery/types").ErrorInfo | undefined;
13
33
  has_more: boolean;
14
- loading?: boolean | undefined;
15
34
  options: Partial<QueryOption<T>>;
16
- } & {
17
- empty: boolean | "" | null | undefined;
18
35
  };
@@ -10,7 +10,7 @@ export const useCollectionData = (ref, collection_options = {}) => {
10
10
  const { transporter } = useLiveQueryContext();
11
11
  const client = useMemo(() => new CollectionObservable(ref, { transporter, ...collection_options }), [ref]);
12
12
  const stream = useObservable(client, { options: {}, items: [], has_more: false, loading: false, error: undefined });
13
- const { loading, has_more, items } = stream;
13
+ const { loading, has_more, items, error } = stream;
14
14
  useEffect(() => {
15
15
  try {
16
16
  ref && !collection_options?.lazy && client?.fetch_more();
@@ -21,7 +21,17 @@ export const useCollectionData = (ref, collection_options = {}) => {
21
21
  useEffect(() => {
22
22
  collection_options.load_all && !loading && has_more && items.length > 0 && client?.fetch_more();
23
23
  }, [loading]);
24
- return Object.assign(client, stream, {
25
- empty: ref && !stream.error && stream.items.length == 0 && !stream.loading
26
- });
24
+ return {
25
+ ...stream,
26
+ loading: !!stream.loading,
27
+ empty: !!(ref && !error && items.length == 0 && loading === false),
28
+ add: assert(client?.add, client),
29
+ fetch_more: assert(client?.fetch_more, client),
30
+ filter: assert(client?.filter, client),
31
+ reload: assert(client?.reload, client),
32
+ reset: assert(client?.reset, client),
33
+ trigger: assert(client?.trigger, client),
34
+ update: assert(client?.update, client),
35
+ $changes: client?.$changes
36
+ };
27
37
  };
@@ -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 | undefined;
10
+ loading: boolean;
11
11
  error: import("@livequery/types").ErrorInfo | undefined;
12
12
  reload: () => void;
13
13
  $changes: import("rxjs").Subject<import("@livequery/types").UpdatedData<T>>;
@@ -4,7 +4,7 @@ export const useObservable = (o, default_value) => {
4
4
  const [s, ss] = useState();
5
5
  useEffect(() => {
6
6
  if (o) {
7
- const subcription = o.subscribe(d => ss(d));
7
+ const subcription = o.subscribe(d => ss({ ...d }));
8
8
  return () => {
9
9
  subcription.unsubscribe();
10
10
  };
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.91",
7
+ "version": "1.0.93",
8
8
  "description": "",
9
9
  "main": "build/index.js",
10
10
  "types": "build/index.d.ts",