Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-rx

Package Overview
Dependencies
Maintainers
62
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-rx - npm Package Compare versions

Comparing version 4.1.2-canary.8 to 4.1.2-canary.9

107

dist/index.js

@@ -1,2 +0,3 @@

import { useMemo, useSyncExternalStore, useState, useEffect } from "react";
import { c } from "react-compiler-runtime";
import { useSyncExternalStore, useState, useEffect } from "react";
import { catchError, of, finalize, share, timer, asapScheduler } from "rxjs";

@@ -11,51 +12,67 @@ import { map, tap } from "rxjs/operators";

function useObservable(observable, initialValue, debug) {
const store = useMemo(() => {
if (!cache.has(observable)) {
const entry = {};
entry.observable = observable.pipe(
map((value) => ({ snapshot: value, error: void 0 })),
catchError((error) => of({ snapshot: void 0, error })),
tap(({ snapshot, error }) => {
debug && console.log("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);
}
const instance = cache.get(observable);
return {
subscribe: (onStoreChange) => {
debug && console.log("subscribe", observable);
const subscription = instance.observable.subscribe(() => {
debug && console.log("onStoreChange", observable), onStoreChange();
});
return () => {
debug && console.log("unsubscribe", observable), subscription.unsubscribe();
};
},
getSnapshot: () => {
if (debug && console.log("getSnapshot", instance.snapshot, instance.error), instance.error)
throw instance.error;
return instance.snapshot;
}
const $ = c(18);
let t0;
if (!cache.has(observable)) {
const entry = {};
entry.observable = observable.pipe(map((value) => ({
snapshot: value,
error: void 0
})), catchError((error) => of({
snapshot: void 0,
error
})), tap((t12) => {
const {
snapshot,
error: error_0
} = t12;
debug && console.log("tap", snapshot, error_0), entry.snapshot = snapshot, entry.error = error_0;
}), map((value_0) => {
}), finalize(() => cache.delete(observable)), share({
resetOnRefCountZero: () => timer(0, asapScheduler)
})), entry.observable.subscribe().unsubscribe(), cache.set(observable, entry);
}
let t1;
$[0] !== observable ? (t1 = cache.get(observable), $[0] = observable, $[1] = t1) : t1 = $[1];
const instance = t1;
let t2;
$[2] !== debug || $[3] !== observable || $[4] !== instance.observable ? (t2 = (onStoreChange) => {
debug && console.log("subscribe", observable);
const subscription_0 = instance.observable.subscribe(() => {
debug && console.log("onStoreChange", observable), onStoreChange();
});
return () => {
debug && console.log("unsubscribe", observable), subscription_0.unsubscribe();
};
}, [debug, observable]);
return useSyncExternalStore(
store.subscribe,
() => store.getSnapshot() ?? getValue(initialValue),
typeof initialValue > "u" ? void 0 : () => getValue(initialValue)
);
}, $[2] = debug, $[3] = observable, $[4] = instance.observable, $[5] = t2) : t2 = $[5];
let t3;
$[6] !== debug || $[7] !== instance.snapshot || $[8] !== instance.error ? (t3 = () => {
if (debug && console.log("getSnapshot", instance.snapshot, instance.error), instance.error)
throw instance.error;
return instance.snapshot;
}, $[6] = debug, $[7] = instance.snapshot, $[8] = instance.error, $[9] = t3) : t3 = $[9];
let t4;
$[10] !== t2 || $[11] !== t3 ? (t4 = {
subscribe: t2,
getSnapshot: t3
}, $[10] = t2, $[11] = t3, $[12] = t4) : t4 = $[12], t0 = t4;
const store = t0;
let t5;
$[13] !== store || $[14] !== initialValue ? (t5 = () => store.getSnapshot() ?? getValue(initialValue), $[13] = store, $[14] = initialValue, $[15] = t5) : t5 = $[15];
let t6;
return $[16] !== initialValue ? (t6 = typeof initialValue > "u" ? void 0 : () => getValue(initialValue), $[16] = initialValue, $[17] = t6) : t6 = $[17], useSyncExternalStore(store.subscribe, t5, t6);
}
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 {

@@ -62,0 +79,0 @@ useObservable,

{
"name": "react-rx",
"version": "4.1.2-canary.8",
"version": "4.1.2-canary.9",
"description": "React + RxJS = <3",

@@ -5,0 +5,0 @@ "keywords": [

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc