@livequery/react 2.0.135 → 2.0.136
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/useObservable.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Observable, BehaviorSubject } from "rxjs";
|
|
2
2
|
export type MaybeFunction<T> = T | (() => T);
|
|
3
|
-
type
|
|
4
|
-
type ObservableSource<T> = MaybeFunction<Source<T>> | undefined;
|
|
3
|
+
type ObservableSource<T> = MaybeFunction<BehaviorSubject<T> | Observable<T>> | undefined;
|
|
5
4
|
export declare function useObservable<T>(o: BehaviorSubject<T>): T;
|
|
6
5
|
export declare function useObservable<T>(o: ObservableSource<T>): T | undefined;
|
|
7
6
|
export declare function useObservable<T>(o: ObservableSource<T>, default_value: T): T;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useObservable.d.ts","sourceRoot":"","sources":["../src/useObservable.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,eAAe,
|
|
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,KAAK,gBAAgB,CAAC,CAAC,IAAI,aAAa,CAAC,eAAe,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,CAAA;AAExF,wBAAgB,aAAa,CAAC,CAAC,EAAE,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;AAC1D,wBAAgB,aAAa,CAAC,CAAC,EAAE,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,SAAS,CAAA;AACvE,wBAAgB,aAAa,CAAC,CAAC,EAAE,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,CAAC,GAAG,CAAC,CAAA"}
|
package/dist/useObservable.js
CHANGED
|
@@ -1,28 +1,22 @@
|
|
|
1
1
|
import { useEffect, useRef, useState } from "react";
|
|
2
|
-
import { Observable, BehaviorSubject, tap } from "rxjs";
|
|
2
|
+
import { Observable, BehaviorSubject, tap, EMPTY } from "rxjs";
|
|
3
3
|
import { skip } from "rxjs/operators";
|
|
4
|
-
const isBehaviorSubject = (source) => {
|
|
5
|
-
return typeof source?.getValue === 'function';
|
|
6
|
-
};
|
|
7
|
-
const hasPipe = (source) => {
|
|
8
|
-
return typeof source?.pipe === 'function';
|
|
9
|
-
};
|
|
10
4
|
export function useObservable(o, default_value) {
|
|
11
|
-
const
|
|
12
|
-
const source =
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
const [v, s] = useState(() => isBehaviorSubject(source) ? source.getValue() : default_value);
|
|
5
|
+
const prev = useRef(o);
|
|
6
|
+
const source = o || EMPTY;
|
|
7
|
+
const isBehaviorSubject = typeof o == 'object' && typeof source.getValue === 'function';
|
|
8
|
+
const dfv = isBehaviorSubject ? source.getValue() : default_value;
|
|
9
|
+
const [v, s] = useState(dfv);
|
|
17
10
|
useEffect(() => {
|
|
18
|
-
const diff = prev.current !==
|
|
19
|
-
prev.current =
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
11
|
+
const diff = prev.current !== o;
|
|
12
|
+
prev.current = o;
|
|
13
|
+
try {
|
|
14
|
+
const subscription = source.pipe(skip(isBehaviorSubject && !diff ? 1 : 0), tap(s)).subscribe();
|
|
15
|
+
return () => {
|
|
16
|
+
subscription.unsubscribe();
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
catch (e) { }
|
|
26
20
|
}, typeof o === 'function' ? [] : [o]);
|
|
27
21
|
return v;
|
|
28
22
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useObservable.js","sourceRoot":"","sources":["../src/useObservable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"useObservable.js","sourceRoot":"","sources":["../src/useObservable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAC/D,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAUtC,MAAM,UAAU,aAAa,CAAI,CAAmB,EAAE,aAAiB;IACnE,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,CAAA;IACtB,MAAM,MAAM,GAAG,CAA8B,IAAI,KAAK,CAAA;IACtD,MAAM,iBAAiB,GAAE,OAAO,CAAC,IAAI,QAAQ,IAAK,OAAO,MAAM,CAAC,QAAQ,KAAK,UAAU,CAAA;IACvF,MAAM,GAAG,GAAG,iBAAiB,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,aAAa,CAAA;IACjE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,QAAQ,CAAgB,GAAG,CAAC,CAAA;IAC3C,SAAS,CAAC,GAAG,EAAE;QACX,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,KAAK,CAAC,CAAA;QAC/B,IAAI,CAAC,OAAO,GAAG,CAAC,CAAA;QAChB,IAAI,CAAC;YACD,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAC5B,IAAI,CAAC,iBAAiB,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EACxC,GAAG,CAAC,CAAC,CAAC,CACT,CAAC,SAAS,EAAE,CAAA;YACb,OAAO,GAAG,EAAE;gBACR,YAAY,CAAC,WAAW,EAAE,CAAA;YAC9B,CAAC,CAAA;QACL,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;IACnB,CAAC,EAAE,OAAO,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAEtC,OAAO,CAAC,CAAA;AACZ,CAAC"}
|
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.136",
|
|
8
8
|
"description": "",
|
|
9
9
|
"main": "./dist/index.js",
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
@@ -49,14 +49,14 @@
|
|
|
49
49
|
"dist/**/*"
|
|
50
50
|
],
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@livequery/client": "^2.0.
|
|
52
|
+
"@livequery/client": "^2.0.136",
|
|
53
53
|
"@types/bun": "^1.3.14",
|
|
54
54
|
"@types/react": "^19.2.14",
|
|
55
55
|
"@types/react-test-renderer": "^19.1.0",
|
|
56
56
|
"react-test-renderer": "^19.2.6"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
|
-
"@livequery/client": "^2.0.
|
|
59
|
+
"@livequery/client": "^2.0.136",
|
|
60
60
|
"react": "^19.2.5",
|
|
61
61
|
"rxjs": "^7.8.2"
|
|
62
62
|
},
|