@tanstack/react-db 0.1.76 → 0.1.77
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/cjs/index.cjs +2 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +1 -0
- package/dist/cjs/useLiveQueryEffect.cjs +26 -0
- package/dist/cjs/useLiveQueryEffect.cjs.map +1 -0
- package/dist/cjs/useLiveQueryEffect.d.cts +27 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/useLiveQueryEffect.d.ts +27 -0
- package/dist/esm/useLiveQueryEffect.js +26 -0
- package/dist/esm/useLiveQueryEffect.js.map +1 -0
- package/package.json +2 -2
- package/src/index.ts +1 -0
- package/src/useLiveQueryEffect.ts +59 -0
package/dist/cjs/index.cjs
CHANGED
|
@@ -4,11 +4,13 @@ const useLiveQuery = require("./useLiveQuery.cjs");
|
|
|
4
4
|
const useLiveSuspenseQuery = require("./useLiveSuspenseQuery.cjs");
|
|
5
5
|
const usePacedMutations = require("./usePacedMutations.cjs");
|
|
6
6
|
const useLiveInfiniteQuery = require("./useLiveInfiniteQuery.cjs");
|
|
7
|
+
const useLiveQueryEffect = require("./useLiveQueryEffect.cjs");
|
|
7
8
|
const db = require("@tanstack/db");
|
|
8
9
|
exports.useLiveQuery = useLiveQuery.useLiveQuery;
|
|
9
10
|
exports.useLiveSuspenseQuery = useLiveSuspenseQuery.useLiveSuspenseQuery;
|
|
10
11
|
exports.usePacedMutations = usePacedMutations.usePacedMutations;
|
|
11
12
|
exports.useLiveInfiniteQuery = useLiveInfiniteQuery.useLiveInfiniteQuery;
|
|
13
|
+
exports.useLiveQueryEffect = useLiveQueryEffect.useLiveQueryEffect;
|
|
12
14
|
Object.defineProperty(exports, "createTransaction", {
|
|
13
15
|
enumerable: true,
|
|
14
16
|
get: () => db.createTransaction
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -2,6 +2,7 @@ export * from './useLiveQuery.cjs';
|
|
|
2
2
|
export * from './useLiveSuspenseQuery.cjs';
|
|
3
3
|
export * from './usePacedMutations.cjs';
|
|
4
4
|
export * from './useLiveInfiniteQuery.cjs';
|
|
5
|
+
export * from './useLiveQueryEffect.cjs';
|
|
5
6
|
export * from '@tanstack/db';
|
|
6
7
|
export type { Collection } from '@tanstack/db';
|
|
7
8
|
export { createTransaction } from '@tanstack/db';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const react = require("react");
|
|
4
|
+
const db = require("@tanstack/db");
|
|
5
|
+
function useLiveQueryEffect(config, deps = []) {
|
|
6
|
+
const configRef = react.useRef(config);
|
|
7
|
+
configRef.current = config;
|
|
8
|
+
react.useEffect(() => {
|
|
9
|
+
const effect = db.createEffect({
|
|
10
|
+
id: config.id,
|
|
11
|
+
query: config.query,
|
|
12
|
+
skipInitial: config.skipInitial,
|
|
13
|
+
onEnter: (event, ctx) => configRef.current.onEnter?.(event, ctx),
|
|
14
|
+
onUpdate: (event, ctx) => configRef.current.onUpdate?.(event, ctx),
|
|
15
|
+
onExit: (event, ctx) => configRef.current.onExit?.(event, ctx),
|
|
16
|
+
onBatch: (events, ctx) => configRef.current.onBatch?.(events, ctx),
|
|
17
|
+
onError: config.onError ? (error, event) => configRef.current.onError?.(error, event) : void 0,
|
|
18
|
+
onSourceError: config.onSourceError ? (error) => configRef.current.onSourceError?.(error) : void 0
|
|
19
|
+
});
|
|
20
|
+
return () => {
|
|
21
|
+
effect.dispose();
|
|
22
|
+
};
|
|
23
|
+
}, deps);
|
|
24
|
+
}
|
|
25
|
+
exports.useLiveQueryEffect = useLiveQueryEffect;
|
|
26
|
+
//# sourceMappingURL=useLiveQueryEffect.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLiveQueryEffect.cjs","sources":["../../src/useLiveQueryEffect.ts"],"sourcesContent":["import { useEffect, useRef } from 'react'\nimport { createEffect } from '@tanstack/db'\nimport type { Effect, EffectConfig } from '@tanstack/db'\n\n/**\n * React hook for creating a reactive effect that fires handlers when rows\n * enter, exit, or update within a query result.\n *\n * The effect is created on mount and disposed on unmount. If `deps` change,\n * the previous effect is disposed and a new one is created.\n *\n * @example\n * ```tsx\n * function ChatComponent() {\n * useLiveQueryEffect(\n * {\n * query: (q) => q.from({ msg: messages }).where(({ msg }) => eq(msg.role, 'user')),\n * skipInitial: true,\n * onEnter: async (event) => {\n * await generateResponse(event.value)\n * },\n * },\n * []\n * )\n *\n * return <div>...</div>\n * }\n * ```\n */\nexport function useLiveQueryEffect<\n TRow extends object = Record<string, unknown>,\n TKey extends string | number = string | number,\n>(config: EffectConfig<TRow, TKey>, deps: React.DependencyList = []): void {\n const configRef = useRef<EffectConfig<TRow, TKey>>(config)\n configRef.current = config\n\n useEffect(() => {\n const effect: Effect = createEffect<TRow, TKey>({\n id: config.id,\n query: config.query,\n skipInitial: config.skipInitial,\n onEnter: (event, ctx) => configRef.current.onEnter?.(event, ctx),\n onUpdate: (event, ctx) => configRef.current.onUpdate?.(event, ctx),\n onExit: (event, ctx) => configRef.current.onExit?.(event, ctx),\n onBatch: (events, ctx) => configRef.current.onBatch?.(events, ctx),\n onError: config.onError\n ? (error, event) => configRef.current.onError?.(error, event)\n : undefined,\n onSourceError: config.onSourceError\n ? (error) => configRef.current.onSourceError?.(error)\n : undefined,\n })\n\n return () => {\n // Fire-and-forget disposal; AbortSignal cancels in-flight work\n effect.dispose()\n }\n }, deps)\n}\n"],"names":["useRef","useEffect","createEffect"],"mappings":";;;;AA6BO,SAAS,mBAGd,QAAkC,OAA6B,IAAU;AACzE,QAAM,YAAYA,MAAAA,OAAiC,MAAM;AACzD,YAAU,UAAU;AAEpBC,QAAAA,UAAU,MAAM;AACd,UAAM,SAAiBC,GAAAA,aAAyB;AAAA,MAC9C,IAAI,OAAO;AAAA,MACX,OAAO,OAAO;AAAA,MACd,aAAa,OAAO;AAAA,MACpB,SAAS,CAAC,OAAO,QAAQ,UAAU,QAAQ,UAAU,OAAO,GAAG;AAAA,MAC/D,UAAU,CAAC,OAAO,QAAQ,UAAU,QAAQ,WAAW,OAAO,GAAG;AAAA,MACjE,QAAQ,CAAC,OAAO,QAAQ,UAAU,QAAQ,SAAS,OAAO,GAAG;AAAA,MAC7D,SAAS,CAAC,QAAQ,QAAQ,UAAU,QAAQ,UAAU,QAAQ,GAAG;AAAA,MACjE,SAAS,OAAO,UACZ,CAAC,OAAO,UAAU,UAAU,QAAQ,UAAU,OAAO,KAAK,IAC1D;AAAA,MACJ,eAAe,OAAO,gBAClB,CAAC,UAAU,UAAU,QAAQ,gBAAgB,KAAK,IAClD;AAAA,IAAA,CACL;AAED,WAAO,MAAM;AAEX,aAAO,QAAA;AAAA,IACT;AAAA,EACF,GAAG,IAAI;AACT;;"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { EffectConfig } from '@tanstack/db';
|
|
2
|
+
/**
|
|
3
|
+
* React hook for creating a reactive effect that fires handlers when rows
|
|
4
|
+
* enter, exit, or update within a query result.
|
|
5
|
+
*
|
|
6
|
+
* The effect is created on mount and disposed on unmount. If `deps` change,
|
|
7
|
+
* the previous effect is disposed and a new one is created.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* function ChatComponent() {
|
|
12
|
+
* useLiveQueryEffect(
|
|
13
|
+
* {
|
|
14
|
+
* query: (q) => q.from({ msg: messages }).where(({ msg }) => eq(msg.role, 'user')),
|
|
15
|
+
* skipInitial: true,
|
|
16
|
+
* onEnter: async (event) => {
|
|
17
|
+
* await generateResponse(event.value)
|
|
18
|
+
* },
|
|
19
|
+
* },
|
|
20
|
+
* []
|
|
21
|
+
* )
|
|
22
|
+
*
|
|
23
|
+
* return <div>...</div>
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare function useLiveQueryEffect<TRow extends object = Record<string, unknown>, TKey extends string | number = string | number>(config: EffectConfig<TRow, TKey>, deps?: React.DependencyList): void;
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from './useLiveQuery.js';
|
|
|
2
2
|
export * from './useLiveSuspenseQuery.js';
|
|
3
3
|
export * from './usePacedMutations.js';
|
|
4
4
|
export * from './useLiveInfiniteQuery.js';
|
|
5
|
+
export * from './useLiveQueryEffect.js';
|
|
5
6
|
export * from '@tanstack/db';
|
|
6
7
|
export type { Collection } from '@tanstack/db';
|
|
7
8
|
export { createTransaction } from '@tanstack/db';
|
package/dist/esm/index.js
CHANGED
|
@@ -2,12 +2,14 @@ import { useLiveQuery } from "./useLiveQuery.js";
|
|
|
2
2
|
import { useLiveSuspenseQuery } from "./useLiveSuspenseQuery.js";
|
|
3
3
|
import { usePacedMutations } from "./usePacedMutations.js";
|
|
4
4
|
import { useLiveInfiniteQuery } from "./useLiveInfiniteQuery.js";
|
|
5
|
+
import { useLiveQueryEffect } from "./useLiveQueryEffect.js";
|
|
5
6
|
export * from "@tanstack/db";
|
|
6
7
|
import { createTransaction } from "@tanstack/db";
|
|
7
8
|
export {
|
|
8
9
|
createTransaction,
|
|
9
10
|
useLiveInfiniteQuery,
|
|
10
11
|
useLiveQuery,
|
|
12
|
+
useLiveQueryEffect,
|
|
11
13
|
useLiveSuspenseQuery,
|
|
12
14
|
usePacedMutations
|
|
13
15
|
};
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { EffectConfig } from '@tanstack/db';
|
|
2
|
+
/**
|
|
3
|
+
* React hook for creating a reactive effect that fires handlers when rows
|
|
4
|
+
* enter, exit, or update within a query result.
|
|
5
|
+
*
|
|
6
|
+
* The effect is created on mount and disposed on unmount. If `deps` change,
|
|
7
|
+
* the previous effect is disposed and a new one is created.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* function ChatComponent() {
|
|
12
|
+
* useLiveQueryEffect(
|
|
13
|
+
* {
|
|
14
|
+
* query: (q) => q.from({ msg: messages }).where(({ msg }) => eq(msg.role, 'user')),
|
|
15
|
+
* skipInitial: true,
|
|
16
|
+
* onEnter: async (event) => {
|
|
17
|
+
* await generateResponse(event.value)
|
|
18
|
+
* },
|
|
19
|
+
* },
|
|
20
|
+
* []
|
|
21
|
+
* )
|
|
22
|
+
*
|
|
23
|
+
* return <div>...</div>
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare function useLiveQueryEffect<TRow extends object = Record<string, unknown>, TKey extends string | number = string | number>(config: EffectConfig<TRow, TKey>, deps?: React.DependencyList): void;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { useRef, useEffect } from "react";
|
|
2
|
+
import { createEffect } from "@tanstack/db";
|
|
3
|
+
function useLiveQueryEffect(config, deps = []) {
|
|
4
|
+
const configRef = useRef(config);
|
|
5
|
+
configRef.current = config;
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
const effect = createEffect({
|
|
8
|
+
id: config.id,
|
|
9
|
+
query: config.query,
|
|
10
|
+
skipInitial: config.skipInitial,
|
|
11
|
+
onEnter: (event, ctx) => configRef.current.onEnter?.(event, ctx),
|
|
12
|
+
onUpdate: (event, ctx) => configRef.current.onUpdate?.(event, ctx),
|
|
13
|
+
onExit: (event, ctx) => configRef.current.onExit?.(event, ctx),
|
|
14
|
+
onBatch: (events, ctx) => configRef.current.onBatch?.(events, ctx),
|
|
15
|
+
onError: config.onError ? (error, event) => configRef.current.onError?.(error, event) : void 0,
|
|
16
|
+
onSourceError: config.onSourceError ? (error) => configRef.current.onSourceError?.(error) : void 0
|
|
17
|
+
});
|
|
18
|
+
return () => {
|
|
19
|
+
effect.dispose();
|
|
20
|
+
};
|
|
21
|
+
}, deps);
|
|
22
|
+
}
|
|
23
|
+
export {
|
|
24
|
+
useLiveQueryEffect
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=useLiveQueryEffect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLiveQueryEffect.js","sources":["../../src/useLiveQueryEffect.ts"],"sourcesContent":["import { useEffect, useRef } from 'react'\nimport { createEffect } from '@tanstack/db'\nimport type { Effect, EffectConfig } from '@tanstack/db'\n\n/**\n * React hook for creating a reactive effect that fires handlers when rows\n * enter, exit, or update within a query result.\n *\n * The effect is created on mount and disposed on unmount. If `deps` change,\n * the previous effect is disposed and a new one is created.\n *\n * @example\n * ```tsx\n * function ChatComponent() {\n * useLiveQueryEffect(\n * {\n * query: (q) => q.from({ msg: messages }).where(({ msg }) => eq(msg.role, 'user')),\n * skipInitial: true,\n * onEnter: async (event) => {\n * await generateResponse(event.value)\n * },\n * },\n * []\n * )\n *\n * return <div>...</div>\n * }\n * ```\n */\nexport function useLiveQueryEffect<\n TRow extends object = Record<string, unknown>,\n TKey extends string | number = string | number,\n>(config: EffectConfig<TRow, TKey>, deps: React.DependencyList = []): void {\n const configRef = useRef<EffectConfig<TRow, TKey>>(config)\n configRef.current = config\n\n useEffect(() => {\n const effect: Effect = createEffect<TRow, TKey>({\n id: config.id,\n query: config.query,\n skipInitial: config.skipInitial,\n onEnter: (event, ctx) => configRef.current.onEnter?.(event, ctx),\n onUpdate: (event, ctx) => configRef.current.onUpdate?.(event, ctx),\n onExit: (event, ctx) => configRef.current.onExit?.(event, ctx),\n onBatch: (events, ctx) => configRef.current.onBatch?.(events, ctx),\n onError: config.onError\n ? (error, event) => configRef.current.onError?.(error, event)\n : undefined,\n onSourceError: config.onSourceError\n ? (error) => configRef.current.onSourceError?.(error)\n : undefined,\n })\n\n return () => {\n // Fire-and-forget disposal; AbortSignal cancels in-flight work\n effect.dispose()\n }\n }, deps)\n}\n"],"names":[],"mappings":";;AA6BO,SAAS,mBAGd,QAAkC,OAA6B,IAAU;AACzE,QAAM,YAAY,OAAiC,MAAM;AACzD,YAAU,UAAU;AAEpB,YAAU,MAAM;AACd,UAAM,SAAiB,aAAyB;AAAA,MAC9C,IAAI,OAAO;AAAA,MACX,OAAO,OAAO;AAAA,MACd,aAAa,OAAO;AAAA,MACpB,SAAS,CAAC,OAAO,QAAQ,UAAU,QAAQ,UAAU,OAAO,GAAG;AAAA,MAC/D,UAAU,CAAC,OAAO,QAAQ,UAAU,QAAQ,WAAW,OAAO,GAAG;AAAA,MACjE,QAAQ,CAAC,OAAO,QAAQ,UAAU,QAAQ,SAAS,OAAO,GAAG;AAAA,MAC7D,SAAS,CAAC,QAAQ,QAAQ,UAAU,QAAQ,UAAU,QAAQ,GAAG;AAAA,MACjE,SAAS,OAAO,UACZ,CAAC,OAAO,UAAU,UAAU,QAAQ,UAAU,OAAO,KAAK,IAC1D;AAAA,MACJ,eAAe,OAAO,gBAClB,CAAC,UAAU,UAAU,QAAQ,gBAAgB,KAAK,IAClD;AAAA,IAAA,CACL;AAED,WAAO,MAAM;AAEX,aAAO,QAAA;AAAA,IACT;AAAA,EACF,GAAG,IAAI;AACT;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-db",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.77",
|
|
4
4
|
"description": "React integration for @tanstack/db",
|
|
5
5
|
"author": "Kyle Mathews",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"use-sync-external-store": "^1.6.0",
|
|
43
|
-
"@tanstack/db": "0.5.
|
|
43
|
+
"@tanstack/db": "0.5.33"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"react": ">=16.8.0"
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react'
|
|
2
|
+
import { createEffect } from '@tanstack/db'
|
|
3
|
+
import type { Effect, EffectConfig } from '@tanstack/db'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* React hook for creating a reactive effect that fires handlers when rows
|
|
7
|
+
* enter, exit, or update within a query result.
|
|
8
|
+
*
|
|
9
|
+
* The effect is created on mount and disposed on unmount. If `deps` change,
|
|
10
|
+
* the previous effect is disposed and a new one is created.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* function ChatComponent() {
|
|
15
|
+
* useLiveQueryEffect(
|
|
16
|
+
* {
|
|
17
|
+
* query: (q) => q.from({ msg: messages }).where(({ msg }) => eq(msg.role, 'user')),
|
|
18
|
+
* skipInitial: true,
|
|
19
|
+
* onEnter: async (event) => {
|
|
20
|
+
* await generateResponse(event.value)
|
|
21
|
+
* },
|
|
22
|
+
* },
|
|
23
|
+
* []
|
|
24
|
+
* )
|
|
25
|
+
*
|
|
26
|
+
* return <div>...</div>
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export function useLiveQueryEffect<
|
|
31
|
+
TRow extends object = Record<string, unknown>,
|
|
32
|
+
TKey extends string | number = string | number,
|
|
33
|
+
>(config: EffectConfig<TRow, TKey>, deps: React.DependencyList = []): void {
|
|
34
|
+
const configRef = useRef<EffectConfig<TRow, TKey>>(config)
|
|
35
|
+
configRef.current = config
|
|
36
|
+
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
const effect: Effect = createEffect<TRow, TKey>({
|
|
39
|
+
id: config.id,
|
|
40
|
+
query: config.query,
|
|
41
|
+
skipInitial: config.skipInitial,
|
|
42
|
+
onEnter: (event, ctx) => configRef.current.onEnter?.(event, ctx),
|
|
43
|
+
onUpdate: (event, ctx) => configRef.current.onUpdate?.(event, ctx),
|
|
44
|
+
onExit: (event, ctx) => configRef.current.onExit?.(event, ctx),
|
|
45
|
+
onBatch: (events, ctx) => configRef.current.onBatch?.(events, ctx),
|
|
46
|
+
onError: config.onError
|
|
47
|
+
? (error, event) => configRef.current.onError?.(error, event)
|
|
48
|
+
: undefined,
|
|
49
|
+
onSourceError: config.onSourceError
|
|
50
|
+
? (error) => configRef.current.onSourceError?.(error)
|
|
51
|
+
: undefined,
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
return () => {
|
|
55
|
+
// Fire-and-forget disposal; AbortSignal cancels in-flight work
|
|
56
|
+
effect.dispose()
|
|
57
|
+
}
|
|
58
|
+
}, deps)
|
|
59
|
+
}
|