-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add createWrpAtomSetFromSourceChannelAtom
- Loading branch information
Showing
2 changed files
with
21 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,23 @@ | ||
import { useEffect } from "react"; | ||
import { atom, PrimitiveAtom, useSetAtom } from "jotai"; | ||
import { createWrpAtomSet, WrpAtomSet } from "./index.ts"; | ||
import { createWrpAtomSetFromSourceChannelAtom, WrpAtomSet } from "./index.ts"; | ||
import { createWrpChannel as createWrpChannelFn } from "../channel.ts"; | ||
import { | ||
default as useWrpIframeSocket, | ||
UseWrpIframeSocketResult, | ||
} from "../react/useWrpIframeSocket.ts"; | ||
|
||
export function useIframeWrpAtomSetUpdateEffect( | ||
primitiveWrpAtomSetAtom: PrimitiveAtom<WrpAtomSet>, | ||
createWrpChannel = createWrpChannelFn, | ||
): UseWrpIframeSocketResult { | ||
const setIframeAtomSet = useSetAtom(primitiveWrpAtomSetAtom); | ||
const useWrpIframeSocketResult = useWrpIframeSocket(); | ||
const { socket } = useWrpIframeSocketResult; | ||
useEffect(() => { | ||
if (!socket) return; | ||
const socketAtom = atom(async () => socket); | ||
setIframeAtomSet(createWrpAtomSet(socketAtom)); | ||
const channelAtom = atom(createWrpChannel(socket)); | ||
setIframeAtomSet(createWrpAtomSetFromSourceChannelAtom(channelAtom)); | ||
}, [socket]); | ||
return useWrpIframeSocketResult; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters