@pbkit/wrp
Advanced tools
Comparing version 0.0.10 to 0.0.11
@@ -35,2 +35,5 @@ "use strict"; | ||
}); | ||
setTimeout(() => { | ||
wait.reject(new Error("Handshake timeout.")); | ||
}, 500); | ||
await wait; | ||
@@ -37,0 +40,0 @@ return { |
import { PrimitiveAtom } from "jotai"; | ||
import { WrpAtomSet } from "./index"; | ||
import { createWrpChannel as createWrpChannelFn } from "../channel"; | ||
import { UseWrpIframeSocketResult } from "../react/useWrpIframeSocket"; | ||
export declare function useIframeWrpAtomSetUpdateEffect(primitiveWrpAtomSetAtom: PrimitiveAtom<WrpAtomSet>): UseWrpIframeSocketResult; | ||
export declare function useIframeWrpAtomSetUpdateEffect(primitiveWrpAtomSetAtom: PrimitiveAtom<WrpAtomSet>, createWrpChannel?: typeof createWrpChannelFn): UseWrpIframeSocketResult; |
@@ -7,4 +7,5 @@ "use strict"; | ||
const index_1 = require("./index"); | ||
const channel_1 = require("../channel"); | ||
const useWrpIframeSocket_1 = require("../react/useWrpIframeSocket"); | ||
function useIframeWrpAtomSetUpdateEffect(primitiveWrpAtomSetAtom) { | ||
function useIframeWrpAtomSetUpdateEffect(primitiveWrpAtomSetAtom, createWrpChannel = channel_1.createWrpChannel) { | ||
const setIframeAtomSet = (0, jotai_1.useSetAtom)(primitiveWrpAtomSetAtom); | ||
@@ -16,4 +17,4 @@ const useWrpIframeSocketResult = (0, useWrpIframeSocket_1.default)(); | ||
return; | ||
const socketAtom = (0, jotai_1.atom)(async () => socket); | ||
setIframeAtomSet((0, index_1.createWrpAtomSet)(socketAtom)); | ||
const channelAtom = (0, jotai_1.atom)(createWrpChannel(socket)); | ||
setIframeAtomSet((0, index_1.createWrpAtomSetFromSourceChannelAtom)(channelAtom)); | ||
}, [socket]); | ||
@@ -20,0 +21,0 @@ return useWrpIframeSocketResult; |
@@ -16,1 +16,2 @@ import { Atom } from "jotai"; | ||
export declare function createWrpAtomSet(socketAtom: SocketAtom): WrpAtomSet; | ||
export declare function createWrpAtomSetFromSourceChannelAtom(sourceChannelAtom: ChannelAtom): WrpAtomSet; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createWrpAtomSet = void 0; | ||
exports.createWrpAtomSetFromSourceChannelAtom = exports.createWrpAtomSet = void 0; | ||
const jotai_1 = require("jotai"); | ||
@@ -10,13 +10,22 @@ const utils_1 = require("jotai/utils"); | ||
function createWrpAtomSet(socketAtom) { | ||
const channelAndGuestAtom = (0, jotai_1.atom)(async (get) => { | ||
const channelAtom = (0, jotai_1.atom)((get) => { | ||
const socket = get(socketAtom); | ||
if (!socket) | ||
return; | ||
const realChannel = (0, channel_1.createWrpChannel)(socket); | ||
return (0, channel_1.createWrpChannel)(socket); | ||
}); | ||
return createWrpAtomSetFromSourceChannelAtom(channelAtom); | ||
} | ||
exports.createWrpAtomSet = createWrpAtomSet; | ||
function createWrpAtomSetFromSourceChannelAtom(sourceChannelAtom) { | ||
const channelAndGuestAtom = (0, jotai_1.atom)(async (get) => { | ||
const sourceChannel = get(sourceChannelAtom); | ||
if (!sourceChannel) | ||
return; | ||
const listeners = []; | ||
const guest = (0, guest_1.createWrpGuest)({ | ||
channel: { | ||
...realChannel, | ||
...sourceChannel, | ||
async *listen() { | ||
for await (const message of realChannel.listen()) { | ||
for await (const message of sourceChannel.listen()) { | ||
yield message; | ||
@@ -31,3 +40,3 @@ for (const listener of listeners) | ||
const channel = { | ||
...realChannel, | ||
...sourceChannel, | ||
async *listen() { | ||
@@ -54,2 +63,2 @@ while (true) { | ||
} | ||
exports.createWrpAtomSet = createWrpAtomSet; | ||
exports.createWrpAtomSetFromSourceChannelAtom = createWrpAtomSetFromSourceChannelAtom; |
{ | ||
"name": "@pbkit/wrp", | ||
"version": "0.0.10", | ||
"version": "0.0.11", | ||
"author": "JongChan Choi <jong@chan.moe>", | ||
@@ -5,0 +5,0 @@ "license": "(MIT OR Apache-2.0)", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
133167
2783