@toapi/react 1.0.1 → 8.0.0

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,11 @@
1
+ import type { Observable } from "@farbenmeer/tapi/client";
2
+ import * as React from "react";
3
+ type ObservablePromise<T> = Promise<T> & Observable<T>;
4
+ interface Options {
5
+ startTransition?: typeof React.startTransition;
6
+ onError?: (error: Error) => void;
7
+ swr?: boolean;
8
+ }
9
+ export declare function useLacy<T>(query: ObservablePromise<T> | (() => ObservablePromise<T>), options?: Options): import("@farbenmeer/lacy").LacyPromise<T, never>;
10
+ export {};
11
+ //# sourceMappingURL=use-lacy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-lacy.d.ts","sourceRoot":"","sources":["../src/use-lacy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,KAAK,iBAAiB,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;AAEvD,UAAU,OAAO;IACf,eAAe,CAAC,EAAE,OAAO,KAAK,CAAC,eAAe,CAAC;IAC/C,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAED,wBAAgB,OAAO,CAAC,CAAC,EACvB,KAAK,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,iBAAiB,CAAC,CAAC,CAAC,CAAC,EAC1D,OAAO,GAAE,OAAY,oDAuCtB"}
@@ -0,0 +1,35 @@
1
+ import * as React from "react";
2
+ import { lacy } from "@farbenmeer/lacy";
3
+ export function useLacy(query, options = {}) {
4
+ const optionsRef = React.useRef(options);
5
+ optionsRef.current = options;
6
+ const observable = React.useMemo(typeof query === "function" ? query : () => query, [query]);
7
+ const [data, setData] = React.useState(observable);
8
+ React.useEffect(() => {
9
+ const unsubscribe = observable.subscribe((next) => {
10
+ const { startTransition = React.startTransition, onError, swr, } = optionsRef.current;
11
+ startTransition(async () => {
12
+ if (swr) {
13
+ try {
14
+ await next;
15
+ setData(next);
16
+ }
17
+ catch (error) {
18
+ onError?.(error);
19
+ }
20
+ }
21
+ else {
22
+ setData(next);
23
+ try {
24
+ await next;
25
+ }
26
+ catch (error) {
27
+ onError?.(error);
28
+ }
29
+ }
30
+ });
31
+ });
32
+ return unsubscribe;
33
+ }, [observable]);
34
+ return React.useMemo(() => lacy(data), [data]);
35
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toapi/react",
3
- "version": "1.0.1",
3
+ "version": "8.0.0",
4
4
  "author": {
5
5
  "name": "Michel Smola",
6
6
  "email": "michel.smola@farbenmeer.de"
@@ -27,13 +27,13 @@
27
27
  "react": "^19.1.1",
28
28
  "vitest": "^4.0.16",
29
29
  "zod": "^4.1.5",
30
- "@toapi/client": "^1.0.1",
31
- "@toapi/server": "^1.0.1"
30
+ "@toapi/server": "^0.12.1",
31
+ "@toapi/client": "^0.12.1"
32
32
  },
33
33
  "peerDependencies": {
34
34
  "react": "^19.1.1",
35
35
  "typescript": "^5 || ^6.0.0",
36
- "@toapi/client": "^1.0.1"
36
+ "@toapi/client": "^0.12.1"
37
37
  },
38
38
  "scripts": {
39
39
  "build": "tsc -p tsconfig.build.json",