Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
start(observer) {
const attachMessage = {
cmd: WorkerDOMMessageCommand.attach,
payload: {
selector: selector,
events: events,
options: options,
listenerId
}
}
tx.postMessage(attachMessage);
subscription = fromEvent(rx, 'message')
.filter(e => (e.data as WorkerDOMEvent).listenerId === listenerId)
.subscribe({
next (event) {
const payload = event.data.payload as EventSynthesis;
observer.next(payload);
},
error (error) {
console.error(error)
},
complete () {
}
})
},
stop() {
sources[key]
)
}
} else {
throw Error('We dont know how to handle this with a bridge');
}
}, {});
observer.next(sinks);
const startMessage: SandboxMessage = {
cmd: SandboxMessageCommand.start,
instanceId,
}
worker.postMessage(startMessage);
}
subscription = fromEvent(worker, 'message')
.map((event: MessageEvent) => event.data as SandboxMessage)
.filter(message => message.cmd === SandboxMessageCommand.init && message.instanceId === instanceId)
.take(1)
.subscribe({
next: listener,
error: (e) => console.error(e),
complete: () => null
})
},
stop () {
[key]: connectors[key](
receivePorts[key],
sendPorts[key]
)(sources[key])
}
}
}, {});
observer.next(sinks);
const startMessage: SandboxMessage = {
cmd: SandboxMessageCommand.start,
instanceId,
}
worker.postMessage(startMessage);
}
subscription = fromEvent(worker, 'message')
.map((event: MessageEvent) => event.data as SandboxMessage)
.filter(message => message.cmd === SandboxMessageCommand.init && message.instanceId === instanceId)
.take(1)
.subscribe({
next: listener,
error(error) { console.error(error) },
complete() { }
})
},
stop() {
if (stream$) {
tx.start();
sender = stream$.subscribe({
next(event) {
tx.postMessage(event);
},
error(error) {
console.error(error);
},
complete() {
}
});
} {
rx.start();
receiver = fromEvent(rx, 'message')
.subscribe({
next(event: MessageEvent) {
observer.next(event.data);
},
error(error) {
console.error(error);
},
complete() {
}
});
}
},
stop() {
export function setup (
component: (Sources: Sources) => FantasySinks,
drivers: Drivers,
connectors: WorkerConnectors = {},
run = defaultRun
) {
fromEvent(self, 'message')
.map((event: MessageEvent) => event.data as SandboxMessage)
.filter(message => message.cmd === SandboxMessageCommand.init)
.subscribe({
next: message => {
let dispose: DisposeFunction;
const instanceId = message.instanceId;
const receivePorts = message.ports;
let channels = createChannels(Object.keys(receivePorts));
const transferPorts = portMap(channels, 2);
const sendPorts = portMap(channels, 1);
const initMessage: SandboxMessage = {
cmd: SandboxMessageCommand.init,
ports: transferPorts,
instanceId
};
self.postMessage(initMessage, Object.values(transferPorts));
start(observer) {
rx.start();
tx.start();
listener = fromEvent(rx, 'message')
.map(e => e.data as WorkerDOMMessage)
.subscribe({
next (message) {
if (message.cmd === WorkerDOMMessageCommand.vnode) {
const vnode = message.payload as VNode;
observer.next(vnode);
} else if (message.cmd === WorkerDOMMessageCommand.attach) {
const payload = message.payload as WorkerDOMAttachMessage;
const options = payload.options || {};
attachments[payload.listenerId] = (xs.from(source
.select(payload.selector)
.events(payload.events, options.useCapture)) as FantasyObservable)
.subscribe({
next (event: Event) {
if (options.preventDefault) {
event.preventDefault();
start(observer) {
rx.start();
tx.start();
listener = fromEvent(rx, 'message')
.map(e => e.data as WorkerDOMMessage)
.subscribe({
next(message) {
if (message.cmd === WorkerDOMMessageCommand.vnode) {
const vnode = message.payload as VNode;
observer.next(vnode);
} else if (message.cmd === WorkerDOMMessageCommand.attach) {
const payload = message.payload as WorkerDOMAttachMessage;
const options = payload.options || {};
attachments[payload.listenerId] = (xs.from(source
.select(payload.selector)
.events(payload.events, options.useCapture)) as FantasyObservable)
.subscribe({
next(event: Event) {
if (options.preventDefault) {
event.preventDefault();
next: message => {
let dispose: DisposeFunction;
const instanceId = message.instanceId;
const receivePorts = message.ports;
let channels = createChannels(Object.keys(receivePorts));
const transferPorts = portMap(channels, 2);
const sendPorts = portMap(channels, 1);
const initMessage: SandboxMessage = {
cmd: SandboxMessageCommand.init,
ports: transferPorts,
instanceId
};
self.postMessage(initMessage, Object.values(transferPorts));
const start$ = fromEvent(self, 'message')
.map((event: MessageEvent) => event.data as SandboxMessage)
.filter(message => message.instanceId === instanceId && message.cmd === SandboxMessageCommand.start)
.mapTo(SandboxMessageCommand.start);
const stop$ = fromEvent(self, 'message')
.map((event: MessageEvent) => event.data as SandboxMessage)
.filter(message => message.instanceId === instanceId && message.cmd === SandboxMessageCommand.stop)
.mapTo(SandboxMessageCommand.stop);
start$
.endWhen(stop$)
.subscribe({
next () {