@livequery/react 1.0.37 → 1.0.82
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.
- package/build/LiveQueryContext.d.ts +1 -1
- package/build/LiveQueryContext.js +2 -6
- package/build/hooks/createContextFromHook.d.ts +1 -1
- package/build/hooks/createContextFromHook.js +7 -26
- package/build/hooks/createStaticContext.d.ts +1 -1
- package/build/hooks/createStaticContext.js +2 -6
- package/build/index.js +6 -22
- package/build/useCollectionData.d.ts +8 -6
- package/build/useCollectionData.js +19 -23
- package/build/useDocumentData.d.ts +2 -1
- package/build/useDocumentData.js +3 -7
- package/build/useMonitor.js +6 -19
- package/build/useObservable.js +6 -10
- package/package.json +2 -1
|
@@ -3,4 +3,4 @@ import { Transporter } from '@livequery/types';
|
|
|
3
3
|
export type LiveQueryContextOption = {
|
|
4
4
|
transporter: Transporter;
|
|
5
5
|
};
|
|
6
|
-
export declare const useLiveQueryContext: () => LiveQueryContextOption, LiveQueryContextProvider: ({ children, ...props }: import("react").PropsWithChildren<LiveQueryContextOption>) => JSX.Element;
|
|
6
|
+
export declare const useLiveQueryContext: () => LiveQueryContextOption, LiveQueryContextProvider: ({ children, ...props }: import("react").PropsWithChildren<LiveQueryContextOption>) => import("react").JSX.Element;
|
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.LiveQueryContextProvider = exports.useLiveQueryContext = void 0;
|
|
5
|
-
const createContextFromHook_1 = require("./hooks/createContextFromHook");
|
|
6
|
-
_a = (0, createContextFromHook_1.createContextFromHook)((props) => props), exports.useLiveQueryContext = _a[0], exports.LiveQueryContextProvider = _a[1];
|
|
1
|
+
import { createContextFromHook } from './hooks/createContextFromHook';
|
|
2
|
+
export const [useLiveQueryContext, LiveQueryContextProvider] = createContextFromHook((props) => props);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import React, { PropsWithChildren } from 'react';
|
|
2
|
-
export declare const createContextFromHook: <T, K>(fn: (props?: T) => K) => [() => K, ({ children, ...props }: React.PropsWithChildren<T>) => JSX.Element];
|
|
2
|
+
export declare const createContextFromHook: <T, K>(fn: (props?: T) => K) => [() => K, ({ children, ...props }: React.PropsWithChildren<T>) => React.JSX.Element];
|
|
@@ -1,30 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.createContextFromHook = void 0;
|
|
18
|
-
const react_1 = __importDefault(require("react"));
|
|
19
|
-
const react_2 = require("react");
|
|
20
|
-
const createContextFromHook = (fn) => {
|
|
21
|
-
const context = (0, react_2.createContext)({});
|
|
22
|
-
const getContext = () => (0, react_2.useContext)(context);
|
|
23
|
-
const Provider = (_a) => {
|
|
24
|
-
var { children } = _a, props = __rest(_a, ["children"]);
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { createContext, useContext } from "react";
|
|
3
|
+
export const createContextFromHook = (fn) => {
|
|
4
|
+
const context = createContext({});
|
|
5
|
+
const getContext = () => useContext(context);
|
|
6
|
+
const Provider = ({ children, ...props }) => {
|
|
25
7
|
const value = fn(props);
|
|
26
|
-
return (
|
|
8
|
+
return (React.createElement(context.Provider, { value: value }, children));
|
|
27
9
|
};
|
|
28
10
|
return [getContext, Provider];
|
|
29
11
|
};
|
|
30
|
-
exports.createContextFromHook = createContextFromHook;
|
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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;
|
|
1
|
+
import { createContextFromHook } from './createContextFromHook';
|
|
2
|
+
export const createStaticContext = () => createContextFromHook((props) => props.value);
|
package/build/index.js
CHANGED
|
@@ -1,22 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./useDocumentData"), exports);
|
|
18
|
-
__exportStar(require("./useCollectionData"), exports);
|
|
19
|
-
__exportStar(require("./useMonitor"), exports);
|
|
20
|
-
__exportStar(require("./LiveQueryContext"), exports);
|
|
21
|
-
__exportStar(require("./hooks/createContextFromHook"), exports);
|
|
22
|
-
__exportStar(require("./hooks/createStaticContext"), exports);
|
|
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,6 +1,6 @@
|
|
|
1
|
-
import { QueryOption } from "@livequery/types";
|
|
1
|
+
import { LivequeryBaseEntity, QueryOption } from "@livequery/types";
|
|
2
2
|
import { CollectionOption } from "@livequery/client";
|
|
3
|
-
export type useCollectionDataOptions<T =
|
|
3
|
+
export type useCollectionDataOptions<T extends LivequeryBaseEntity = LivequeryBaseEntity> = CollectionOption<T> & {
|
|
4
4
|
lazy?: boolean;
|
|
5
5
|
filters: Partial<QueryOption<T>>;
|
|
6
6
|
load_all: boolean;
|
|
@@ -14,14 +14,16 @@ export declare const useCollectionData: <T extends {
|
|
|
14
14
|
has_more: boolean;
|
|
15
15
|
empty: boolean;
|
|
16
16
|
filters: Partial<QueryOption<T>>;
|
|
17
|
-
add: (payload: T) => Promise<
|
|
17
|
+
add: (payload: Partial<T>) => Promise<{
|
|
18
|
+
data: {
|
|
19
|
+
item: T;
|
|
20
|
+
};
|
|
21
|
+
}>;
|
|
18
22
|
fetch_more: () => void;
|
|
19
23
|
filter: (filters: Partial<QueryOption<T>>) => void;
|
|
20
24
|
reload: () => void;
|
|
21
25
|
reset: () => void;
|
|
22
26
|
trigger: <T_1>(name: string, payload?: object, trigger_document_id?: string) => Promise<T_1>;
|
|
23
|
-
update: ({ id: update_payload_id, ...payload }: Partial<T
|
|
24
|
-
id: string;
|
|
25
|
-
}>) => Promise<T>;
|
|
27
|
+
update: ({ id: update_payload_id, ...payload }: Partial<T>) => Promise<any>;
|
|
26
28
|
$changes: import("rxjs").Subject<import("@livequery/types").UpdatedData<T>>;
|
|
27
29
|
};
|
|
@@ -1,21 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const LiveQueryContext_1 = require("./LiveQueryContext");
|
|
6
|
-
const useObservable_1 = require("./useObservable");
|
|
7
|
-
const client_1 = require("@livequery/client");
|
|
1
|
+
import { useEffect, useMemo } from "react";
|
|
2
|
+
import { useLiveQueryContext } from "./LiveQueryContext";
|
|
3
|
+
import { useObservable } from "./useObservable";
|
|
4
|
+
import { CollectionObservable } from "@livequery/client";
|
|
8
5
|
function assert(fn, thiss) {
|
|
9
6
|
return (fn || (() => { })).bind(thiss);
|
|
10
7
|
}
|
|
11
|
-
const useCollectionData = (ref, collection_options = {}) => {
|
|
12
|
-
const { transporter } =
|
|
13
|
-
const client =
|
|
14
|
-
const { loading, has_more, error, items, options } =
|
|
15
|
-
|
|
16
|
-
ref && !
|
|
8
|
+
export const useCollectionData = (ref, collection_options = {}) => {
|
|
9
|
+
const { transporter } = useLiveQueryContext();
|
|
10
|
+
const client = useMemo(() => ref && new CollectionObservable(ref, { transporter, ...collection_options }), [ref]);
|
|
11
|
+
const { loading, has_more, error, items, options } = useObservable(client, { options: {}, items: [], has_more: false, loading: collection_options.lazy ? false : true });
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
ref && !collection_options?.lazy && client.fetch_more();
|
|
17
14
|
}, [ref]);
|
|
18
|
-
|
|
15
|
+
useEffect(() => {
|
|
19
16
|
collection_options.load_all && !loading && has_more && items.length > 0 && client.fetch_more();
|
|
20
17
|
}, [loading]);
|
|
21
18
|
return {
|
|
@@ -25,14 +22,13 @@ const useCollectionData = (ref, collection_options = {}) => {
|
|
|
25
22
|
has_more,
|
|
26
23
|
empty: ref && !error && Object.keys(items).length == 0 && loading === false,
|
|
27
24
|
filters: (options || {}),
|
|
28
|
-
add: assert(client
|
|
29
|
-
fetch_more: assert(client
|
|
30
|
-
filter: assert(client
|
|
31
|
-
reload: assert(client
|
|
32
|
-
reset: assert(client
|
|
33
|
-
trigger: assert(client
|
|
34
|
-
update: assert(client
|
|
35
|
-
$changes: client
|
|
25
|
+
add: assert(client?.add, client),
|
|
26
|
+
fetch_more: assert(client?.fetch_more, client),
|
|
27
|
+
filter: assert(client?.filter, client),
|
|
28
|
+
reload: assert(client?.reload, client),
|
|
29
|
+
reset: assert(client?.reset, client),
|
|
30
|
+
trigger: assert(client?.trigger, client),
|
|
31
|
+
update: assert(client?.update, client),
|
|
32
|
+
$changes: client?.$changes
|
|
36
33
|
};
|
|
37
34
|
};
|
|
38
|
-
exports.useCollectionData = useCollectionData;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CollectionOption } from "@livequery/client";
|
|
2
|
-
|
|
2
|
+
import { LivequeryBaseEntity } from "@livequery/types";
|
|
3
|
+
export type useDocumentDataOptions<T extends LivequeryBaseEntity = LivequeryBaseEntity> = Omit<CollectionOption<T>, 'filters'> & {
|
|
3
4
|
lazy?: boolean;
|
|
4
5
|
};
|
|
5
6
|
export declare const useDocumentData: <T extends {
|
package/build/useDocumentData.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const useCollectionData_1 = require("./useCollectionData");
|
|
5
|
-
const useDocumentData = (ref, options) => {
|
|
6
|
-
const { items, loading, error, reload, $changes } = (0, useCollectionData_1.useCollectionData)(ref, options);
|
|
1
|
+
import { useCollectionData } from "./useCollectionData";
|
|
2
|
+
export const useDocumentData = (ref, options) => {
|
|
3
|
+
const { items, loading, error, reload, $changes } = useCollectionData(ref, options);
|
|
7
4
|
return {
|
|
8
5
|
item: items[0],
|
|
9
6
|
loading,
|
|
@@ -12,4 +9,3 @@ const useDocumentData = (ref, options) => {
|
|
|
12
9
|
$changes
|
|
13
10
|
};
|
|
14
11
|
};
|
|
15
|
-
exports.useDocumentData = useDocumentData;
|
package/build/useMonitor.js
CHANGED
|
@@ -1,28 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.useMonitor = void 0;
|
|
13
|
-
const react_1 = require("react");
|
|
14
|
-
const useMonitor = (fn) => {
|
|
15
|
-
const [{ error, data, loading }, update] = (0, react_1.useState)({});
|
|
16
|
-
const excute = ((...args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
export const useMonitor = (fn) => {
|
|
3
|
+
const [{ error, data, loading }, update] = useState({});
|
|
4
|
+
const excute = (async (...args) => {
|
|
17
5
|
update({ data: null, loading: true, error: null });
|
|
18
6
|
try {
|
|
19
|
-
update({ data:
|
|
7
|
+
update({ data: await fn(...args), error: null, loading: false });
|
|
20
8
|
}
|
|
21
9
|
catch (error) {
|
|
22
10
|
update({ data: null, error, loading: false });
|
|
23
11
|
}
|
|
24
|
-
})
|
|
12
|
+
});
|
|
25
13
|
const vaild = !error && !loading;
|
|
26
14
|
return { excute, loading, data, error, vaild };
|
|
27
15
|
};
|
|
28
|
-
exports.useMonitor = useMonitor;
|
package/build/useObservable.js
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.useObservable = void 0;
|
|
4
|
-
const react_1 = require("react");
|
|
5
|
-
const useObservable = (o, default_value) => {
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
export const useObservable = (o, default_value) => {
|
|
6
3
|
let mounting = true;
|
|
7
|
-
const [s, ss] =
|
|
8
|
-
|
|
4
|
+
const [s, ss] = useState(default_value);
|
|
5
|
+
useEffect(() => {
|
|
9
6
|
if (!o)
|
|
10
7
|
return;
|
|
11
|
-
const subcription = o
|
|
8
|
+
const subcription = o?.subscribe(d => ss({ ...d }));
|
|
12
9
|
return () => {
|
|
13
|
-
subcription
|
|
10
|
+
subcription?.unsubscribe();
|
|
14
11
|
mounting = false;
|
|
15
12
|
};
|
|
16
13
|
}, [o]);
|
|
17
14
|
return s;
|
|
18
15
|
};
|
|
19
|
-
exports.useObservable = useObservable;
|