1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { patronum } from "https://esm.town/v/effector/patronum?v=1";
import { effector } from "https://esm.town/v/effector/effector?v=2";
export async function effectorWithPatronum(req: Request) {
const { createEvent, createStore, sample } = await effector();
const { condition } = await patronum();
const initial = createEvent();
const first = createEvent();
const second = createEvent();
const $counter = createStore(0);
const $isEven = $counter.map((count) => count % 2 === 0);
$counter.on(initial, (count) => count + 1);
condition({
source: initial,
if: $isEven,
then: first,
else: second,
});
first.watch(() => console.log("First"));
second.watch(() => console.log("Second"));
initial();
initial();
initial();
initial();
return Response.json({
hello: "world",
req: Object.fromEntries(
Array.from(req.headers.keys()).map((key) => [key, req.headers.get(key)]),
),
}, {
status: 201,
headers: {
"Content-Type": "application/json;chartset=UTF-8",
},
});
}