@player-ui/react-subscribe
Advanced tools
Comparing version
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/subscribe/src/index.tsx | ||
import React from "react"; | ||
import { useSyncExternalStore } from "use-sync-external-store/shim"; | ||
function deferred() { | ||
@@ -99,16 +100,32 @@ let resolve = () => void 0; | ||
function useSubscribedState(subscriber) { | ||
const [state, setState] = React.useState(subscriber.get()); | ||
React.useEffect(() => { | ||
const id = subscriber.add( | ||
(resp) => { | ||
setState(resp); | ||
}, | ||
{ | ||
initializeWithPreviousValue: true | ||
} | ||
); | ||
return () => { | ||
subscriber.remove(id); | ||
}; | ||
const subscription = React.useMemo(() => { | ||
function subscribe(callback) { | ||
const id = subscriber.add( | ||
(resp) => { | ||
callback(resp); | ||
}, | ||
{ | ||
initializeWithPreviousValue: true | ||
} | ||
); | ||
return () => { | ||
if (subscriber) { | ||
subscriber.remove(id); | ||
} | ||
}; | ||
} | ||
return subscribe; | ||
}, [subscriber]); | ||
function getSnapshot() { | ||
try { | ||
return subscriber.get(); | ||
} catch (err) { | ||
return void 0; | ||
} | ||
} | ||
const state = useSyncExternalStore( | ||
subscription, | ||
getSnapshot, | ||
() => void 0 | ||
); | ||
return state; | ||
@@ -115,0 +132,0 @@ } |
@@ -9,3 +9,3 @@ { | ||
"name": "@player-ui/react-subscribe", | ||
"version": "0.11.3--canary.666.24070", | ||
"version": "0.11.3--canary.666.24188", | ||
"main": "dist/cjs/index.cjs", | ||
@@ -25,2 +25,3 @@ "module": "dist/index.legacy-esm.js", | ||
"p-defer": "^3.0.0", | ||
"use-sync-external-store": "^1.5.0", | ||
"tslib": "^2.6.2" | ||
@@ -30,4 +31,5 @@ }, | ||
"@types/react": "^18.2.39", | ||
"@types/use-sync-external-store": "^1.5.0", | ||
"react": "^18.2.0" | ||
} | ||
} |
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
35107
13.34%719
16.34%6
50%+ Added
+ Added