npm package diff
Package: react-rx
Versions: 4.0.1 - 4.1.0-canary.5
Modified: package/dist/index.cjs
Index: package/dist/index.cjs
===================================================================
--- package/dist/index.cjs
+++ package/dist/index.cjs
@@ -1,59 +1,77 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: !0 });
-var react = require("react"), rxjs = require("rxjs"), operators = require("rxjs/operators"), observableCallback = require("observable-callback"), useEffectEvent = require("use-effect-event");
+var reactCompilerRuntime = require("react-compiler-runtime"), react = require("react"), rxjs = require("rxjs"), operators = require("rxjs/operators"), observableCallback = require("observable-callback"), useEffectEvent = require("use-effect-event");
function getValue(value) {
return typeof value == "function" ? value() : value;
}
const cache = /* @__PURE__ */ new WeakMap();
function useObservable(observable, initialValue) {
+ const $ = reactCompilerRuntime.c(9);
if (!cache.has(observable)) {
const entry = {
snapshot: getValue(initialValue)
};
- entry.observable = observable.pipe(
- operators.map((value) => ({ snapshot: value, error: void 0 })),
- rxjs.catchError((error) => rxjs.of({ snapshot: void 0, error })),
- operators.tap(({ snapshot, error }) => {
- entry.snapshot = snapshot, entry.error = error;
- }),
- // Note: any value or error emitted by the provided observable will be mapped to the cache entry's mutable state
- // and the observable is thereafter only used as a notifier to call `onStoreChange`, hence the `void` return type.
- operators.map((value) => {
- }),
- // Ensure that the cache entry is deleted when the observable completes or errors.
- rxjs.finalize(() => cache.delete(observable)),
- rxjs.share({ resetOnRefCountZero: () => rxjs.timer(0, rxjs.asapScheduler) })
- ), entry.observable.subscribe().unsubscribe(), cache.set(observable, entry);
+ entry.observable = observable.pipe(operators.map(_temp$1), rxjs.catchError(_temp2), operators.tap((t02) => {
+ const {
+ snapshot,
+ error: error_0
+ } = t02;
+ entry.snapshot = snapshot, entry.error = error_0;
+ }), operators.map(_temp3), rxjs.finalize(() => cache.delete(observable)), rxjs.share({
+ resetOnRefCountZero: _temp4
+ })), entry.observable.subscribe().unsubscribe(), cache.set(observable, entry);
}
- const store = react.useMemo(() => {
- const instance = cache.get(observable);
- return {
- subscribe: (onStoreChange) => {
- const subscription = instance.observable.subscribe(onStoreChange);
- return () => {
- subscription.unsubscribe();
- };
- },
- getSnapshot: () => {
- if (instance.error)
- throw instance.error;
- return instance.snapshot;
- }
+ let t0;
+ $[0] !== observable ? (t0 = cache.get(observable), $[0] = observable, $[1] = t0) : t0 = $[1];
+ const instance = t0;
+ let t1;
+ $[2] !== instance.observable ? (t1 = (onStoreChange) => {
+ const subscription_0 = instance.observable.subscribe(onStoreChange);
+ return () => {
+ subscription_0.unsubscribe();
};
- }, [observable]);
- return react.useSyncExternalStore(
- store.subscribe,
- store.getSnapshot,
- typeof initialValue > "u" ? void 0 : () => getValue(initialValue)
- );
+ }, $[2] = instance.observable, $[3] = t1) : t1 = $[3];
+ const subscribe = t1;
+ let t2;
+ $[4] !== instance.error || $[5] !== instance.snapshot ? (t2 = () => {
+ if (instance.error)
+ throw instance.error;
+ return instance.snapshot;
+ }, $[4] = instance.error, $[5] = instance.snapshot, $[6] = t2) : t2 = $[6];
+ let t3;
+ return $[7] !== initialValue ? (t3 = typeof initialValue > "u" ? void 0 : () => getValue(initialValue), $[7] = initialValue, $[8] = t3) : t3 = $[8], react.useSyncExternalStore(subscribe, t2, t3);
}
+function _temp4() {
+ return rxjs.timer(0, rxjs.asapScheduler);
+}
+function _temp3(value_0) {
+}
+function _temp2(error) {
+ return rxjs.of({
+ snapshot: void 0,
+ error
+ });
+}
+function _temp$1(value) {
+ return {
+ snapshot: value,
+ error: void 0
+ };
+}
function useObservableEvent(handleEvent) {
- const [[calls$, call]] = react.useState(() => observableCallback.observableCallback()), onEvent = useEffectEvent.useEffectEvent((observable) => handleEvent(observable));
- return react.useEffect(() => {
- const subscription = calls$.pipe((observable) => onEvent(observable)).subscribe();
+ const $ = reactCompilerRuntime.c(6), [t0] = react.useState(_temp), [calls$, call] = t0;
+ let t1;
+ $[0] !== handleEvent ? (t1 = (observable) => handleEvent(observable), $[0] = handleEvent, $[1] = t1) : t1 = $[1];
+ const onEvent = useEffectEvent.useEffectEvent(t1);
+ let t2, t3;
+ return $[2] !== calls$ || $[3] !== onEvent ? (t2 = () => {
+ const subscription = calls$.pipe((observable_0) => onEvent(observable_0)).subscribe();
return () => subscription.unsubscribe();
- }, [calls$, onEvent]), call;
+ }, t3 = [calls$, onEvent], $[2] = calls$, $[3] = onEvent, $[4] = t2, $[5] = t3) : (t2 = $[4], t3 = $[5]), react.useEffect(t2, t3), call;
}
+function _temp() {
+ return observableCallback.observableCallback();
+}
exports.useObservable = useObservable;
exports.useObservableEvent = useObservableEvent;
//# sourceMappingURL=index.cjs.map
Modified: package/dist/index.js
Index: package/dist/index.js
===================================================================
--- package/dist/index.js
+++ package/dist/index.js
@@ -1,62 +1,81 @@
-import { useMemo, useSyncExternalStore, useState, useEffect } from "react";
-import { catchError, of, finalize, share, timer, asapScheduler } from "rxjs";
+import { c } from "react-compiler-runtime";
+import { useSyncExternalStore, useState, useEffect } from "react";
+import { catchError, finalize, share, timer, asapScheduler, of } from "rxjs";
import { map, tap } from "rxjs/operators";
import { observableCallback } from "observable-callback";
import { useEffectEvent } from "use-effect-event";
function getValue(value) {
return typeof value == "function" ? value() : value;
}
const cache = /* @__PURE__ */ new WeakMap();
function useObservable(observable, initialValue) {
+ const $ = c(9);
if (!cache.has(observable)) {
const entry = {
snapshot: getValue(initialValue)
};
- entry.observable = observable.pipe(
- map((value) => ({ snapshot: value, error: void 0 })),
- catchError((error) => of({ snapshot: void 0, error })),
- tap(({ snapshot, error }) => {
- entry.snapshot = snapshot, entry.error = error;
- }),
- // Note: any value or error emitted by the provided observable will be mapped to the cache entry's mutable state
- // and the observable is thereafter only used as a notifier to call `onStoreChange`, hence the `void` return type.
- map((value) => {
- }),
- // Ensure that the cache entry is deleted when the observable completes or errors.
- finalize(() => cache.delete(observable)),
- share({ resetOnRefCountZero: () => timer(0, asapScheduler) })
- ), entry.observable.subscribe().unsubscribe(), cache.set(observable, entry);
+ entry.observable = observable.pipe(map(_temp$1), catchError(_temp2), tap((t02) => {
+ const {
+ snapshot,
+ error: error_0
+ } = t02;
+ entry.snapshot = snapshot, entry.error = error_0;
+ }), map(_temp3), finalize(() => cache.delete(observable)), share({
+ resetOnRefCountZero: _temp4
+ })), entry.observable.subscribe().unsubscribe(), cache.set(observable, entry);
}
- const store = useMemo(() => {
- const instance = cache.get(observable);
- return {
- subscribe: (onStoreChange) => {
- const subscription = instance.observable.subscribe(onStoreChange);
- return () => {
- subscription.unsubscribe();
- };
- },
- getSnapshot: () => {
- if (instance.error)
- throw instance.error;
- return instance.snapshot;
- }
+ let t0;
+ $[0] !== observable ? (t0 = cache.get(observable), $[0] = observable, $[1] = t0) : t0 = $[1];
+ const instance = t0;
+ let t1;
+ $[2] !== instance.observable ? (t1 = (onStoreChange) => {
+ const subscription_0 = instance.observable.subscribe(onStoreChange);
+ return () => {
+ subscription_0.unsubscribe();
};
- }, [observable]);
- return useSyncExternalStore(
- store.subscribe,
- store.getSnapshot,
- typeof initialValue > "u" ? void 0 : () => getValue(initialValue)
- );
+ }, $[2] = instance.observable, $[3] = t1) : t1 = $[3];
+ const subscribe = t1;
+ let t2;
+ $[4] !== instance.error || $[5] !== instance.snapshot ? (t2 = () => {
+ if (instance.error)
+ throw instance.error;
+ return instance.snapshot;
+ }, $[4] = instance.error, $[5] = instance.snapshot, $[6] = t2) : t2 = $[6];
+ let t3;
+ return $[7] !== initialValue ? (t3 = typeof initialValue > "u" ? void 0 : () => getValue(initialValue), $[7] = initialValue, $[8] = t3) : t3 = $[8], useSyncExternalStore(subscribe, t2, t3);
}
+function _temp4() {
+ return timer(0, asapScheduler);
+}
+function _temp3(value_0) {
+}
+function _temp2(error) {
+ return of({
+ snapshot: void 0,
+ error
+ });
+}
+function _temp$1(value) {
+ return {
+ snapshot: value,
+ error: void 0
+ };
+}
function useObservableEvent(handleEvent) {
- const [[calls$, call]] = useState(() => observableCallback()), onEvent = useEffectEvent((observable) => handleEvent(observable));
- return useEffect(() => {
- const subscription = calls$.pipe((observable) => onEvent(observable)).subscribe();
+ const $ = c(6), [t0] = useState(_temp), [calls$, call] = t0;
+ let t1;
+ $[0] !== handleEvent ? (t1 = (observable) => handleEvent(observable), $[0] = handleEvent, $[1] = t1) : t1 = $[1];
+ const onEvent = useEffectEvent(t1);
+ let t2, t3;
+ return $[2] !== calls$ || $[3] !== onEvent ? (t2 = () => {
+ const subscription = calls$.pipe((observable_0) => onEvent(observable_0)).subscribe();
return () => subscription.unsubscribe();
- }, [calls$, onEvent]), call;
+ }, t3 = [calls$, onEvent], $[2] = calls$, $[3] = onEvent, $[4] = t2, $[5] = t3) : (t2 = $[4], t3 = $[5]), useEffect(t2, t3), call;
}
+function _temp() {
+ return observableCallback();
+}
export {
useObservable,
useObservableEvent
};
Modified: package/package.json
Index: package/package.json
===================================================================
--- package/package.json
+++ package/package.json
@@ -1,7 +1,7 @@
{
"name": "react-rx",
- "version": "4.0.1",
+ "version": "4.1.0-canary.5",
"description": "React + RxJS = <3",
"keywords": [
"action",
"behavior",
@@ -61,21 +61,13 @@
"files": [
"dist",
"src"
],
- "scripts": {
- "build": "pkg build --strict --clean --check",
- "dev": "pnpm --filter 'react-rx-website' dev",
- "format": "prettier --cache --write .",
- "lint": "eslint --cache .",
- "prepublishOnly": "pnpm build",
- "test": "vitest run --typecheck",
- "watch": "pnpm build -- --watch"
- },
"browserslist": "extends @sanity/browserslist-config",
"prettier": "@sanity/prettier-config",
"dependencies": {
"observable-callback": "^1.0.3",
+ "react-compiler-runtime": "19.0.0-beta-6fc168f-20241025",
"use-effect-event": "^1.0.2"
},
"devDependencies": {
"@sanity/pkg-utils": "^6.11.7",
@@ -87,8 +79,10 @@
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@typescript-eslint/eslint-plugin": "^8.12.2",
"@typescript-eslint/parser": "^8.12.2",
+ "@vitejs/plugin-react": "^4.3.3",
+ "babel-plugin-react-compiler": "beta",
"eslint": "^8.57.1",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-react": "^7.37.2",
@@ -105,9 +99,16 @@
"typescript": "5.6.3",
"vitest": "^2.1.4"
},
"peerDependencies": {
- "react": "^18.3 || >=19.0.0-rc",
+ "react": "^18.3 || >=19.0.0-0",
"rxjs": "^7"
},
- "packageManager": "[email protected]"
-}
+ "scripts": {
+ "build": "pkg build --strict --clean --check",
+ "dev": "pnpm --filter 'react-rx-website' dev",
+ "format": "prettier --cache --write .",
+ "lint": "eslint --cache .",
+ "test": "vitest run --typecheck",
+ "watch": "pnpm build -- --watch"
+ }
+}
\ No newline at end of file
Modified: package/dist/index.cjs.map
Index: package/dist/index.cjs.map
===================================================================
--- package/dist/index.cjs.map
+++ package/dist/index.cjs.map
@@ -1,1 +1,1 @@
-{"version":3,"file":"index.cjs","sources":["../src/useObservable.ts","../src/useObservableEvent.ts"],"sourcesContent":["import {useMemo, useSyncExternalStore} from 'react'\nimport {\n asapScheduler,\n catchError,\n finalize,\n type Observable,\n type ObservedValueOf,\n of,\n share,\n timer,\n} from 'rxjs'\nimport {map, tap} from 'rxjs/operators'\n\nfunction getValue<T>(value: T): T extends () => infer U ? U : T {\n return typeof value === 'function' ? value() : value\n}\n\ninterface CacheRecord<T> {\n observable: Observable<void>\n snapshot: T\n error?: unknown\n}\n\nconst cache = new WeakMap<Observable<any>, CacheRecord<any>>()\n\n/** @public */\nexport function useObservable<ObservableType extends Observable<any>>(\n observable: ObservableType,\n initialValue: ObservedValueOf<ObservableType> | (() => ObservedValueOf<ObservableType>),\n): ObservedValueOf<ObservableType>\n/** @public */\nexport function useObservable<ObservableType extends Observable<any>>(\n observable: ObservableType,\n): undefined | ObservedValueOf<ObservableType>\n/** @public */\nexport function useObservable<ObservableType extends Observable<any>, InitialValue>(\n observable: ObservableType,\n initialValue: InitialValue | (() => InitialValue),\n): InitialValue | ObservedValueOf<ObservableType>\n/** @public */\nexport function useObservable<ObservableType extends Observable<any>, InitialValue>(\n observable: ObservableType,\n initialValue?: InitialValue | (() => InitialValue),\n): InitialValue | ObservedValueOf<ObservableType> {\n if (!cache.has(observable)) {\n const entry: Partial<CacheRecord<ObservedValueOf<ObservableType>>> = {\n snapshot: getValue(initialValue) as ObservedValueOf<ObservableType>,\n }\n entry.observable = observable.pipe(\n map((value) => ({snapshot: value, error: undefined})),\n catchError((error) => of({snapshot: undefined, error})),\n tap(({snapshot, error}) => {\n entry.snapshot = snapshot\n entry.error = error\n }),\n // Note: any value or error emitted by the provided observable will be mapped to the cache entry's mutable state\n // and the observable is thereafter only used as a notifier to call `onStoreChange`, hence the `void` return type.\n map((value) => void value),\n // Ensure that the cache entry is deleted when the observable completes or errors.\n finalize(() => cache.delete(observable)),\n share({resetOnRefCountZero: () => timer(0, asapScheduler)}),\n )\n\n // Eagerly subscribe to sync set `entry.currentValue` to what the observable returns, and keep the observable alive until the component unmounts.\n const subscription = entry.observable.subscribe()\n subscription.unsubscribe()\n\n cache.set(observable, entry as CacheRecord<ObservedValueOf<ObservableType>>)\n }\n\n const store = useMemo(() => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const instance = cache.get(observable)!\n return {\n subscribe: (onStoreChange: () => void) => {\n const subscription = instance.observable.subscribe(onStoreChange)\n return () => {\n subscription.unsubscribe()\n }\n },\n getSnapshot: () => {\n if (instance.error) {\n throw instance.error\n }\n return instance.snapshot\n },\n }\n }, [observable])\n\n return useSyncExternalStore<ObservedValueOf<ObservableType>>(\n store.subscribe,\n store.getSnapshot,\n typeof initialValue === 'undefined'\n ? undefined\n : () => getValue(initialValue) as ObservedValueOf<ObservableType>,\n )\n}\n","import {observableCallback} from 'observable-callback'\nimport {useEffect, useState} from 'react'\nimport {type Observable} from 'rxjs'\nimport {useEffectEvent} from 'use-effect-event'\n\n/** @public */\nexport function useObservableEvent<T, U>(\n handleEvent: (arg: Observable<T>) => Observable<U>,\n): (arg: T) => void {\n const [[calls$, call]] = useState(() => observableCallback<T>())\n\n const onEvent = useEffectEvent((observable: Observable<T>) => handleEvent(observable))\n\n useEffect(() => {\n const subscription = calls$.pipe((observable) => onEvent(observable)).subscribe()\n return () => subscription.unsubscribe()\n }, [calls$, onEvent])\n\n return call\n}\n"],"names":["map","catchError","of","tap","finalize","share","timer","asapScheduler","useMemo","useSyncExternalStore","useState","observableCallback","useEffectEvent","useEffect"],"mappings":";;;AAaA,SAAS,SAAY,OAA2C;AAC9D,SAAO,OAAO,SAAU,aAAa,MAAU,IAAA;AACjD;AAQA,MAAM,4BAAY,QAA2C;AAiB7C,SAAA,cACd,YACA,cACgD;AAChD,MAAI,CAAC,MAAM,IAAI,UAAU,GAAG;AAC1B,UAAM,QAA+D;AAAA,MACnE,UAAU,SAAS,YAAY;AAAA,IACjC;AACA,UAAM,aAAa,WAAW;AAAA,MAC5BA,cAAI,CAAC,WAAW,EAAC,UAAU,OAAO,OAAO,SAAW;AAAA,MACpDC,gBAAW,CAAC,UAAUC,QAAG,EAAC,UAAU,QAAW,MAAK,CAAC,CAAC;AAAA,MACtDC,UAAAA,IAAI,CAAC,EAAC,UAAU,YAAW;AACnB,cAAA,WAAW,UACjB,MAAM,QAAQ;AAAA,MAAA,CACf;AAAA;AAAA;AAAA,MAGDH,UAAA,IAAI,CAAC,UAAO;AAAA,MAAA,CAAa;AAAA;AAAA,MAEzBI,KAAAA,SAAS,MAAM,MAAM,OAAO,UAAU,CAAC;AAAA,MACvCC,KAAA,MAAM,EAAC,qBAAqB,MAAMC,WAAM,GAAGC,KAAa,aAAA,EAAE,CAAA;AAAA,IAAA,GAIvC,MAAM,WAAW,YACzB,YAEb,GAAA,MAAM,IAAI,YAAY,KAAqD;AAAA,EAAA;AAGvE,QAAA,QAAQC,MAAAA,QAAQ,MAAM;AAEpB,UAAA,WAAW,MAAM,IAAI,UAAU;AAC9B,WAAA;AAAA,MACL,WAAW,CAAC,kBAA8B;AACxC,cAAM,eAAe,SAAS,WAAW,UAAU,aAAa;AAChE,eAAO,MAAM;AACX,uBAAa,YAAY;AAAA,QAC3B;AAAA,MACF;AAAA,MACA,aAAa,MAAM;AACjB,YAAI,SAAS;AACX,gBAAM,SAAS;AAEjB,eAAO,SAAS;AAAA,MAAA;AAAA,IAEpB;AAAA,EAAA,GACC,CAAC,UAAU,CAAC;AAER,SAAAC,MAAA;AAAA,IACL,MAAM;AAAA,IACN,MAAM;AAAA,IACN,OAAO,eAAiB,MACpB,SACA,MAAM,SAAS,YAAY;AAAA,EACjC;AACF;AC1FO,SAAS,mBACd,aACkB;AAClB,QAAM,CAAC,CAAC,QAAQ,IAAI,CAAC,IAAIC,MAAS,SAAA,MAAMC,mBAAAA,mBAAuB,CAAA,GAEzD,UAAUC,eAAAA,eAAe,CAAC,eAA8B,YAAY,UAAU,CAAC;AAErF,SAAAC,MAAA,UAAU,MAAM;AACR,UAAA,eAAe,OAAO,KAAK,CAAC,eAAe,QAAQ,UAAU,CAAC,EAAE,UAAU;AACzE,WAAA,MAAM,aAAa,YAAY;AAAA,EACrC,GAAA,CAAC,QAAQ,OAAO,CAAC,GAEb;AACT;;;"}
\ No newline at end of file
+{"version":3,"file":"index.cjs","sources":["../src/useObservable.ts","../src/useObservableEvent.ts"],"sourcesContent":["import {useCallback, useSyncExternalStore} from 'react'\nimport {\n asapScheduler,\n catchError,\n finalize,\n type Observable,\n type ObservedValueOf,\n of,\n share,\n timer,\n} from 'rxjs'\nimport {map, tap} from 'rxjs/operators'\n\nfunction getValue<T>(value: T): T extends () => infer U ? U : T {\n return typeof value === 'function' ? value() : value\n}\n\ninterface CacheRecord<T> {\n observable: Observable<void>\n snapshot: T\n error?: unknown\n}\n\nconst cache = new WeakMap<Observable<any>, CacheRecord<any>>()\n\n/** @public */\nexport function useObservable<ObservableType extends Observable<any>>(\n observable: ObservableType,\n initialValue: ObservedValueOf<ObservableType> | (() => ObservedValueOf<ObservableType>),\n): ObservedValueOf<ObservableType>\n/** @public */\nexport function useObservable<ObservableType extends Observable<any>>(\n observable: ObservableType,\n): undefined | ObservedValueOf<ObservableType>\n/** @public */\nexport function useObservable<ObservableType extends Observable<any>, InitialValue>(\n observable: ObservableType,\n initialValue: InitialValue | (() => InitialValue),\n): InitialValue | ObservedValueOf<ObservableType>\n/** @public */\nexport function useObservable<ObservableType extends Observable<any>, InitialValue>(\n observable: ObservableType,\n initialValue?: InitialValue | (() => InitialValue),\n): InitialValue | ObservedValueOf<ObservableType> {\n if (!cache.has(observable)) {\n const entry: Partial<CacheRecord<ObservedValueOf<ObservableType>>> = {\n snapshot: getValue(initialValue) as ObservedValueOf<ObservableType>,\n }\n entry.observable = observable.pipe(\n map((value) => ({snapshot: value, error: undefined})),\n catchError((error) => of({snapshot: undefined, error})),\n tap(({snapshot, error}) => {\n entry.snapshot = snapshot\n entry.error = error\n }),\n // Note: any value or error emitted by the provided observable will be mapped to the cache entry's mutable state\n // and the observable is thereafter only used as a notifier to call `onStoreChange`, hence the `void` return type.\n map((value) => void value),\n // Ensure that the cache entry is deleted when the observable completes or errors.\n finalize(() => cache.delete(observable)),\n share({resetOnRefCountZero: () => timer(0, asapScheduler)}),\n )\n\n // Eagerly subscribe to sync set `entry.currentValue` to what the observable returns, and keep the observable alive until the component unmounts.\n const subscription = entry.observable.subscribe()\n subscription.unsubscribe()\n\n cache.set(observable, entry as CacheRecord<ObservedValueOf<ObservableType>>)\n }\n const instance = cache.get(observable)!\n\n const subscribe = useCallback(\n (onStoreChange: () => void) => {\n const subscription = instance.observable.subscribe(onStoreChange)\n return () => {\n subscription.unsubscribe()\n }\n },\n [instance.observable],\n )\n\n return useSyncExternalStore<ObservedValueOf<ObservableType>>(\n subscribe,\n () => {\n if (instance.error) {\n throw instance.error\n }\n return instance.snapshot\n },\n typeof initialValue === 'undefined'\n ? undefined\n : () => getValue(initialValue) as ObservedValueOf<ObservableType>,\n )\n}\n","import {observableCallback} from 'observable-callback'\nimport {useEffect, useState} from 'react'\nimport {type Observable} from 'rxjs'\nimport {useEffectEvent} from 'use-effect-event'\n\n/** @public */\nexport function useObservableEvent<T, U>(\n handleEvent: (arg: Observable<T>) => Observable<U>,\n): (arg: T) => void {\n const [[calls$, call]] = useState(() => observableCallback<T>())\n\n const onEvent = useEffectEvent((observable: Observable<T>) => handleEvent(observable))\n\n useEffect(() => {\n const subscription = calls$.pipe((observable) => onEvent(observable)).subscribe()\n return () => subscription.unsubscribe()\n }, [calls$, onEvent])\n\n return call\n}\n"],"names":["getValue","value","cache","WeakMap","useObservable","observable","initialValue","$","_c","has","entry","snapshot","pipe","map","_temp","catchError","_temp2","tap","t0","error","error_0","_temp3","finalize","delete","share","resetOnRefCountZero","_temp4","subscribe","unsubscribe","set","get","instance","t1","onStoreChange","subscription_0","subscription","t2","t3","undefined","useSyncExternalStore","timer","asapScheduler","value_0","of","useObservableEvent","handleEvent","useState","calls$","call","onEvent","useEffectEvent","observable_0","useEffect","observableCallback"],"mappings":";;;AAaA,SAASA,SAAYC,OAA2C;AAC9D,SAAO,OAAOA,SAAU,aAAaA,MAAUA,IAAAA;AACjD;AAQA,MAAMC,4BAAYC,QAA2C;AAiBtDC,SAAAA,cAAAC,YAAAC,cAAA;AAAAC,QAAAA,IAAAC,uBAAA,CAAA;AAAA,MAAA,CAIAN,MAAAO,IAAUJ,UAAU,GAAC;AACxB,UAAAK,QAAA;AAAA,MAAAC,UACYX,SAASM,YAAY;AAAA,IAAC;AAE7BD,UAAAA,aAAcA,WAAUO,KAC3BC,UAAAA,IAAAC,OAAoD,GACpDC,KAAAA,WAAAC,MAAsD,GACtDC,UAAAC,IAAAA,CAAAA,QAAA;AAAK,YAAA;AAAA,QAAAP;AAAAA,QAAAQ,OAAAC;AAAAA,MAAAA,IAAAF;AACEP,YAAAA,WAAYA,UACjBD,MAAKS,QAASA;AAAAA,IAAAA,CACf,GAGDN,UAAAA,IAAAQ,MAAyB,GAEzBC,KAAAA,SAAepB,MAAAA,MAAAqB,OAAalB,UAAU,CAAC,GACvCmB,WAAA;AAAA,MAAAC,qBAAAC;AAAAA,IAA0D,CAAA,CAC5D,GAGqBhB,MAAKL,WAAAsB,UACdC,EAAAA,YAEZ1B,GAAAA,MAAA2B,IAA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AVrD,SAAAL,QAAAb,OAAA;AAAA,SAAA;AAAA,IAAAU,UAS0BV;AAAAA,IAAKkB,OAAAmB;AAAAA,EAAA;AAAA;AC3C/B,SAAAM,mBAAAC,aAAA;AAAA,QAAAtC,IAAAC,qBAAAA,EAAA,CAAA,GAGL,CAAAU,EAAA,IAAyB4B,MAAAA,SAAAhC,KAAsC,GAAxD,CAAAiC,QAAAC,IAAA,IAAA9B;AAAcc,MAAAA;AAAAzB,WAAAsC,eAEUb,KAAA3B,CAAAA,eAA+BwC,YAAYxC,UAAU,GAACE,OAAAsC,aAAAtC,OAAAyB,MAAAA,KAAAzB,EAAA,CAAA;AAArF0C,QAAAA,UAAgBC,8BAAelB,EAAsD;AAAC,MAAAI,IAAAC;AAAA9B,SAAAA,EAAAwC,CAAAA,MAAAA,UAAAxC,SAAA0C,WAE5Eb,KAAAA,MAAA;AACRD,UAAAA,eAAqBY,OAAMnC,KAAAuC,CAAAA,iBAAsBF,QAAQ5C,YAAU,CAAC,EAACsB,UAAW;AAAC,WAAA,MACpEQ,aAAYP,YAAa;AAAA,EACrCS,GAAAA,KAAA,CAACU,QAAQE,OAAO,GAAC1C,OAAAwC,QAAAxC,OAAA0C,SAAA1C,OAAA6B,IAAA7B,OAAA8B,OAAAD,KAAA7B,EAAA,CAAA,GAAA8B,KAAA9B,EAAA,CAAA,IAHpB6C,MAAAA,UAAUhB,IAGPC,EAAiB,GAEbW;AAAI;AAZN,SAAAlC,QAAA;AAAA,SAGmCuC,sCAAsB;AAAC;;;"}
\ No newline at end of file
Modified: package/dist/index.js.map
Index: package/dist/index.js.map
===================================================================
--- package/dist/index.js.map
+++ package/dist/index.js.map
@@ -1,1 +1,1 @@
-{"version":3,"file":"index.js","sources":["../src/useObservable.ts","../src/useObservableEvent.ts"],"sourcesContent":["import {useMemo, useSyncExternalStore} from 'react'\nimport {\n asapScheduler,\n catchError,\n finalize,\n type Observable,\n type ObservedValueOf,\n of,\n share,\n timer,\n} from 'rxjs'\nimport {map, tap} from 'rxjs/operators'\n\nfunction getValue<T>(value: T): T extends () => infer U ? U : T {\n return typeof value === 'function' ? value() : value\n}\n\ninterface CacheRecord<T> {\n observable: Observable<void>\n snapshot: T\n error?: unknown\n}\n\nconst cache = new WeakMap<Observable<any>, CacheRecord<any>>()\n\n/** @public */\nexport function useObservable<ObservableType extends Observable<any>>(\n observable: ObservableType,\n initialValue: ObservedValueOf<ObservableType> | (() => ObservedValueOf<ObservableType>),\n): ObservedValueOf<ObservableType>\n/** @public */\nexport function useObservable<ObservableType extends Observable<any>>(\n observable: ObservableType,\n): undefined | ObservedValueOf<ObservableType>\n/** @public */\nexport function useObservable<ObservableType extends Observable<any>, InitialValue>(\n observable: ObservableType,\n initialValue: InitialValue | (() => InitialValue),\n): InitialValue | ObservedValueOf<ObservableType>\n/** @public */\nexport function useObservable<ObservableType extends Observable<any>, InitialValue>(\n observable: ObservableType,\n initialValue?: InitialValue | (() => InitialValue),\n): InitialValue | ObservedValueOf<ObservableType> {\n if (!cache.has(observable)) {\n const entry: Partial<CacheRecord<ObservedValueOf<ObservableType>>> = {\n snapshot: getValue(initialValue) as ObservedValueOf<ObservableType>,\n }\n entry.observable = observable.pipe(\n map((value) => ({snapshot: value, error: undefined})),\n catchError((error) => of({snapshot: undefined, error})),\n tap(({snapshot, error}) => {\n entry.snapshot = snapshot\n entry.error = error\n }),\n // Note: any value or error emitted by the provided observable will be mapped to the cache entry's mutable state\n // and the observable is thereafter only used as a notifier to call `onStoreChange`, hence the `void` return type.\n map((value) => void value),\n // Ensure that the cache entry is deleted when the observable completes or errors.\n finalize(() => cache.delete(observable)),\n share({resetOnRefCountZero: () => timer(0, asapScheduler)}),\n )\n\n // Eagerly subscribe to sync set `entry.currentValue` to what the observable returns, and keep the observable alive until the component unmounts.\n const subscription = entry.observable.subscribe()\n subscription.unsubscribe()\n\n cache.set(observable, entry as CacheRecord<ObservedValueOf<ObservableType>>)\n }\n\n const store = useMemo(() => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const instance = cache.get(observable)!\n return {\n subscribe: (onStoreChange: () => void) => {\n const subscription = instance.observable.subscribe(onStoreChange)\n return () => {\n subscription.unsubscribe()\n }\n },\n getSnapshot: () => {\n if (instance.error) {\n throw instance.error\n }\n return instance.snapshot\n },\n }\n }, [observable])\n\n return useSyncExternalStore<ObservedValueOf<ObservableType>>(\n store.subscribe,\n store.getSnapshot,\n typeof initialValue === 'undefined'\n ? undefined\n : () => getValue(initialValue) as ObservedValueOf<ObservableType>,\n )\n}\n","import {observableCallback} from 'observable-callback'\nimport {useEffect, useState} from 'react'\nimport {type Observable} from 'rxjs'\nimport {useEffectEvent} from 'use-effect-event'\n\n/** @public */\nexport function useObservableEvent<T, U>(\n handleEvent: (arg: Observable<T>) => Observable<U>,\n): (arg: T) => void {\n const [[calls$, call]] = useState(() => observableCallback<T>())\n\n const onEvent = useEffectEvent((observable: Observable<T>) => handleEvent(observable))\n\n useEffect(() => {\n const subscription = calls$.pipe((observable) => onEvent(observable)).subscribe()\n return () => subscription.unsubscribe()\n }, [calls$, onEvent])\n\n return call\n}\n"],"names":[],"mappings":";;;;;AAaA,SAAS,SAAY,OAA2C;AAC9D,SAAO,OAAO,SAAU,aAAa,MAAU,IAAA;AACjD;AAQA,MAAM,4BAAY,QAA2C;AAiB7C,SAAA,cACd,YACA,cACgD;AAChD,MAAI,CAAC,MAAM,IAAI,UAAU,GAAG;AAC1B,UAAM,QAA+D;AAAA,MACnE,UAAU,SAAS,YAAY;AAAA,IACjC;AACA,UAAM,aAAa,WAAW;AAAA,MAC5B,IAAI,CAAC,WAAW,EAAC,UAAU,OAAO,OAAO,SAAW;AAAA,MACpD,WAAW,CAAC,UAAU,GAAG,EAAC,UAAU,QAAW,MAAK,CAAC,CAAC;AAAA,MACtD,IAAI,CAAC,EAAC,UAAU,YAAW;AACnB,cAAA,WAAW,UACjB,MAAM,QAAQ;AAAA,MAAA,CACf;AAAA;AAAA;AAAA,MAGD,IAAI,CAAC,UAAO;AAAA,MAAA,CAAa;AAAA;AAAA,MAEzB,SAAS,MAAM,MAAM,OAAO,UAAU,CAAC;AAAA,MACvC,MAAM,EAAC,qBAAqB,MAAM,MAAM,GAAG,aAAa,EAAE,CAAA;AAAA,IAAA,GAIvC,MAAM,WAAW,YACzB,YAEb,GAAA,MAAM,IAAI,YAAY,KAAqD;AAAA,EAAA;AAGvE,QAAA,QAAQ,QAAQ,MAAM;AAEpB,UAAA,WAAW,MAAM,IAAI,UAAU;AAC9B,WAAA;AAAA,MACL,WAAW,CAAC,kBAA8B;AACxC,cAAM,eAAe,SAAS,WAAW,UAAU,aAAa;AAChE,eAAO,MAAM;AACX,uBAAa,YAAY;AAAA,QAC3B;AAAA,MACF;AAAA,MACA,aAAa,MAAM;AACjB,YAAI,SAAS;AACX,gBAAM,SAAS;AAEjB,eAAO,SAAS;AAAA,MAAA;AAAA,IAEpB;AAAA,EAAA,GACC,CAAC,UAAU,CAAC;AAER,SAAA;AAAA,IACL,MAAM;AAAA,IACN,MAAM;AAAA,IACN,OAAO,eAAiB,MACpB,SACA,MAAM,SAAS,YAAY;AAAA,EACjC;AACF;AC1FO,SAAS,mBACd,aACkB;AAClB,QAAM,CAAC,CAAC,QAAQ,IAAI,CAAC,IAAI,SAAS,MAAM,mBAAuB,CAAA,GAEzD,UAAU,eAAe,CAAC,eAA8B,YAAY,UAAU,CAAC;AAErF,SAAA,UAAU,MAAM;AACR,UAAA,eAAe,OAAO,KAAK,CAAC,eAAe,QAAQ,UAAU,CAAC,EAAE,UAAU;AACzE,WAAA,MAAM,aAAa,YAAY;AAAA,EACrC,GAAA,CAAC,QAAQ,OAAO,CAAC,GAEb;AACT;"}
\ No newline at end of file
+{"version":3,"file":"index.js","sources":["../src/useObservable.ts","../src/useObservableEvent.ts"],"sourcesContent":["import {useCallback, useSyncExternalStore} from 'react'\nimport {\n asapScheduler,\n catchError,\n finalize,\n type Observable,\n type ObservedValueOf,\n of,\n share,\n timer,\n} from 'rxjs'\nimport {map, tap} from 'rxjs/operators'\n\nfunction getValue<T>(value: T): T extends () => infer U ? U : T {\n return typeof value === 'function' ? value() : value\n}\n\ninterface CacheRecord<T> {\n observable: Observable<void>\n snapshot: T\n error?: unknown\n}\n\nconst cache = new WeakMap<Observable<any>, CacheRecord<any>>()\n\n/** @public */\nexport function useObservable<ObservableType extends Observable<any>>(\n observable: ObservableType,\n initialValue: ObservedValueOf<ObservableType> | (() => ObservedValueOf<ObservableType>),\n): ObservedValueOf<ObservableType>\n/** @public */\nexport function useObservable<ObservableType extends Observable<any>>(\n observable: ObservableType,\n): undefined | ObservedValueOf<ObservableType>\n/** @public */\nexport function useObservable<ObservableType extends Observable<any>, InitialValue>(\n observable: ObservableType,\n initialValue: InitialValue | (() => InitialValue),\n): InitialValue | ObservedValueOf<ObservableType>\n/** @public */\nexport function useObservable<ObservableType extends Observable<any>, InitialValue>(\n observable: ObservableType,\n initialValue?: InitialValue | (() => InitialValue),\n): InitialValue | ObservedValueOf<ObservableType> {\n if (!cache.has(observable)) {\n const entry: Partial<CacheRecord<ObservedValueOf<ObservableType>>> = {\n snapshot: getValue(initialValue) as ObservedValueOf<ObservableType>,\n }\n entry.observable = observable.pipe(\n map((value) => ({snapshot: value, error: undefined})),\n catchError((error) => of({snapshot: undefined, error})),\n tap(({snapshot, error}) => {\n entry.snapshot = snapshot\n entry.error = error\n }),\n // Note: any value or error emitted by the provided observable will be mapped to the cache entry's mutable state\n // and the observable is thereafter only used as a notifier to call `onStoreChange`, hence the `void` return type.\n map((value) => void value),\n // Ensure that the cache entry is deleted when the observable completes or errors.\n finalize(() => cache.delete(observable)),\n share({resetOnRefCountZero: () => timer(0, asapScheduler)}),\n )\n\n // Eagerly subscribe to sync set `entry.currentValue` to what the observable returns, and keep the observable alive until the component unmounts.\n const subscription = entry.observable.subscribe()\n subscription.unsubscribe()\n\n cache.set(observable, entry as CacheRecord<ObservedValueOf<ObservableType>>)\n }\n const instance = cache.get(observable)!\n\n const subscribe = useCallback(\n (onStoreChange: () => void) => {\n const subscription = instance.observable.subscribe(onStoreChange)\n return () => {\n subscription.unsubscribe()\n }\n },\n [instance.observable],\n )\n\n return useSyncExternalStore<ObservedValueOf<ObservableType>>(\n subscribe,\n () => {\n if (instance.error) {\n throw instance.error\n }\n return instance.snapshot\n },\n typeof initialValue === 'undefined'\n ? undefined\n : () => getValue(initialValue) as ObservedValueOf<ObservableType>,\n )\n}\n","import {observableCallback} from 'observable-callback'\nimport {useEffect, useState} from 'react'\nimport {type Observable} from 'rxjs'\nimport {useEffectEvent} from 'use-effect-event'\n\n/** @public */\nexport function useObservableEvent<T, U>(\n handleEvent: (arg: Observable<T>) => Observable<U>,\n): (arg: T) => void {\n const [[calls$, call]] = useState(() => observableCallback<T>())\n\n const onEvent = useEffectEvent((observable: Observable<T>) => handleEvent(observable))\n\n useEffect(() => {\n const subscription = calls$.pipe((observable) => onEvent(observable)).subscribe()\n return () => subscription.unsubscribe()\n }, [calls$, onEvent])\n\n return call\n}\n"],"names":["getValue","value","cache","WeakMap","useObservable","observable","initialValue","$","_c","has","entry","snapshot","pipe","map","_temp","catchError","_temp2","tap","t0","error","error_0","_temp3","finalize","delete","share","resetOnRefCountZero","_temp4","subscribe","unsubscribe","set","get","instance","t1","onStoreChange","subscription_0","subscription","t2","t3","undefined","useSyncExternalStore","timer","asapScheduler","value_0","of","useObservableEvent","handleEvent","useState","calls$","call","onEvent","useEffectEvent","observable_0","useEffect","observableCallback"],"mappings":";;;;;;AAaA,SAASA,SAAYC,OAA2C;AAC9D,SAAO,OAAOA,SAAU,aAAaA,MAAUA,IAAAA;AACjD;AAQA,MAAMC,4BAAYC,QAA2C;AAiBtDC,SAAAA,cAAAC,YAAAC,cAAA;AAAAC,QAAAA,IAAAC,EAAA,CAAA;AAAA,MAAA,CAIAN,MAAAO,IAAUJ,UAAU,GAAC;AACxB,UAAAK,QAAA;AAAA,MAAAC,UACYX,SAASM,YAAY;AAAA,IAAC;AAE7BD,UAAAA,aAAcA,WAAUO,KAC3BC,I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AEbW;AAAI;AAZN,SAAAlC,QAAA;AAAA,SAGmCuC,mBAAsB;AAAC;"}
\ No newline at end of file
Modified: package/src/useObservable.ts
Index: package/src/useObservable.ts
===================================================================
--- package/src/useObservable.ts
+++ package/src/useObservable.ts
@@ -1,5 +1,5 @@
-import {useMemo, useSyncExternalStore} from 'react'
+import {useCallback, useSyncExternalStore} from 'react'
import {
asapScheduler,
catchError,
finalize,
@@ -66,31 +66,28 @@
subscription.unsubscribe()
cache.set(observable, entry as CacheRecord<ObservedValueOf<ObservableType>>)
}
+ const instance = cache.get(observable)!
- const store = useMemo(() => {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- const instance = cache.get(observable)!
- return {
- subscribe: (onStoreChange: () => void) => {
- const subscription = instance.observable.subscribe(onStoreChange)
- return () => {
- subscription.unsubscribe()
- }
- },
- getSnapshot: () => {
- if (instance.error) {
- throw instance.error
- }
- return instance.snapshot
- },
- }
- }, [observable])
+ const subscribe = useCallback(
+ (onStoreChange: () => void) => {
+ const subscription = instance.observable.subscribe(onStoreChange)
+ return () => {
+ subscription.unsubscribe()
+ }
+ },
+ [instance.observable],
+ )
return useSyncExternalStore<ObservedValueOf<ObservableType>>(
- store.subscribe,
- store.getSnapshot,
+ subscribe,
+ () => {
+ if (instance.error) {
+ throw instance.error
+ }
+ return instance.snapshot
+ },
typeof initialValue === 'undefined'
? undefined
: () => getValue(initialValue) as ObservedValueOf<ObservableType>,
)