@livequery/react 1.0.33 → 1.0.35

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,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { Transporter } from '@livequery/types';
3
- export declare type LiveQueryContextOption = {
3
+ export type LiveQueryContextOption = {
4
4
  transporter: Transporter;
5
5
  };
6
6
  export declare const useLiveQueryContext: () => LiveQueryContextOption, LiveQueryContextProvider: ({ children, ...props }: import("react").PropsWithChildren<LiveQueryContextOption>) => JSX.Element;
@@ -3,4 +3,4 @@ var _a;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.LiveQueryContextProvider = exports.useLiveQueryContext = void 0;
5
5
  const createContextFromHook_1 = require("./hooks/createContextFromHook");
6
- _a = createContextFromHook_1.createContextFromHook((props) => props), exports.useLiveQueryContext = _a[0], exports.LiveQueryContextProvider = _a[1];
6
+ _a = (0, createContextFromHook_1.createContextFromHook)((props) => props), exports.useLiveQueryContext = _a[0], exports.LiveQueryContextProvider = _a[1];
@@ -18,8 +18,8 @@ exports.createContextFromHook = void 0;
18
18
  const react_1 = __importDefault(require("react"));
19
19
  const react_2 = require("react");
20
20
  const createContextFromHook = (fn) => {
21
- const context = react_2.createContext({});
22
- const getContext = () => react_2.useContext(context);
21
+ const context = (0, react_2.createContext)({});
22
+ const getContext = () => (0, react_2.useContext)(context);
23
23
  const Provider = (_a) => {
24
24
  var { children } = _a, props = __rest(_a, ["children"]);
25
25
  const value = fn(props);
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ export declare const createStaticContext: <T extends {}>() => [() => T, ({ children, ...props }: import("react").PropsWithChildren<{
3
+ value: T;
4
+ }>) => JSX.Element];
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createStaticContext = void 0;
4
+ const createContextFromHook_1 = require("./createContextFromHook");
5
+ const createStaticContext = () => (0, createContextFromHook_1.createContextFromHook)((props) => props.value);
6
+ exports.createStaticContext = createStaticContext;
package/build/index.d.ts CHANGED
@@ -3,3 +3,4 @@ export * from './useCollectionData';
3
3
  export * from './useMonitor';
4
4
  export * from "./LiveQueryContext";
5
5
  export * from './hooks/createContextFromHook';
6
+ export * from './hooks/createStaticContext';
package/build/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -15,3 +19,4 @@ __exportStar(require("./useCollectionData"), exports);
15
19
  __exportStar(require("./useMonitor"), exports);
16
20
  __exportStar(require("./LiveQueryContext"), exports);
17
21
  __exportStar(require("./hooks/createContextFromHook"), exports);
22
+ __exportStar(require("./hooks/createStaticContext"), exports);
@@ -1,6 +1,6 @@
1
1
  import { QueryOption } from "@livequery/types";
2
2
  import { CollectionOption } from "@livequery/client";
3
- export declare type useCollectionDataOptions<T = any> = CollectionOption<T> & {
3
+ export type useCollectionDataOptions<T = any> = CollectionOption<T> & {
4
4
  lazy?: boolean;
5
5
  filters: Partial<QueryOption<T>>;
6
6
  };
@@ -22,4 +22,5 @@ export declare const useCollectionData: <T extends {
22
22
  update: ({ id: update_payload_id, ...payload }: Partial<T & {
23
23
  id: string;
24
24
  }>) => Promise<T>;
25
+ $changes: import("rxjs").Subject<import("@livequery/types").UpdatedData<T>>;
25
26
  };
@@ -9,10 +9,10 @@ function assert(fn, thiss) {
9
9
  return (fn || (() => { })).bind(thiss);
10
10
  }
11
11
  const useCollectionData = (ref, collection_options = {}) => {
12
- const { transporter } = LiveQueryContext_1.useLiveQueryContext();
13
- const client = react_1.useMemo(() => ref && new client_1.CollectionObservable(ref, Object.assign({ transporter }, collection_options)), [ref]);
14
- const { loading, has_more, error, items, options } = useObservable_1.useObservable(client, { options: {}, items: [], has_more: false });
15
- react_1.useEffect(() => {
12
+ const { transporter } = (0, LiveQueryContext_1.useLiveQueryContext)();
13
+ const client = (0, react_1.useMemo)(() => ref && new client_1.CollectionObservable(ref, Object.assign({ transporter }, collection_options)), [ref]);
14
+ const { loading, has_more, error, items, options } = (0, useObservable_1.useObservable)(client, { options: {}, items: [], has_more: false, loading: collection_options.lazy ? false : true });
15
+ (0, react_1.useEffect)(() => {
16
16
  ref && !(collection_options === null || collection_options === void 0 ? void 0 : collection_options.lazy) && client.fetch_more();
17
17
  }, [ref]);
18
18
  return {
@@ -29,6 +29,7 @@ const useCollectionData = (ref, collection_options = {}) => {
29
29
  reset: assert(client === null || client === void 0 ? void 0 : client.reset, client),
30
30
  trigger: assert(client === null || client === void 0 ? void 0 : client.trigger, client),
31
31
  update: assert(client === null || client === void 0 ? void 0 : client.update, client),
32
+ $changes: client.$changes
32
33
  };
33
34
  };
34
35
  exports.useCollectionData = useCollectionData;
@@ -1,5 +1,5 @@
1
1
  import { CollectionOption } from "@livequery/client";
2
- export declare type useDocumentDataOptions<T = any> = Omit<CollectionOption<T>, 'filters'> & {
2
+ export type useDocumentDataOptions<T = any> = Omit<CollectionOption<T>, 'filters'> & {
3
3
  lazy?: boolean;
4
4
  };
5
5
  export declare const useDocumentData: <T extends {
@@ -9,4 +9,5 @@ export declare const useDocumentData: <T extends {
9
9
  loading: boolean;
10
10
  error: import("@livequery/types").ErrorInfo;
11
11
  reload: () => void;
12
+ $changes: import("rxjs").Subject<import("@livequery/types").UpdatedData<T>>;
12
13
  };
@@ -3,12 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useDocumentData = void 0;
4
4
  const useCollectionData_1 = require("./useCollectionData");
5
5
  const useDocumentData = (ref, options) => {
6
- const { items, loading, error, reload } = useCollectionData_1.useCollectionData(ref, options);
6
+ const { items, loading, error, reload, $changes } = (0, useCollectionData_1.useCollectionData)(ref, options);
7
7
  return {
8
8
  item: items[0],
9
9
  loading,
10
10
  error,
11
- reload
11
+ reload,
12
+ $changes
12
13
  };
13
14
  };
14
15
  exports.useDocumentData = useDocumentData;
@@ -1,4 +1,4 @@
1
- declare type PromiseType<T> = T extends PromiseLike<infer U> ? U : T;
1
+ type PromiseType<T> = T extends PromiseLike<infer U> ? U : T;
2
2
  export declare const useMonitor: <T extends (...args: any) => any>(fn: T) => {
3
3
  excute: T;
4
4
  loading: boolean;
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.useMonitor = void 0;
13
13
  const react_1 = require("react");
14
14
  const useMonitor = (fn) => {
15
- const [{ error, data, loading }, update] = react_1.useState({});
15
+ const [{ error, data, loading }, update] = (0, react_1.useState)({});
16
16
  const excute = ((...args) => __awaiter(void 0, void 0, void 0, function* () {
17
17
  update({ data: null, loading: true, error: null });
18
18
  try {
@@ -4,8 +4,8 @@ exports.useObservable = void 0;
4
4
  const react_1 = require("react");
5
5
  const useObservable = (o, default_value) => {
6
6
  let mounting = true;
7
- const [s, ss] = react_1.useState(default_value);
8
- react_1.useEffect(() => {
7
+ const [s, ss] = (0, react_1.useState)(default_value);
8
+ (0, react_1.useEffect)(() => {
9
9
  if (!o)
10
10
  return;
11
11
  const subcription = o === null || o === void 0 ? void 0 : o.subscribe(d => ss(Object.assign({}, d)));
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.33",
6
+ "version": "1.0.35",
7
7
  "description": "",
8
8
  "main": "build/index.js",
9
9
  "types": "build/index.d.ts",
@@ -11,7 +11,7 @@
11
11
  "build/**/*"
12
12
  ],
13
13
  "dependencies": {
14
- "@livequery/client": "^1.0.26"
14
+ "@livequery/client": "^1.0.29"
15
15
  },
16
16
  "devDependencies": {
17
17
  "react": "^17.0.2",