react-rx 4.1.0-canary.1 → 4.1.0-canary.2

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/index.cjs CHANGED
@@ -6,7 +6,7 @@ function getValue(value) {
6
6
  }
7
7
  const cache = /* @__PURE__ */ new WeakMap();
8
8
  function useObservable(observable, initialValue) {
9
- const $ = reactCompilerRuntime.c(12);
9
+ const $ = reactCompilerRuntime.c(8);
10
10
  if (!cache.has(observable)) {
11
11
  const entry = {
12
12
  snapshot: getValue(initialValue)
@@ -27,27 +27,25 @@ function useObservable(observable, initialValue) {
27
27
  $[0] !== observable ? (t1 = cache.get(observable), $[0] = observable, $[1] = t1) : t1 = $[1];
28
28
  const instance = t1;
29
29
  let t2;
30
- $[2] !== instance.observable ? (t2 = (onStoreChange) => {
31
- console.count("subscribe");
32
- const subscription_0 = instance.observable.subscribe(onStoreChange);
33
- return () => {
34
- subscription_0.unsubscribe();
35
- };
36
- }, $[2] = instance.observable, $[3] = t2) : t2 = $[3];
30
+ $[2] !== instance.observable ? (t2 = {
31
+ subscribe: (onStoreChange) => {
32
+ console.count("subscribe");
33
+ const subscription_0 = instance.observable.subscribe(onStoreChange);
34
+ return () => {
35
+ subscription_0.unsubscribe();
36
+ };
37
+ }
38
+ }, $[2] = instance.observable, $[3] = t2) : t2 = $[3], t0 = t2;
39
+ const store = t0;
37
40
  let t3;
38
- $[4] !== instance.error || $[5] !== instance.snapshot ? (t3 = () => {
39
- if (console.count("getSnapshot"), instance.error)
40
- throw instance.error;
41
- return instance.snapshot;
42
- }, $[4] = instance.error, $[5] = instance.snapshot, $[6] = t3) : t3 = $[6];
41
+ $[4] !== observable ? (t3 = () => {
42
+ const instance_0 = cache.get(observable);
43
+ if (console.count("getSnapshot"), instance_0.error)
44
+ throw instance_0.error;
45
+ return instance_0.snapshot;
46
+ }, $[4] = observable, $[5] = t3) : t3 = $[5];
43
47
  let t4;
44
- $[7] !== t2 || $[8] !== t3 ? (t4 = {
45
- subscribe: t2,
46
- getSnapshot: t3
47
- }, $[7] = t2, $[8] = t3, $[9] = t4) : t4 = $[9], t0 = t4;
48
- const store = t0;
49
- let t5;
50
- return $[10] !== initialValue ? (t5 = typeof initialValue > "u" ? void 0 : () => getValue(initialValue), $[10] = initialValue, $[11] = t5) : t5 = $[11], react.useSyncExternalStore(store.subscribe, store.getSnapshot, t5);
48
+ return $[6] !== initialValue ? (t4 = typeof initialValue > "u" ? void 0 : () => getValue(initialValue), $[6] = initialValue, $[7] = t4) : t4 = $[7], react.useSyncExternalStore(store.subscribe, t3, t4);
51
49
  }
52
50
  function _temp4() {
53
51
  return rxjs.timer(0, rxjs.asapScheduler);
@@ -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 console.count('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 console.count('subscribe')\n const subscription = instance.observable.subscribe(onStoreChange)\n return () => {\n subscription.unsubscribe()\n }\n },\n getSnapshot: () => {\n console.count('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":["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","console","count","t1","get","instance","t2","onStoreChange","subscription_0","subscription","t3","t4","getSnapshot","store","t5","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,EAAA;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,IAAUxB,YAAYK,KAAqD;AAAA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mC6C,sCAAsB;AAAC;;;"}
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 console.count('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 console.count('subscribe')\n const subscription = instance.observable.subscribe(onStoreChange)\n return () => {\n subscription.unsubscribe()\n }\n },\n }\n }, [observable])\n\n return useSyncExternalStore<ObservedValueOf<ObservableType>>(\n store.subscribe,\n () => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const instance = cache.get(observable)!\n console.count('getSnapshot')\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","console","count","t1","get","instance","t2","onStoreChange","subscription_0","subscription","store","t3","instance_0","t4","undefined","useSyncExternalStore","timer","asapScheduler","value_0","of","useObservableEvent","handleEvent","useState","calls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,UAAU,GAACE,OAAA2C,aAAA3C,OAAAyB,MAAAA,KAAAzB,EAAA,CAAA;AAArF+C,QAAAA,UAAgBC,8BAAevB,EAAsD;AAAC,MAAAG,IAAAK;AAAAjC,SAAAA,EAAA6C,CAAAA,MAAAA,UAAA7C,SAAA+C,WAE5EnB,KAAAA,MAAA;AACRG,UAAAA,eAAqBc,OAAMxC,KAAA4C,CAAAA,iBAAsBF,QAAQjD,YAAU,CAAC,EAACsB,UAAW;AAAC,WAAA,MACpEW,aAAYV,YAAa;AAAA,EACrCY,GAAAA,KAAA,CAACY,QAAQE,OAAO,GAAC/C,OAAA6C,QAAA7C,OAAA+C,SAAA/C,OAAA4B,IAAA5B,OAAAiC,OAAAL,KAAA5B,EAAA,CAAA,GAAAiC,KAAAjC,EAAA,CAAA,IAHpBkD,MAAAA,UAAUtB,IAGPK,EAAiB,GAEba;AAAI;AAZN,SAAAvC,QAAA;AAAA,SAGmC4C,sCAAsB;AAAC;;;"}
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ function getValue(value) {
9
9
  }
10
10
  const cache = /* @__PURE__ */ new WeakMap();
11
11
  function useObservable(observable, initialValue) {
12
- const $ = c(12);
12
+ const $ = c(8);
13
13
  if (!cache.has(observable)) {
14
14
  const entry = {
15
15
  snapshot: getValue(initialValue)
@@ -30,27 +30,25 @@ function useObservable(observable, initialValue) {
30
30
  $[0] !== observable ? (t1 = cache.get(observable), $[0] = observable, $[1] = t1) : t1 = $[1];
31
31
  const instance = t1;
32
32
  let t2;
33
- $[2] !== instance.observable ? (t2 = (onStoreChange) => {
34
- console.count("subscribe");
35
- const subscription_0 = instance.observable.subscribe(onStoreChange);
36
- return () => {
37
- subscription_0.unsubscribe();
38
- };
39
- }, $[2] = instance.observable, $[3] = t2) : t2 = $[3];
33
+ $[2] !== instance.observable ? (t2 = {
34
+ subscribe: (onStoreChange) => {
35
+ console.count("subscribe");
36
+ const subscription_0 = instance.observable.subscribe(onStoreChange);
37
+ return () => {
38
+ subscription_0.unsubscribe();
39
+ };
40
+ }
41
+ }, $[2] = instance.observable, $[3] = t2) : t2 = $[3], t0 = t2;
42
+ const store = t0;
40
43
  let t3;
41
- $[4] !== instance.error || $[5] !== instance.snapshot ? (t3 = () => {
42
- if (console.count("getSnapshot"), instance.error)
43
- throw instance.error;
44
- return instance.snapshot;
45
- }, $[4] = instance.error, $[5] = instance.snapshot, $[6] = t3) : t3 = $[6];
44
+ $[4] !== observable ? (t3 = () => {
45
+ const instance_0 = cache.get(observable);
46
+ if (console.count("getSnapshot"), instance_0.error)
47
+ throw instance_0.error;
48
+ return instance_0.snapshot;
49
+ }, $[4] = observable, $[5] = t3) : t3 = $[5];
46
50
  let t4;
47
- $[7] !== t2 || $[8] !== t3 ? (t4 = {
48
- subscribe: t2,
49
- getSnapshot: t3
50
- }, $[7] = t2, $[8] = t3, $[9] = t4) : t4 = $[9], t0 = t4;
51
- const store = t0;
52
- let t5;
53
- return $[10] !== initialValue ? (t5 = typeof initialValue > "u" ? void 0 : () => getValue(initialValue), $[10] = initialValue, $[11] = t5) : t5 = $[11], useSyncExternalStore(store.subscribe, store.getSnapshot, t5);
51
+ return $[6] !== initialValue ? (t4 = typeof initialValue > "u" ? void 0 : () => getValue(initialValue), $[6] = initialValue, $[7] = t4) : t4 = $[7], useSyncExternalStore(store.subscribe, t3, t4);
54
52
  }
55
53
  function _temp4() {
56
54
  return timer(0, asapScheduler);
package/dist/index.js.map CHANGED
@@ -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 console.count('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 console.count('subscribe')\n const subscription = instance.observable.subscribe(onStoreChange)\n return () => {\n subscription.unsubscribe()\n }\n },\n getSnapshot: () => {\n console.count('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":["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","console","count","t1","get","instance","t2","onStoreChange","subscription_0","subscription","t3","t4","getSnapshot","store","t5","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,EAAA;AAAA,MAAA,CAIAN,MAAAO,IAAUJ,UAAU,GAAC;AACxB,UAAAK,QAAA;AAAA,MAAAC,UACYX,SAASM,YAAY;AAAA,IAAC;AAE7BD,UAAAA,aAAcA,WAAUO,KAC3BC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pB,KAAAA,MAAA;AACRG,UAAAA,eAAqBe,OAAMzC,KAAA6C,CAAAA,iBAAsBF,QAAQlD,YAAU,CAAC,EAACsB,UAAW;AAAC,WAAA,MACpEW,aAAYV,YAAa;AAAA,EACrCW,GAAAA,KAAA,CAACc,QAAQE,OAAO,GAAChD,OAAA8C,QAAA9C,OAAAgD,SAAAhD,OAAA4B,IAAA5B,OAAAgC,OAAAJ,KAAA5B,EAAA,CAAA,GAAAgC,KAAAhC,EAAA,CAAA,IAHpBmD,UAAUvB,IAGPI,EAAiB,GAEbe;AAAI;AAZN,SAAAxC,QAAA;AAAA,SAGmC6C,mBAAsB;AAAC;"}
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 console.count('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 console.count('subscribe')\n const subscription = instance.observable.subscribe(onStoreChange)\n return () => {\n subscription.unsubscribe()\n }\n },\n }\n }, [observable])\n\n return useSyncExternalStore<ObservedValueOf<ObservableType>>(\n store.subscribe,\n () => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const instance = cache.get(observable)!\n console.count('getSnapshot')\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","console","count","t1","get","instance","t2","onStoreChange","subscription_0","subscription","store","t3","instance_0","t4","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,IAAAC,OAAoD,GACpDC,WAAAC,MAAsD,GACtDC,IAAAC,CAAAA,QAAA;AAAK,YAAA;AAAA,QAAAP;AAAAA,QAAAQ,OAAAC;AAAAA,MAAAA,IAAAF;AACEP,YAAAA,WAAYA,UACjBD,MAAKS,QAASA;AAAAA,IAAAA,CACf,GAGDN,IAAAQ,MAAyB,GAEzBC,SAAepB,MAAAA,MAAAqB,OAAalB,UAAU,CAAC,GACvCmB,MAAA;AAAA,MAAAC,qBAAAC;AAAAA,IAA0D,CAAA,CAC5D,GAGqBhB,MAAKL,WAAAsB,UACdC,EAAAA,YAEZ1B,GAAAA,MAAA2B,IAAUxB,YAAYK,KAAqD;AAAA,EAAA;AAACQ,MAAAA;AAI5EY,UAAAC,MAAc,SAAS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SAAAL,QAAAb,OAAA;AAAA,SAAA;AAAA,IAAAU,UAS0BV;AAAAA,IAAKkB,OAAAwB;AAAAA,EAAA;AAAA;AC3C/B,SAAAM,mBAAAC,aAAA;AAAA,QAAA3C,IAAAC,EAAA,CAAA,GAGL,CAAAU,EAAA,IAAyBiC,SAAArC,KAAsC,GAAxD,CAAAsC,QAAAC,IAAA,IAAAnC;AAAcc,MAAAA;AAAAzB,WAAA2C,eAEUlB,KAAA3B,CAAAA,eAA+B6C,YAAY7C,UAAU,GAACE,OAAA2C,aAAA3C,OAAAyB,MAAAA,KAAAzB,EAAA,CAAA;AAArF+C,QAAAA,UAAgBC,eAAevB,EAAsD;AAAC,MAAAG,IAAAK;AAAAjC,SAAAA,EAAA6C,CAAAA,MAAAA,UAAA7C,SAAA+C,WAE5EnB,KAAAA,MAAA;AACRG,UAAAA,eAAqBc,OAAMxC,KAAA4C,CAAAA,iBAAsBF,QAAQjD,YAAU,CAAC,EAACsB,UAAW;AAAC,WAAA,MACpEW,aAAYV,YAAa;AAAA,EACrCY,GAAAA,KAAA,CAACY,QAAQE,OAAO,GAAC/C,OAAA6C,QAAA7C,OAAA+C,SAAA/C,OAAA4B,IAAA5B,OAAAiC,OAAAL,KAAA5B,EAAA,CAAA,GAAAiC,KAAAjC,EAAA,CAAA,IAHpBkD,UAAUtB,IAGPK,EAAiB,GAEba;AAAI;AAZN,SAAAvC,QAAA;AAAA,SAGmC4C,mBAAsB;AAAC;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-rx",
3
- "version": "4.1.0-canary.1",
3
+ "version": "4.1.0-canary.2",
4
4
  "description": "React + RxJS = <3",
5
5
  "keywords": [
6
6
  "action",
@@ -80,19 +80,20 @@ export function useObservable<ObservableType extends Observable<any>, InitialVal
80
80
  subscription.unsubscribe()
81
81
  }
82
82
  },
83
- getSnapshot: () => {
84
- console.count('getSnapshot')
85
- if (instance.error) {
86
- throw instance.error
87
- }
88
- return instance.snapshot
89
- },
90
83
  }
91
84
  }, [observable])
92
85
 
93
86
  return useSyncExternalStore<ObservedValueOf<ObservableType>>(
94
87
  store.subscribe,
95
- store.getSnapshot,
88
+ () => {
89
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
90
+ const instance = cache.get(observable)!
91
+ console.count('getSnapshot')
92
+ if (instance.error) {
93
+ throw instance.error
94
+ }
95
+ return instance.snapshot
96
+ },
96
97
  typeof initialValue === 'undefined'
97
98
  ? undefined
98
99
  : () => getValue(initialValue) as ObservedValueOf<ObservableType>,