Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function signal(dispatch, type, value) {
return R.bind(_signal, null, dispatch, type, value);
}
async function* forkMain(input, dispatch, threads, transducer) {
let cur = 0;
for await (const i of input) {
if (i.type === "ITEM") {
const thread = threads.get(i.key);
thread.source.dispatch(i.value);
} else if (i.type === "NEW") {
const source = createProducer();
const key = i.key || ++cur;
const iter = transducer(
source,
R.bind(forkDispatch, null, dispatch, key)
)[Symbol.asyncIterator]();
const thread = { iter, key, task: iter.next(), source };
threads.set(key, thread);
yield false;
} else if (i.type === "FLUSH" && threads.size) {
const awaiting = new Set();
for (const { source, key } of threads.values()) {
awaiting.add(key);
source.dispatch({ ...i, awaiting });
}
} else {
yield i;
}
}
}
export async function* incrementAsync(input, dispatch) {
yield {
type: "MENU_ITEM",
index: 300,
value: (
<button>
Increment Async
</button>
)
};
yield* input;
}
export function createProducer() {
const producer = R.producer();
return { producer, event: R.bind(event, producer) };
}
export function createProducer() {
const producer = R.producer();
producer.dispatch = R.bind(resend, producer);
return producer;
}
function event(props, propagate) {
return R.bind(eventHandler, this, props, propagate);
}