@livequery/react 2.0.16 → 2.0.17
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.
|
@@ -5,5 +5,7 @@ export type LivequeryContext = {
|
|
|
5
5
|
hooks?: TransporterHook[];
|
|
6
6
|
};
|
|
7
7
|
export declare function mergeTransporterHooks(...hooks: TransporterHook[]): TransporterHook;
|
|
8
|
-
export declare const useLivequeryContext: () =>
|
|
8
|
+
export declare const useLivequeryContext: () => {
|
|
9
|
+
transporter: Transporter;
|
|
10
|
+
};
|
|
9
11
|
export declare const LiveQueryContextProvider: (props: PropsWithChildren<LivequeryContext>) => React.JSX.Element;
|
|
@@ -6,9 +6,16 @@ export function mergeTransporterHooks(...hooks) {
|
|
|
6
6
|
return hooks.reduce((p, c) => (next) => p(() => c(next)), (next) => pipe(next()));
|
|
7
7
|
}
|
|
8
8
|
const LivequeryContext = createContext({});
|
|
9
|
-
export const useLivequeryContext = () =>
|
|
9
|
+
export const useLivequeryContext = () => {
|
|
10
|
+
const ctx = useContext(LivequeryContext);
|
|
11
|
+
if (!ctx.transporter)
|
|
12
|
+
throw 'MISSING_LIVEQUERY_TRANSPORTER';
|
|
13
|
+
return {
|
|
14
|
+
transporter: ctx.transporter
|
|
15
|
+
};
|
|
16
|
+
};
|
|
10
17
|
export const LiveQueryContextProvider = (props) => {
|
|
11
|
-
const ctx =
|
|
18
|
+
const ctx = useContext(LivequeryContext);
|
|
12
19
|
const merged = mergeTransporterHooks(...props.hooks || []);
|
|
13
20
|
const transporter = ctx.transporter ? ctx.transporter.hook(merged) : props.transporter?.hook(merged);
|
|
14
21
|
return (React.createElement(LivequeryContext.Provider, { value: { transporter } }, props.children));
|
|
@@ -9,8 +9,6 @@ function assert(fn, thiss) {
|
|
|
9
9
|
export const CollectionMap = new Map();
|
|
10
10
|
export const useCollectionData = (ref, collection_options = {}) => {
|
|
11
11
|
const { transporter } = useLivequeryContext();
|
|
12
|
-
if (!transporter)
|
|
13
|
-
throw 'MISSING_LIVEQUERY_TRANSPORTER';
|
|
14
12
|
const client = useMemo(() => new CollectionObservable(ref, {
|
|
15
13
|
...collection_options,
|
|
16
14
|
transporter
|