@livequery/react 2.0.95 → 2.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.
- package/dist/LivequeryCoreContext.d.ts +5 -0
- package/dist/LivequeryCoreContext.d.ts.map +1 -0
- package/dist/LivequeryCoreContext.js +3 -0
- package/dist/LivequeryCoreContext.js.map +1 -0
- package/dist/createContextFromHook.d.ts +2 -15
- package/dist/createContextFromHook.d.ts.map +1 -1
- package/dist/createContextFromHook.js +14 -0
- package/dist/createContextFromHook.js.map +1 -0
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -4
- package/dist/index.js.map +1 -14
- package/dist/useAction.d.ts +11 -0
- package/dist/useAction.d.ts.map +1 -0
- package/dist/useAction.js +22 -0
- package/dist/useAction.js.map +1 -0
- package/dist/useCollection.d.ts +1 -21
- package/dist/useCollection.d.ts.map +1 -1
- package/dist/useCollection.js +17 -0
- package/dist/useCollection.js.map +1 -0
- package/dist/useDocument.d.ts +2 -12
- package/dist/useDocument.d.ts.map +1 -1
- package/dist/useDocument.js +10 -0
- package/dist/useDocument.js.map +1 -0
- package/dist/useObservable.d.ts +1 -14
- package/dist/useObservable.d.ts.map +1 -1
- package/dist/useObservable.js +21 -0
- package/dist/useObservable.js.map +1 -0
- package/package.json +35 -7
- package/dist/useGlobalValue.d.ts +0 -12
- package/dist/useGlobalValue.d.ts.map +0 -1
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { LivequeryCore } from "@livequery/core";
|
|
2
|
+
export declare const useLivequeryCore: () => LivequeryCore, LivequeryCoreProvider: (props: import("react").PropsWithChildren<{
|
|
3
|
+
core: any;
|
|
4
|
+
}>) => import("react").JSX.Element;
|
|
5
|
+
//# sourceMappingURL=LivequeryCoreContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LivequeryCoreContext.d.ts","sourceRoot":"","sources":["../src/LivequeryCoreContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGrD,eAAO,MAAO,gBAAgB,uBAAE,qBAAqB;UACjC,GAAG;kCACtB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LivequeryCoreContext.js","sourceRoot":"","sources":["../src/LivequeryCoreContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAEnE,MAAM,CAAC,MAAM,CAAC,gBAAgB,EAAE,qBAAqB,CAAC,GAAG,qBAAqB,CAC1E,CAAC,KAAoB,EAAE,EAAE,CAAC,KAAK,CAAC,IAAqB,CACxD,CAAA"}
|
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
import { type PropsWithChildren } from "react";
|
|
2
|
-
|
|
3
|
-
* Creates a React context pair from a hook-like factory.
|
|
4
|
-
*
|
|
5
|
-
* The returned tuple contains:
|
|
6
|
-
* - a consumer hook that reads the computed value from context
|
|
7
|
-
* - a provider component that calls `fn(props)` and places the result into context
|
|
8
|
-
*
|
|
9
|
-
* This pattern is useful when some shared state should feel like a normal hook at call
|
|
10
|
-
* sites, while still being configured once at the edge of a subtree.
|
|
11
|
-
*
|
|
12
|
-
* @param fn Factory that receives provider props and returns the context value.
|
|
13
|
-
* @returns A tuple of `[useValue, Provider]`.
|
|
14
|
-
*/
|
|
15
|
-
export declare const createContextFromHook: <T, R>(fn: ((props: T) => R) | (() => R)) => [() => R, React.FC<PropsWithChildren<T>>];
|
|
1
|
+
import { type JSX, type PropsWithChildren } from "react";
|
|
2
|
+
export declare const createContextFromHook: <T, R>(fn: ((props: T) => R) | (() => R)) => [() => R, (props: PropsWithChildren<T>) => JSX.Element];
|
|
16
3
|
//# sourceMappingURL=createContextFromHook.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createContextFromHook.d.ts","sourceRoot":"","sources":["../src/createContextFromHook.tsx"],"names":[],"mappings":"AAAA,OAAO,EAA6B,KAAK,iBAAiB,EAAE,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"createContextFromHook.d.ts","sourceRoot":"","sources":["../src/createContextFromHook.tsx"],"names":[],"mappings":"AAAA,OAAO,EAA6B,KAAK,GAAG,EAAE,KAAK,iBAAiB,EAAE,MAAM,OAAO,CAAA;AAGnF,eAAO,MAAM,qBAAqB,GAAI,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,KAczC,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,iBAAiB,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,OAAO,CACzF,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext } from "react";
|
|
3
|
+
export const createContextFromHook = (fn) => {
|
|
4
|
+
const ctx = createContext(undefined);
|
|
5
|
+
const useState = () => {
|
|
6
|
+
return useContext(ctx);
|
|
7
|
+
};
|
|
8
|
+
const Provider = ({ children, ...props }) => {
|
|
9
|
+
const value = fn(props);
|
|
10
|
+
return (_jsx(ctx.Provider, { value: value, children: children }));
|
|
11
|
+
};
|
|
12
|
+
return [useState, Provider,];
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=createContextFromHook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createContextFromHook.js","sourceRoot":"","sources":["../src/createContextFromHook.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAoC,MAAM,OAAO,CAAA;AAGnF,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAO,EAAiC,EAAE,EAAE;IAC7E,MAAM,GAAG,GAAG,aAAa,CAAgB,SAAS,CAAC,CAAA;IAEnD,MAAM,QAAQ,GAAG,GAAG,EAAE;QAClB,OAAO,UAAU,CAAC,GAAG,CAAM,CAAA;IAC/B,CAAC,CAAA;IACD,MAAM,QAAQ,GAAG,CAAC,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAwB,EAAE,EAAE;QAC9D,MAAM,KAAK,GAAG,EAAE,CAAC,KAAU,CAAC,CAAA;QAC5B,OAAO,CACH,KAAC,GAAG,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YACrB,QAAQ,GACE,CAClB,CAAA;IACL,CAAC,CAAA;IACD,OAAO,CAAC,QAAQ,EAAE,QAAQ,EAA6D,CAAA;AAC3F,CAAC,CAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from './createContextFromHook';
|
|
2
|
-
export * from './useCollection';
|
|
3
|
-
export * from './useDocument';
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './
|
|
1
|
+
export * from './createContextFromHook.js';
|
|
2
|
+
export * from './useCollection.js';
|
|
3
|
+
export * from './useDocument.js';
|
|
4
|
+
export * from './useObservable.js';
|
|
5
|
+
export * from './LivequeryCoreContext.js';
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAA;AAC1C,cAAc,oBAAoB,CAAA;AAClC,cAAc,kBAAkB,CAAA;AAChC,cAAc,oBAAoB,CAAA;AAClC,cAAc,2BAA2B,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
export * from './createContextFromHook.js';
|
|
2
|
+
export * from './useCollection.js';
|
|
3
|
+
export * from './useDocument.js';
|
|
4
|
+
export * from './useObservable.js';
|
|
5
|
+
export * from './LivequeryCoreContext.js';
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1,14 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/createContextFromHook.tsx", "../src/useCollection.ts", "../src/useDocument.ts", "../src/useObservable.ts", "../src/useGlobalValue.ts"],
|
|
4
|
-
"sourcesContent": [
|
|
5
|
-
"import { createContext, useContext, type PropsWithChildren } from \"react\"\n\n/**\n * Creates a React context pair from a hook-like factory.\n *\n * The returned tuple contains:\n * - a consumer hook that reads the computed value from context\n * - a provider component that calls `fn(props)` and places the result into context\n *\n * This pattern is useful when some shared state should feel like a normal hook at call\n * sites, while still being configured once at the edge of a subtree.\n *\n * @param fn Factory that receives provider props and returns the context value.\n * @returns A tuple of `[useValue, Provider]`.\n */\nexport const createContextFromHook = <T, R>(fn: ((props: T) => R) | (() => R)) => {\n const ctx = createContext<R | undefined>(undefined)\n\n /**\n * Reads the current context value produced by the paired provider.\n */\n const useState = () => {\n return useContext(ctx) as R\n }\n\n /**\n * Computes the context value from provider props and exposes it to descendants.\n */\n const Provider = ({ children, ...props }: PropsWithChildren<T>) => {\n const value = fn(props as T)\n return (\n <ctx.Provider value={value}>\n {children}\n </ctx.Provider>\n )\n }\n return [useState, Provider,] as [() => R, React.FC<PropsWithChildren<T>>]\n}",
|
|
6
|
-
"import { LivequeryCollection, LivequeryCore, type Doc, type LivequeryCollectionOptions } from \"@livequery/core\"\nimport { useMemo, useEffect } from \"react\"\nimport { createContextFromHook } from \"./createContextFromHook\"\n\nconst livequeryCoreContext = createContextFromHook(\n (props: { core: LivequeryCore }) => props.core\n)\n\n/**\n * Returns the `LivequeryCore` instance from the nearest provider.\n */\nexport const useLivequeryCore = livequeryCoreContext[0]\n\n/**\n * Provides a `LivequeryCore` instance to all descendants that use this package's hooks.\n */\nexport const LivequeryCoreProvider = livequeryCoreContext[1]\n\n/**\n * Creates and initializes a `LivequeryCollection` for the supplied collection path.\n *\n * The collection instance is stable for the lifetime of the component. Initialization is\n * skipped when `ref` is falsy.\n *\n * @param ref Collection path understood by `@livequery/core`.\n * @param options Collection options forwarded to `LivequeryCollection`.\n * @returns A stable `LivequeryCollection` instance.\n */\nexport const useCollection = <T extends Doc>(ref: string | undefined | '' | null | false, options: Partial<LivequeryCollectionOptions<T>> = {}) => {\n const core = useLivequeryCore()\n const collection = useMemo(() => new LivequeryCollection<T>(options), [])\n useEffect(() => {\n if (!ref || !core) return\n const linker = collection.initialize(core, ref)\n return () => {\n linker?.unsubscribe()\n }\n }, [collection, core, ref])\n\n return collection\n}",
|
|
7
|
-
"import { LivequeryCollection, type Doc } from \"@livequery/core\"\nimport { useMemo, useEffect } from \"react\"\nimport { useLivequeryCore } from \"./useCollection.js\"\nimport { useObservable } from \"./useObservable.js\"\n\n/**\n * Subscribes to a single document path and returns the first emitted item with loading state.\n *\n * Internally this hook creates a `LivequeryCollection`, initializes it with the document ref,\n * then reads the first item from the collection stream.\n *\n * @param ref Document path understood by `@livequery/core`.\n * @param options Collection options used when creating the backing collection.\n * @returns A tuple of `[document, loading]`.\n */\nexport const useDocument = <T extends Doc>(ref: string | undefined | '' | null | false, options: { lazy?: boolean } = {}) => {\n const core = useLivequeryCore()\n\n const collection = useMemo(() => new LivequeryCollection<T>(options), [])\n useEffect(() => {\n if (!ref || !core) return\n const linker = collection.initialize(core, ref)\n return () => {\n linker?.unsubscribe()\n }\n }, [collection, core, ref])\n\n const items = useObservable(collection.items)\n const loading = useObservable(collection.loading)\n return [items[0], loading] as const\n // const doc: LivequeryDocument<T> | null = items[0] || of(null)\n // return Object.assign(doc, {\n // loading,\n // del: () => id && collection.delete(id)\n // })\n\n}",
|
|
8
|
-
"import { useEffect, useState } from \"react\";\nimport { Observable, BehaviorSubject, tap, EMPTY } from \"rxjs\";\n\n/**\n * Accepts either a value or a lazy factory returning that value.\n */\nexport type MaybeFunction<T> = T | (() => T)\n\n/**\n * Subscribes to an RxJS observable and mirrors its latest value into React state.\n *\n * When a `BehaviorSubject` is provided, the hook uses `getValue()` for the initial render.\n * When a factory is provided, the observable is resolved lazily inside the effect.\n *\n * @param o Observable source or factory returning the source.\n * @param default_value Fallback value used before the first emission when the source is not a `BehaviorSubject`.\n * @returns The latest value emitted by the source.\n */\nexport const useObservable = <T extends any>(o: MaybeFunction<BehaviorSubject<T> | Observable<T>>, default_value?: T) => {\n const [v, s] = useState<T>(typeof (o as any)?.['getValue'] === 'function' ? (o as any).getValue() : (default_value as T))\n useEffect(() => {\n try {\n const target = (typeof o === 'function' ? o() : o) || EMPTY\n const subscription = target.pipe(\n tap(value => {\n s(value)\n })\n ).subscribe()\n return () => {\n subscription.unsubscribe()\n }\n } catch (e) { }\n }, typeof o === 'function' ? [] : [o])\n return v\n}",
|
|
9
|
-
"import { useMemo } from \"react\"\n\nconst WindowGlobalKey = Symbol.for('#livequery/react/global')\n\n/**\n * Resolves a process-wide singleton value stored on `globalThis`.\n *\n * The resolver runs only the first time a given key is requested in the current runtime.\n * Later calls with the same key return the cached value.\n *\n * @param key Unique key within the package global registry.\n * @param resolver Lazy factory used when the value does not exist yet.\n * @returns The cached or newly created value.\n */\nexport const useGlobalValue = <T>(key: string, resolver: () => T) => {\n const G = globalThis as any\n G[WindowGlobalKey] = G[WindowGlobalKey] || {}\n G[WindowGlobalKey]![key] = G[WindowGlobalKey]![key] || resolver()\n return G[WindowGlobalKey]![key] as T\n}"
|
|
10
|
-
],
|
|
11
|
-
"mappings": "AAAA,wBAAS,gBAAe,sDAejB,IAAM,EAAwB,CAAO,IAAsC,CAC9E,IAAM,EAAM,EAA6B,MAAS,EAoBlD,MAAO,CAfU,IAAM,CACnB,OAAO,EAAW,CAAG,GAMR,EAAG,cAAa,KAAkC,CAC/D,IAAM,EAAQ,EAAG,CAAU,EAC3B,OACI,EAEE,EAAI,SAFN,CAAc,MAAO,EAArB,SACK,EACH,EAGiB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AE1B,IAAM,EAAQ,EAAc,EAAW,KAAK,EACtC,EAAU,EAAc,EAAW,OAAO,EAChD,MAAO,CAAC,EAAM,GAAI,CAAO,GE3B7B,IAAM,EAAkB,OAAO,IAAI,yBAAyB,EAY/C,EAAiB,CAAI,EAAa,IAAsB,CACjE,IAAM,EAAI,WAGV,OAFA,EAAE,GAAmB,EAAE,IAAoB,CAAC,EAC5C,EAAE,GAAkB,GAAO,EAAE,GAAkB,IAAQ,EAAS,EACzD,EAAE,GAAkB",
|
|
12
|
-
"debugId": "691A0C6DD6BB1CED64756E2164756E21",
|
|
13
|
-
"names": []
|
|
14
|
-
}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAA;AAC1C,cAAc,oBAAoB,CAAA;AAClC,cAAc,kBAAkB,CAAA;AAChC,cAAc,oBAAoB,CAAA;AAClC,cAAc,2BAA2B,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const useAction: <T extends (...args: any[]) => Promise<any>>(fn: T, options?: Partial<{
|
|
2
|
+
onError: Function;
|
|
3
|
+
}>) => T & {
|
|
4
|
+
loading: boolean;
|
|
5
|
+
data: null;
|
|
6
|
+
error: null | {
|
|
7
|
+
code: string;
|
|
8
|
+
message: string;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=useAction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAction.d.ts","sourceRoot":"","sources":["../src/useAction.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,EAAE,UAAS,OAAO,CAAC;IAAE,OAAO,EAAE,QAAQ,CAAA;CAAE,CAAM;;;WAIlG,IAAI,GAAG;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE;CAc9D,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
export const useAction = (fn, options = {}) => {
|
|
3
|
+
const [state, set_state] = useState({
|
|
4
|
+
loading: false,
|
|
5
|
+
data: null,
|
|
6
|
+
error: null
|
|
7
|
+
});
|
|
8
|
+
const f = async (...args) => {
|
|
9
|
+
set_state({ loading: true, data: null, error: null });
|
|
10
|
+
try {
|
|
11
|
+
const data = await fn(...args);
|
|
12
|
+
set_state({ loading: false, data, error: null });
|
|
13
|
+
return data;
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
options.onError?.(error);
|
|
17
|
+
set_state({ loading: false, data: null, error: error instanceof Error ? { code: 'error', message: error.message } : { code: 'error', message: String(error) } });
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
return Object.assign(f, state);
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=useAction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAction.js","sourceRoot":"","sources":["../src/useAction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEhC,MAAM,CAAC,MAAM,SAAS,GAAG,CAA6C,EAAK,EAAE,UAA0C,EAAE,EAAE,EAAE;IACzH,MAAM,CAAC,KAAK,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAC;QAChC,OAAO,EAAE,KAAK;QACd,IAAI,EAAE,IAAI;QACV,KAAK,EAAE,IAAgD;KAC1D,CAAC,CAAA;IACF,MAAM,CAAC,GAAG,KAAK,EAAE,GAAG,IAAS,EAAE,EAAE;QAC7B,SAAS,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;QACrD,IAAI,CAAC;YACD,MAAM,IAAI,GAAG,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC,CAAA;YAC9B,SAAS,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;YAChD,OAAO,IAAI,CAAA;QACf,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,OAAO,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAA;YACxB,SAAS,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAA;QACpK,CAAC;IACL,CAAC,CAAA;IACD,OAAO,MAAM,CAAC,MAAM,CAAC,CAAM,EAAE,KAAK,CAAC,CAAA;AACvC,CAAC,CAAA"}
|
package/dist/useCollection.d.ts
CHANGED
|
@@ -1,23 +1,3 @@
|
|
|
1
|
-
import { LivequeryCollection,
|
|
2
|
-
/**
|
|
3
|
-
* Returns the `LivequeryCore` instance from the nearest provider.
|
|
4
|
-
*/
|
|
5
|
-
export declare const useLivequeryCore: () => LivequeryCore;
|
|
6
|
-
/**
|
|
7
|
-
* Provides a `LivequeryCore` instance to all descendants that use this package's hooks.
|
|
8
|
-
*/
|
|
9
|
-
export declare const LivequeryCoreProvider: import("react").FC<import("react").PropsWithChildren<{
|
|
10
|
-
core: LivequeryCore;
|
|
11
|
-
}>>;
|
|
12
|
-
/**
|
|
13
|
-
* Creates and initializes a `LivequeryCollection` for the supplied collection path.
|
|
14
|
-
*
|
|
15
|
-
* The collection instance is stable for the lifetime of the component. Initialization is
|
|
16
|
-
* skipped when `ref` is falsy.
|
|
17
|
-
*
|
|
18
|
-
* @param ref Collection path understood by `@livequery/core`.
|
|
19
|
-
* @param options Collection options forwarded to `LivequeryCollection`.
|
|
20
|
-
* @returns A stable `LivequeryCollection` instance.
|
|
21
|
-
*/
|
|
1
|
+
import { LivequeryCollection, type Doc, type LivequeryCollectionOptions } from "@livequery/core";
|
|
22
2
|
export declare const useCollection: <T extends Doc>(ref: string | undefined | "" | null | false, options?: Partial<LivequeryCollectionOptions<T>>) => LivequeryCollection<T>;
|
|
23
3
|
//# sourceMappingURL=useCollection.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCollection.d.ts","sourceRoot":"","sources":["../src/useCollection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,
|
|
1
|
+
{"version":3,"file":"useCollection.d.ts","sourceRoot":"","sources":["../src/useCollection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,KAAK,GAAG,EAAE,KAAK,0BAA0B,EAAE,MAAM,iBAAiB,CAAA;AAMhG,eAAO,MAAM,aAAa,GAAI,CAAC,SAAS,GAAG,EAAE,KAAK,MAAM,GAAG,SAAS,GAAG,EAAE,GAAG,IAAI,GAAG,KAAK,EAAE,UAAS,OAAO,CAAC,0BAA0B,CAAC,CAAC,CAAC,CAAM,2BAW7I,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { LivequeryCollection } from "@livequery/core";
|
|
2
|
+
import { useMemo, useEffect } from "react";
|
|
3
|
+
import { useLivequeryCore } from "./LivequeryCoreContext.js";
|
|
4
|
+
export const useCollection = (ref, options = {}) => {
|
|
5
|
+
const core = useLivequeryCore();
|
|
6
|
+
const collection = useMemo(() => new LivequeryCollection(core, options), []);
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
if (!ref || !core)
|
|
9
|
+
return;
|
|
10
|
+
const linker = collection.initialize(ref);
|
|
11
|
+
return () => {
|
|
12
|
+
linker?.unsubscribe();
|
|
13
|
+
};
|
|
14
|
+
}, [collection, core, ref]);
|
|
15
|
+
return collection;
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=useCollection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCollection.js","sourceRoot":"","sources":["../src/useCollection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAA6C,MAAM,iBAAiB,CAAA;AAChG,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAA;AAI5D,MAAM,CAAC,MAAM,aAAa,GAAG,CAAgB,GAA2C,EAAE,UAAkD,EAAE,EAAE,EAAE;IAC9I,MAAM,IAAI,GAAG,gBAAgB,EAAE,CAAA;IAC/B,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,mBAAmB,CAAI,IAAI,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,CAAA;IAC/E,SAAS,CAAC,GAAG,EAAE;QACX,IAAI,CAAC,GAAG,IAAI,CAAC,IAAI;YAAE,OAAM;QACzB,MAAM,MAAM,GAAG,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,CAAA;QACzC,OAAO,GAAG,EAAE;YACR,MAAM,EAAE,WAAW,EAAE,CAAA;QACzB,CAAC,CAAA;IACL,CAAC,EAAE,CAAC,UAAU,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC,CAAA;IAC3B,OAAO,UAAU,CAAA;AACrB,CAAC,CAAA"}
|
package/dist/useDocument.d.ts
CHANGED
|
@@ -1,15 +1,5 @@
|
|
|
1
|
-
import { type Doc } from "@livequery/core";
|
|
2
|
-
/**
|
|
3
|
-
* Subscribes to a single document path and returns the first emitted item with loading state.
|
|
4
|
-
*
|
|
5
|
-
* Internally this hook creates a `LivequeryCollection`, initializes it with the document ref,
|
|
6
|
-
* then reads the first item from the collection stream.
|
|
7
|
-
*
|
|
8
|
-
* @param ref Document path understood by `@livequery/core`.
|
|
9
|
-
* @param options Collection options used when creating the backing collection.
|
|
10
|
-
* @returns A tuple of `[document, loading]`.
|
|
11
|
-
*/
|
|
1
|
+
import { LivequeryDocument, type Doc, type DocState } from "@livequery/core";
|
|
12
2
|
export declare const useDocument: <T extends Doc>(ref: string | undefined | "" | null | false, options?: {
|
|
13
3
|
lazy?: boolean;
|
|
14
|
-
}) => readonly [
|
|
4
|
+
}) => readonly [LivequeryDocument<DocState<T>> | undefined, import("@livequery/core").LivequeryLoadingState | undefined];
|
|
15
5
|
//# sourceMappingURL=useDocument.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDocument.d.ts","sourceRoot":"","sources":["../src/useDocument.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"useDocument.d.ts","sourceRoot":"","sources":["../src/useDocument.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,KAAK,GAAG,EAAE,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAK5E,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,GAAG,EAAE,KAAK,MAAM,GAAG,SAAS,GAAG,EAAE,GAAG,IAAI,GAAG,KAAK,EAAE,UAAS;IAAE,IAAI,CAAC,EAAE,OAAO,CAAA;CAAO,uHAKvH,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { LivequeryDocument } from "@livequery/core";
|
|
2
|
+
import { useObservable } from "./useObservable.js";
|
|
3
|
+
import { useCollection } from "./useCollection.js";
|
|
4
|
+
export const useDocument = (ref, options = {}) => {
|
|
5
|
+
const collection = useCollection(ref, { lazy: options.lazy });
|
|
6
|
+
const items = useObservable(collection.items, []);
|
|
7
|
+
const loading = useObservable(collection.loading);
|
|
8
|
+
return [items[0], loading];
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=useDocument.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDocument.js","sourceRoot":"","sources":["../src/useDocument.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAA2B,MAAM,iBAAiB,CAAA;AAC5E,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAGlD,MAAM,CAAC,MAAM,WAAW,GAAG,CAAgB,GAA2C,EAAE,UAA8B,EAAE,EAAE,EAAE;IACxH,MAAM,UAAU,GAAG,aAAa,CAAI,GAAG,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC,CAAA;IAChE,MAAM,KAAK,GAAG,aAAa,CAAC,UAAU,CAAC,KAAK,EAAE,EAAsC,CAAC,CAAA;IACrF,MAAM,OAAO,GAAG,aAAa,CAAC,UAAU,CAAC,OAAO,CAAC,CAAA;IACjD,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,OAAO,CAAU,CAAA;AACvC,CAAC,CAAA"}
|
package/dist/useObservable.d.ts
CHANGED
|
@@ -1,17 +1,4 @@
|
|
|
1
1
|
import { Observable, BehaviorSubject } from "rxjs";
|
|
2
|
-
/**
|
|
3
|
-
* Accepts either a value or a lazy factory returning that value.
|
|
4
|
-
*/
|
|
5
2
|
export type MaybeFunction<T> = T | (() => T);
|
|
6
|
-
|
|
7
|
-
* Subscribes to an RxJS observable and mirrors its latest value into React state.
|
|
8
|
-
*
|
|
9
|
-
* When a `BehaviorSubject` is provided, the hook uses `getValue()` for the initial render.
|
|
10
|
-
* When a factory is provided, the observable is resolved lazily inside the effect.
|
|
11
|
-
*
|
|
12
|
-
* @param o Observable source or factory returning the source.
|
|
13
|
-
* @param default_value Fallback value used before the first emission when the source is not a `BehaviorSubject`.
|
|
14
|
-
* @returns The latest value emitted by the source.
|
|
15
|
-
*/
|
|
16
|
-
export declare const useObservable: <T extends any>(o: MaybeFunction<BehaviorSubject<T> | Observable<T>>, default_value?: T) => T;
|
|
3
|
+
export declare const useObservable: <T extends any, R = undefined>(o: MaybeFunction<BehaviorSubject<T> | Observable<T>> | undefined, default_value?: R) => T | R;
|
|
17
4
|
//# sourceMappingURL=useObservable.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useObservable.d.ts","sourceRoot":"","sources":["../src/useObservable.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAc,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"useObservable.d.ts","sourceRoot":"","sources":["../src/useObservable.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAc,MAAM,MAAM,CAAC;AAG/D,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAA;AAE5C,eAAO,MAAM,aAAa,GAAI,CAAC,SAAS,GAAG,EAAE,CAAC,GAAG,SAAS,EAAE,GAAG,aAAa,CAAC,eAAe,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,EAAE,gBAAgB,CAAC,UAkB9I,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
import { Observable, BehaviorSubject, tap, EMPTY } from "rxjs";
|
|
3
|
+
import { skip } from "rxjs/operators";
|
|
4
|
+
export const useObservable = (o, default_value) => {
|
|
5
|
+
const getValue = o?.getValue;
|
|
6
|
+
const [v, s] = useState(getValue ? getValue() : default_value);
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
try {
|
|
9
|
+
const target = (typeof o === 'function' ? o() : (o || EMPTY));
|
|
10
|
+
const subscription = target.pipe(skip(getValue ? 1 : 0), tap(value => {
|
|
11
|
+
s(value);
|
|
12
|
+
})).subscribe();
|
|
13
|
+
return () => {
|
|
14
|
+
subscription.unsubscribe();
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
catch (e) { }
|
|
18
|
+
}, typeof o === 'function' ? [] : [o]);
|
|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AU,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IACtC,OAAO,CAAC,CAAA;AACZ,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"url": "https://github.com/livequery/react"
|
|
5
5
|
},
|
|
6
6
|
"type": "module",
|
|
7
|
-
"version": "2.0.
|
|
7
|
+
"version": "2.0.96",
|
|
8
8
|
"description": "",
|
|
9
9
|
"main": "./dist/index.js",
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
@@ -13,13 +13,43 @@
|
|
|
13
13
|
"types": "./dist/index.d.ts",
|
|
14
14
|
"import": "./dist/index.js",
|
|
15
15
|
"default": "./dist/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./createContextFromHook": {
|
|
18
|
+
"types": "./dist/createContextFromHook.d.ts",
|
|
19
|
+
"import": "./dist/createContextFromHook.js",
|
|
20
|
+
"default": "./dist/createContextFromHook.js"
|
|
21
|
+
},
|
|
22
|
+
"./LivequeryCoreContext": {
|
|
23
|
+
"types": "./dist/LivequeryCoreContext.d.ts",
|
|
24
|
+
"import": "./dist/LivequeryCoreContext.js",
|
|
25
|
+
"default": "./dist/LivequeryCoreContext.js"
|
|
26
|
+
},
|
|
27
|
+
"./useAction": {
|
|
28
|
+
"types": "./dist/useAction.d.ts",
|
|
29
|
+
"import": "./dist/useAction.js",
|
|
30
|
+
"default": "./dist/useAction.js"
|
|
31
|
+
},
|
|
32
|
+
"./useCollection": {
|
|
33
|
+
"types": "./dist/useCollection.d.ts",
|
|
34
|
+
"import": "./dist/useCollection.js",
|
|
35
|
+
"default": "./dist/useCollection.js"
|
|
36
|
+
},
|
|
37
|
+
"./useDocument": {
|
|
38
|
+
"types": "./dist/useDocument.d.ts",
|
|
39
|
+
"import": "./dist/useDocument.js",
|
|
40
|
+
"default": "./dist/useDocument.js"
|
|
41
|
+
},
|
|
42
|
+
"./useObservable": {
|
|
43
|
+
"types": "./dist/useObservable.d.ts",
|
|
44
|
+
"import": "./dist/useObservable.js",
|
|
45
|
+
"default": "./dist/useObservable.js"
|
|
16
46
|
}
|
|
17
47
|
},
|
|
18
48
|
"files": [
|
|
19
49
|
"dist/**/*"
|
|
20
50
|
],
|
|
21
51
|
"dependencies": {
|
|
22
|
-
"@livequery/core": "^2.0.
|
|
52
|
+
"@livequery/core": "^2.0.96",
|
|
23
53
|
"rxjs": "^7.8.2"
|
|
24
54
|
},
|
|
25
55
|
"devDependencies": {
|
|
@@ -30,12 +60,10 @@
|
|
|
30
60
|
},
|
|
31
61
|
"scripts": {
|
|
32
62
|
"clean": "rm -rf dist",
|
|
33
|
-
"build:js": "bun build ./src/index.ts --outdir ./dist --target browser --format esm --sourcemap --packages=external --production",
|
|
34
|
-
"build:js:prod": "bun build ./src/index.ts --outdir ./dist --target browser --format esm --sourcemap --packages=external --production",
|
|
35
63
|
"build:types": "bunx tsc -p tsconfig.build.json",
|
|
36
|
-
"build": "bun run clean && bun run build:
|
|
37
|
-
"build:prod": "bun run
|
|
38
|
-
"build:watch": "
|
|
64
|
+
"build": "bun run clean && bun run build:types",
|
|
65
|
+
"build:prod": "bun run build",
|
|
66
|
+
"build:watch": "bunx tsc -p tsconfig.build.json --watch"
|
|
39
67
|
},
|
|
40
68
|
"author": "",
|
|
41
69
|
"license": "ISC"
|
package/dist/useGlobalValue.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Resolves a process-wide singleton value stored on `globalThis`.
|
|
3
|
-
*
|
|
4
|
-
* The resolver runs only the first time a given key is requested in the current runtime.
|
|
5
|
-
* Later calls with the same key return the cached value.
|
|
6
|
-
*
|
|
7
|
-
* @param key Unique key within the package global registry.
|
|
8
|
-
* @param resolver Lazy factory used when the value does not exist yet.
|
|
9
|
-
* @returns The cached or newly created value.
|
|
10
|
-
*/
|
|
11
|
-
export declare const useGlobalValue: <T>(key: string, resolver: () => T) => T;
|
|
12
|
-
//# sourceMappingURL=useGlobalValue.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useGlobalValue.d.ts","sourceRoot":"","sources":["../src/useGlobalValue.ts"],"names":[],"mappings":"AAIA;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc,GAAI,CAAC,EAAE,KAAK,MAAM,EAAE,UAAU,MAAM,CAAC,KAIzB,CACtC,CAAA"}
|