@livequery/react 1.0.25 → 1.0.29

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
- import { CollectionOption } from '@livequery/client';
2
1
  import { QueryOption } from "../../types/build";
2
+ import { CollectionOption } from "@livequery/client";
3
3
  export declare type useCollectionDataOptions<T = any> = CollectionOption<T> & {
4
4
  lazy?: boolean;
5
5
  filters: Partial<QueryOption<T>>;
@@ -9,17 +9,17 @@ export declare const useCollectionData: <T extends {
9
9
  }>(ref: string, collection_options?: Partial<useCollectionDataOptions<T>>) => {
10
10
  items: import("@livequery/client").SmartQueryItem<T>[];
11
11
  loading: boolean;
12
- error: import("@livequery/types").ErrorInfo;
12
+ error: import("../../types/build").ErrorInfo;
13
13
  has_more: boolean;
14
14
  empty: boolean;
15
- filters: Partial<import("@livequery/types").QueryOption<T>>;
16
- add: (payload: T, local?: boolean) => Promise<void>;
15
+ filters: Partial<QueryOption<T>>;
16
+ add: (payload: T) => Promise<T>;
17
17
  fetch_more: () => void;
18
- filter: (filters: Partial<import("@livequery/types").QueryOption<T>>) => void;
18
+ filter: (filters: Partial<QueryOption<T>>) => void;
19
19
  reload: () => void;
20
20
  reset: () => void;
21
- trigger: (name: string, document_id: string, payload?: object) => Promise<unknown>;
22
- update: ({ id, ...payload }: {
21
+ trigger: <T_1>(name: string, payload?: object, trigger_document_id?: string) => Promise<T_1>;
22
+ update: ({ id: update_payload_id, ...payload }: Partial<T & {
23
23
  id: string;
24
- } & Partial<T>) => Promise<void>;
24
+ }>) => Promise<T>;
25
25
  };
@@ -3,8 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useCollectionData = void 0;
4
4
  const react_1 = require("react");
5
5
  const LiveQueryContext_1 = require("./LiveQueryContext");
6
- const client_1 = require("@livequery/client");
7
6
  const useObservable_1 = require("./useObservable");
7
+ const client_1 = require("@livequery/client");
8
+ function assert(fn, thiss) {
9
+ return (fn || (() => { })).bind(thiss);
10
+ }
8
11
  const useCollectionData = (ref, collection_options = {}) => {
9
12
  const { transporter } = LiveQueryContext_1.useLiveQueryContext();
10
13
  const client = react_1.useMemo(() => ref && new client_1.CollectionObservable(ref, Object.assign({ transporter }, collection_options)), [ref]);
@@ -19,13 +22,13 @@ const useCollectionData = (ref, collection_options = {}) => {
19
22
  has_more,
20
23
  empty: !error && Object.keys(items).length == 0 && !loading,
21
24
  filters: (options || {}),
22
- add: client === null || client === void 0 ? void 0 : client.add.bind(client),
23
- fetch_more: client === null || client === void 0 ? void 0 : client.fetch_more.bind(client),
24
- filter: client === null || client === void 0 ? void 0 : client.filter.bind(client),
25
- reload: client === null || client === void 0 ? void 0 : client.reload.bind(client),
26
- reset: client === null || client === void 0 ? void 0 : client.reset.bind(client),
27
- trigger: client === null || client === void 0 ? void 0 : client.trigger.bind(client),
28
- update: client === null || client === void 0 ? void 0 : client.update.bind(client),
25
+ add: assert(client === null || client === void 0 ? void 0 : client.add, client),
26
+ fetch_more: assert(client === null || client === void 0 ? void 0 : client.fetch_more, client),
27
+ filter: assert(client === null || client === void 0 ? void 0 : client.filter, client),
28
+ reload: assert(client === null || client === void 0 ? void 0 : client.reload, client),
29
+ reset: assert(client === null || client === void 0 ? void 0 : client.reset, client),
30
+ trigger: assert(client === null || client === void 0 ? void 0 : client.trigger, client),
31
+ update: assert(client === null || client === void 0 ? void 0 : client.update, client),
29
32
  };
30
33
  };
31
34
  exports.useCollectionData = useCollectionData;
@@ -6,6 +6,8 @@ const useObservable = (o, default_value) => {
6
6
  let mounting = true;
7
7
  const [s, ss] = react_1.useState(default_value);
8
8
  react_1.useEffect(() => {
9
+ if (!o)
10
+ return;
9
11
  const subcription = o === null || o === void 0 ? void 0 : o.subscribe(d => ss(Object.assign({}, d)));
10
12
  return () => {
11
13
  subcription === null || subcription === void 0 ? void 0 : subcription.unsubscribe();
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "repository": {
4
4
  "url": "https://github.com/livequery/react"
5
5
  },
6
- "version": "1.0.25",
6
+ "version": "1.0.29",
7
7
  "description": "",
8
8
  "main": "build/index.js",
9
9
  "types": "build/index.d.ts",
@@ -11,12 +11,11 @@
11
11
  "build/**/*"
12
12
  ],
13
13
  "dependencies": {
14
- "@livequery/client": "^1.0.15",
15
- "react": "^17.0.2",
16
- "rxjs": "^7.1.0"
14
+ "@livequery/client": "^1.0.25"
17
15
  },
18
16
  "devDependencies": {
19
- "@livequery/types": "^1.0.24",
17
+ "react": "^17.0.2",
18
+ "@livequery/types": "^1.0.31",
20
19
  "@types/react": "^17.0.11"
21
20
  },
22
21
  "peerDependencies": {
@@ -29,4 +28,4 @@
29
28
  },
30
29
  "author": "",
31
30
  "license": "ISC"
32
- }
31
+ }