@pond-ts/react 0.4.1

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.
@@ -0,0 +1,7 @@
1
+ export { useLiveSeries } from './useLiveSeries.js';
2
+ export { useTimeSeries } from './useTimeSeries.js';
3
+ export { useSnapshot, type UseSnapshotOptions } from './useSnapshot.js';
4
+ export { useWindow } from './useWindow.js';
5
+ export { useDerived } from './useDerived.js';
6
+ export { takeSnapshot } from './takeSnapshot.js';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,KAAK,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ // @pond-ts/react — React hooks for pond-ts live time series
2
+ export { useLiveSeries } from './useLiveSeries.js';
3
+ export { useTimeSeries } from './useTimeSeries.js';
4
+ export { useSnapshot } from './useSnapshot.js';
5
+ export { useWindow } from './useWindow.js';
6
+ export { useDerived } from './useDerived.js';
7
+ export { takeSnapshot } from './takeSnapshot.js';
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAE5D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,WAAW,EAA2B,MAAM,kBAAkB,CAAC;AACxE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { TimeSeries } from 'pond-ts';
2
+ import type { LiveSource, SeriesSchema } from 'pond-ts';
3
+ /**
4
+ * Build a `TimeSeries` snapshot from any `LiveSource`.
5
+ *
6
+ * Checks for dedicated snapshot methods first (`toTimeSeries`, `snapshot`),
7
+ * then falls back to iterating `at()` + `length` for sources like
8
+ * `LiveRollingAggregation` that lack a built-in snapshot.
9
+ */
10
+ export declare function takeSnapshot<S extends SeriesSchema>(source: LiveSource<S>): TimeSeries<S> | null;
11
+ //# sourceMappingURL=takeSnapshot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"takeSnapshot.d.ts","sourceRoot":"","sources":["../src/takeSnapshot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAExD;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,YAAY,EACjD,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,GACpB,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI,CAuCtB"}
@@ -0,0 +1,43 @@
1
+ import { TimeSeries } from 'pond-ts';
2
+ /**
3
+ * Build a `TimeSeries` snapshot from any `LiveSource`.
4
+ *
5
+ * Checks for dedicated snapshot methods first (`toTimeSeries`, `snapshot`),
6
+ * then falls back to iterating `at()` + `length` for sources like
7
+ * `LiveRollingAggregation` that lack a built-in snapshot.
8
+ */
9
+ export function takeSnapshot(source) {
10
+ if (source.length === 0)
11
+ return null;
12
+ // LiveSeries, LiveView
13
+ if ('toTimeSeries' in source &&
14
+ typeof source.toTimeSeries === 'function') {
15
+ return source.toTimeSeries();
16
+ }
17
+ // LiveAggregation
18
+ if ('snapshot' in source &&
19
+ typeof source.snapshot === 'function') {
20
+ return source.snapshot();
21
+ }
22
+ // Fallback: reconstruct rows from LiveSource interface
23
+ const schema = source.schema;
24
+ const rows = [];
25
+ for (let i = 0; i < source.length; i++) {
26
+ const event = source.at(i);
27
+ if (!event)
28
+ continue;
29
+ const row = [event.key()];
30
+ for (let col = 1; col < schema.length; col++) {
31
+ row.push(event.get(schema[col].name));
32
+ }
33
+ rows.push(row);
34
+ }
35
+ if (rows.length === 0)
36
+ return null;
37
+ return new TimeSeries({
38
+ name: source.name,
39
+ schema,
40
+ rows: rows,
41
+ });
42
+ }
43
+ //# sourceMappingURL=takeSnapshot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"takeSnapshot.js","sourceRoot":"","sources":["../src/takeSnapshot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGrC;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAC1B,MAAqB;IAErB,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAErC,uBAAuB;IACvB,IACE,cAAc,IAAI,MAAM;QACxB,OAAQ,MAAkC,CAAC,YAAY,KAAK,UAAU,EACtE,CAAC;QACD,OAAQ,MAAuD,CAAC,YAAY,EAAE,CAAC;IACjF,CAAC;IAED,kBAAkB;IAClB,IACE,UAAU,IAAI,MAAM;QACpB,OAAQ,MAAkC,CAAC,QAAQ,KAAK,UAAU,EAClE,CAAC;QACD,OAAQ,MAAmD,CAAC,QAAQ,EAAE,CAAC;IACzE,CAAC;IAED,uDAAuD;IACvD,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAC7B,MAAM,IAAI,GAAgB,EAAE,CAAC;IAC7B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACvC,MAAM,KAAK,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAC3B,IAAI,CAAC,KAAK;YAAE,SAAS;QACrB,MAAM,GAAG,GAAc,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC;QACrC,KAAK,IAAI,GAAG,GAAG,CAAC,EAAE,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC;YAC7C,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAE,MAAM,CAAC,GAAG,CAAsB,CAAC,IAAI,CAAC,CAAC,CAAC;QAC9D,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACjB,CAAC;IAED,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAEnC,OAAO,IAAI,UAAU,CAAC;QACpB,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,MAAM;QACN,IAAI,EAAE,IAAW;KAClB,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,19 @@
1
+ import type { TimeSeries, SeriesSchema } from 'pond-ts';
2
+ /**
3
+ * Apply a batch transform to a `TimeSeries` snapshot, recomputing only when
4
+ * the input snapshot changes.
5
+ *
6
+ * The `transform` function should be referentially stable (wrap in
7
+ * `useCallback` if it captures changing dependencies). Returns `null` when the
8
+ * input snapshot is `null`.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * const [, snapshot] = useLiveSeries(opts);
13
+ * const smoothed = useDerived(snapshot, (s) =>
14
+ * s.smooth('cpu', 'ema', { alpha: 0.2 }),
15
+ * );
16
+ * ```
17
+ */
18
+ export declare function useDerived<S extends SeriesSchema, R>(series: TimeSeries<S> | null, transform: (series: TimeSeries<S>) => R): R | null;
19
+ //# sourceMappingURL=useDerived.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDerived.d.ts","sourceRoot":"","sources":["../src/useDerived.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAExD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,YAAY,EAAE,CAAC,EAClD,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI,EAC5B,SAAS,EAAE,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,GACtC,CAAC,GAAG,IAAI,CAMV"}
@@ -0,0 +1,26 @@
1
+ import { useMemo } from 'react';
2
+ /**
3
+ * Apply a batch transform to a `TimeSeries` snapshot, recomputing only when
4
+ * the input snapshot changes.
5
+ *
6
+ * The `transform` function should be referentially stable (wrap in
7
+ * `useCallback` if it captures changing dependencies). Returns `null` when the
8
+ * input snapshot is `null`.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * const [, snapshot] = useLiveSeries(opts);
13
+ * const smoothed = useDerived(snapshot, (s) =>
14
+ * s.smooth('cpu', 'ema', { alpha: 0.2 }),
15
+ * );
16
+ * ```
17
+ */
18
+ export function useDerived(series, transform) {
19
+ // eslint-disable-next-line react-hooks/exhaustive-deps
20
+ return useMemo(() => {
21
+ if (series === null)
22
+ return null;
23
+ return transform(series);
24
+ }, [series, transform]);
25
+ }
26
+ //# sourceMappingURL=useDerived.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDerived.js","sourceRoot":"","sources":["../src/useDerived.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAGhC;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,UAAU,CACxB,MAA4B,EAC5B,SAAuC;IAEvC,uDAAuD;IACvD,OAAO,OAAO,CAAC,GAAG,EAAE;QAClB,IAAI,MAAM,KAAK,IAAI;YAAE,OAAO,IAAI,CAAC;QACjC,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC;IAC3B,CAAC,EAAE,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { LiveSeries } from 'pond-ts';
2
+ import type { LiveSeriesOptions, SeriesSchema, TimeSeries } from 'pond-ts';
3
+ import { type UseSnapshotOptions } from './useSnapshot.js';
4
+ /**
5
+ * Create and own a `LiveSeries` for the component's lifetime.
6
+ *
7
+ * Returns `[live, snapshot]`:
8
+ * - `live` — a stable `LiveSeries` ref. Push events into it from effects or
9
+ * callbacks (e.g. WebSocket `onmessage`).
10
+ * - `snapshot` — a throttled `TimeSeries` that updates when new events arrive.
11
+ * `null` when the series is empty.
12
+ *
13
+ * The `LiveSeries` is created once on mount. Changing `options` after mount has
14
+ * no effect — pass stable options (literal or top-level constant).
15
+ */
16
+ export declare function useLiveSeries<S extends SeriesSchema>(options: LiveSeriesOptions<S>, hookOptions?: UseSnapshotOptions): [LiveSeries<S>, TimeSeries<S> | null];
17
+ //# sourceMappingURL=useLiveSeries.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLiveSeries.d.ts","sourceRoot":"","sources":["../src/useLiveSeries.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC3E,OAAO,EAAe,KAAK,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAExE;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,YAAY,EAClD,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAC7B,WAAW,CAAC,EAAE,kBAAkB,GAC/B,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAUvC"}
@@ -0,0 +1,25 @@
1
+ import { useRef } from 'react';
2
+ import { LiveSeries } from 'pond-ts';
3
+ import { useSnapshot } from './useSnapshot.js';
4
+ /**
5
+ * Create and own a `LiveSeries` for the component's lifetime.
6
+ *
7
+ * Returns `[live, snapshot]`:
8
+ * - `live` — a stable `LiveSeries` ref. Push events into it from effects or
9
+ * callbacks (e.g. WebSocket `onmessage`).
10
+ * - `snapshot` — a throttled `TimeSeries` that updates when new events arrive.
11
+ * `null` when the series is empty.
12
+ *
13
+ * The `LiveSeries` is created once on mount. Changing `options` after mount has
14
+ * no effect — pass stable options (literal or top-level constant).
15
+ */
16
+ export function useLiveSeries(options, hookOptions) {
17
+ // Create the LiveSeries once and keep it for the component lifetime.
18
+ const liveRef = useRef(undefined);
19
+ if (liveRef.current === undefined) {
20
+ liveRef.current = new LiveSeries(options);
21
+ }
22
+ const snapshot = useSnapshot(liveRef.current, hookOptions);
23
+ return [liveRef.current, snapshot];
24
+ }
25
+ //# sourceMappingURL=useLiveSeries.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLiveSeries.js","sourceRoot":"","sources":["../src/useLiveSeries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAErC,OAAO,EAAE,WAAW,EAA2B,MAAM,kBAAkB,CAAC;AAExE;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,aAAa,CAC3B,OAA6B,EAC7B,WAAgC;IAEhC,qEAAqE;IACrE,MAAM,OAAO,GAAG,MAAM,CAA4B,SAAS,CAAC,CAAC;IAC7D,IAAI,OAAO,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;QAClC,OAAO,CAAC,OAAO,GAAG,IAAI,UAAU,CAAC,OAAO,CAAC,CAAC;IAC5C,CAAC;IAED,MAAM,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;IAE3D,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;AACrC,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { LiveSource, SeriesSchema } from 'pond-ts';
2
+ import type { TimeSeries } from 'pond-ts';
3
+ export interface UseSnapshotOptions {
4
+ /** Minimum milliseconds between snapshot rebuilds. Default 100. Set to 0 for immediate. */
5
+ throttle?: number;
6
+ }
7
+ /**
8
+ * Subscribe to any `LiveSource` and return a throttled `TimeSeries` snapshot.
9
+ *
10
+ * The snapshot updates at most once per `throttle` interval (default 100 ms).
11
+ * Returns `null` when the source is empty.
12
+ */
13
+ export declare function useSnapshot<S extends SeriesSchema>(source: LiveSource<S>, options?: UseSnapshotOptions): TimeSeries<S> | null;
14
+ //# sourceMappingURL=useSnapshot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSnapshot.d.ts","sourceRoot":"","sources":["../src/useSnapshot.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACxD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAG1C,MAAM,WAAW,kBAAkB;IACjC,2FAA2F;IAC3F,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,YAAY,EAChD,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,EACrB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI,CAyCtB"}
@@ -0,0 +1,43 @@
1
+ import { useEffect, useRef, useState } from 'react';
2
+ import { takeSnapshot } from './takeSnapshot.js';
3
+ /**
4
+ * Subscribe to any `LiveSource` and return a throttled `TimeSeries` snapshot.
5
+ *
6
+ * The snapshot updates at most once per `throttle` interval (default 100 ms).
7
+ * Returns `null` when the source is empty.
8
+ */
9
+ export function useSnapshot(source, options) {
10
+ const throttleMs = options?.throttle ?? 100;
11
+ const [snapshot, setSnapshot] = useState(() => takeSnapshot(source));
12
+ // Track the latest source + throttle so the effect re-subscribes when they change.
13
+ const sourceRef = useRef(source);
14
+ sourceRef.current = source;
15
+ useEffect(() => {
16
+ // Re-snapshot on source change
17
+ setSnapshot(takeSnapshot(source));
18
+ let timer = null;
19
+ let pending = false;
20
+ const flush = () => {
21
+ timer = null;
22
+ pending = false;
23
+ setSnapshot(takeSnapshot(sourceRef.current));
24
+ };
25
+ const unsub = source.on('event', () => {
26
+ if (throttleMs === 0) {
27
+ setSnapshot(takeSnapshot(sourceRef.current));
28
+ return;
29
+ }
30
+ if (!pending) {
31
+ pending = true;
32
+ timer = setTimeout(flush, throttleMs);
33
+ }
34
+ });
35
+ return () => {
36
+ unsub();
37
+ if (timer !== null)
38
+ clearTimeout(timer);
39
+ };
40
+ }, [source, throttleMs]);
41
+ return snapshot;
42
+ }
43
+ //# sourceMappingURL=useSnapshot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSnapshot.js","sourceRoot":"","sources":["../src/useSnapshot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAGpD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAOjD;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CACzB,MAAqB,EACrB,OAA4B;IAE5B,MAAM,UAAU,GAAG,OAAO,EAAE,QAAQ,IAAI,GAAG,CAAC;IAC5C,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,CAAuB,GAAG,EAAE,CAClE,YAAY,CAAC,MAAM,CAAC,CACrB,CAAC;IAEF,mFAAmF;IACnF,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;IACjC,SAAS,CAAC,OAAO,GAAG,MAAM,CAAC;IAE3B,SAAS,CAAC,GAAG,EAAE;QACb,+BAA+B;QAC/B,WAAW,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC;QAElC,IAAI,KAAK,GAAyC,IAAI,CAAC;QACvD,IAAI,OAAO,GAAG,KAAK,CAAC;QAEpB,MAAM,KAAK,GAAG,GAAG,EAAE;YACjB,KAAK,GAAG,IAAI,CAAC;YACb,OAAO,GAAG,KAAK,CAAC;YAChB,WAAW,CAAC,YAAY,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;QAC/C,CAAC,CAAC;QAEF,MAAM,KAAK,GAAG,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;YACpC,IAAI,UAAU,KAAK,CAAC,EAAE,CAAC;gBACrB,WAAW,CAAC,YAAY,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;gBAC7C,OAAO;YACT,CAAC;YACD,IAAI,CAAC,OAAO,EAAE,CAAC;gBACb,OAAO,GAAG,IAAI,CAAC;gBACf,KAAK,GAAG,UAAU,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;YACxC,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,OAAO,GAAG,EAAE;YACV,KAAK,EAAE,CAAC;YACR,IAAI,KAAK,KAAK,IAAI;gBAAE,YAAY,CAAC,KAAK,CAAC,CAAC;QAC1C,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;IAEzB,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { TimeSeries } from 'pond-ts';
2
+ import type { SeriesSchema } from 'pond-ts';
3
+ /**
4
+ * Memoized `TimeSeries.fromJSON(...)` for static or fetched data.
5
+ *
6
+ * Re-parses only when `key` changes. If no `key` is provided, the input is
7
+ * serialized via `JSON.stringify` as the cache key — fine for small to
8
+ * moderate payloads. For large datasets, pass an explicit `key` (e.g. a fetch
9
+ * URL or ETag) to avoid the serialization cost.
10
+ */
11
+ export declare function useTimeSeries<S extends SeriesSchema, I extends Parameters<typeof TimeSeries.fromJSON<S>>[0]>(input: I, key?: string): TimeSeries<S>;
12
+ //# sourceMappingURL=useTimeSeries.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTimeSeries.d.ts","sourceRoot":"","sources":["../src/useTimeSeries.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAC3B,CAAC,SAAS,YAAY,EACtB,CAAC,SAAS,UAAU,CAAC,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EACtD,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC,CAKvC"}
@@ -0,0 +1,17 @@
1
+ import { useMemo } from 'react';
2
+ import { TimeSeries } from 'pond-ts';
3
+ /**
4
+ * Memoized `TimeSeries.fromJSON(...)` for static or fetched data.
5
+ *
6
+ * Re-parses only when `key` changes. If no `key` is provided, the input is
7
+ * serialized via `JSON.stringify` as the cache key — fine for small to
8
+ * moderate payloads. For large datasets, pass an explicit `key` (e.g. a fetch
9
+ * URL or ETag) to avoid the serialization cost.
10
+ */
11
+ export function useTimeSeries(input, key) {
12
+ // eslint-disable-next-line react-hooks/exhaustive-deps
13
+ const cacheKey = key ?? JSON.stringify(input);
14
+ // eslint-disable-next-line react-hooks/exhaustive-deps
15
+ return useMemo(() => TimeSeries.fromJSON(input), [cacheKey]);
16
+ }
17
+ //# sourceMappingURL=useTimeSeries.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTimeSeries.js","sourceRoot":"","sources":["../src/useTimeSeries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGrC;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAG3B,KAAQ,EAAE,GAAY;IACtB,uDAAuD;IACvD,MAAM,QAAQ,GAAG,GAAG,IAAI,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAC9C,uDAAuD;IACvD,OAAO,OAAO,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAI,KAAK,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;AAClE,CAAC"}
@@ -0,0 +1,16 @@
1
+ import type { LiveSource, SeriesSchema, TimeSeries } from 'pond-ts';
2
+ import type { RollingWindow } from 'pond-ts';
3
+ import { type UseSnapshotOptions } from './useSnapshot.js';
4
+ /** A `LiveSource` that supports `.window()` — `LiveSeries`, `LiveView`, accumulators. */
5
+ type Windowable<S extends SeriesSchema> = LiveSource<S> & {
6
+ window(size: RollingWindow): LiveSource<S>;
7
+ };
8
+ /**
9
+ * Create a windowed view of a live source and return a throttled snapshot.
10
+ *
11
+ * The view is created once per `source`/`size` pair and disposed on cleanup.
12
+ * Returns `null` when the window is empty.
13
+ */
14
+ export declare function useWindow<S extends SeriesSchema>(source: Windowable<S>, size: RollingWindow, options?: UseSnapshotOptions): TimeSeries<S> | null;
15
+ export {};
16
+ //# sourceMappingURL=useWindow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useWindow.d.ts","sourceRoot":"","sources":["../src/useWindow.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACpE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAe,KAAK,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAExE,yFAAyF;AACzF,KAAK,UAAU,CAAC,CAAC,SAAS,YAAY,IAAI,UAAU,CAAC,CAAC,CAAC,GAAG;IACxD,MAAM,CAAC,IAAI,EAAE,aAAa,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;CAC5C,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,YAAY,EAC9C,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,EACrB,IAAI,EAAE,aAAa,EACnB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI,CAYtB"}
@@ -0,0 +1,20 @@
1
+ import { useEffect, useMemo } from 'react';
2
+ import { useSnapshot } from './useSnapshot.js';
3
+ /**
4
+ * Create a windowed view of a live source and return a throttled snapshot.
5
+ *
6
+ * The view is created once per `source`/`size` pair and disposed on cleanup.
7
+ * Returns `null` when the window is empty.
8
+ */
9
+ export function useWindow(source, size, options) {
10
+ const view = useMemo(() => source.window(size), [source, size]);
11
+ useEffect(() => {
12
+ return () => {
13
+ if ('dispose' in view && typeof view.dispose === 'function') {
14
+ view.dispose();
15
+ }
16
+ };
17
+ }, [view]);
18
+ return useSnapshot(view, options);
19
+ }
20
+ //# sourceMappingURL=useWindow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useWindow.js","sourceRoot":"","sources":["../src/useWindow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAG3C,OAAO,EAAE,WAAW,EAA2B,MAAM,kBAAkB,CAAC;AAOxE;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CACvB,MAAqB,EACrB,IAAmB,EACnB,OAA4B;IAE5B,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;IAEhE,SAAS,CAAC,GAAG,EAAE;QACb,OAAO,GAAG,EAAE;YACV,IAAI,SAAS,IAAI,IAAI,IAAI,OAAQ,IAAY,CAAC,OAAO,KAAK,UAAU,EAAE,CAAC;gBACpE,IAAY,CAAC,OAAO,EAAE,CAAC;YAC1B,CAAC;QACH,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;IAEX,OAAO,WAAW,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AACpC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@pond-ts/react",
3
+ "version": "0.4.1",
4
+ "description": "React hooks for pond-ts live time series",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/pjm17971/pond-ts.git",
9
+ "directory": "packages/react"
10
+ },
11
+ "type": "module",
12
+ "main": "dist/index.js",
13
+ "types": "dist/index.d.ts",
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/index.d.ts",
17
+ "import": "./dist/index.js"
18
+ }
19
+ },
20
+ "engines": {
21
+ "node": ">=18"
22
+ },
23
+ "files": [
24
+ "dist"
25
+ ],
26
+ "scripts": {
27
+ "build": "tsc -p tsconfig.json",
28
+ "test": "vitest run",
29
+ "test:runtime": "vitest run"
30
+ },
31
+ "dependencies": {
32
+ "pond-ts": "^0.4.0"
33
+ },
34
+ "peerDependencies": {
35
+ "react": "^18.0.0 || ^19.0.0"
36
+ },
37
+ "devDependencies": {
38
+ "@testing-library/dom": "^10.4.1",
39
+ "@testing-library/react": "^16.3.2",
40
+ "@types/react": "^19.0.0",
41
+ "@types/react-dom": "^19.2.3",
42
+ "happy-dom": "^20.9.0",
43
+ "react": "^19.0.0",
44
+ "react-dom": "^19.2.5",
45
+ "typescript": "^5.6.3",
46
+ "vitest": "^2.1.4"
47
+ }
48
+ }