This file contains hidden or 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
| import { call } from "effection"; | |
| function* getUser2(id: number) { | |
| if (cachedUser) return cachedUser; | |
| let response = yield* call(fetch(`/users/${id}`)); | |
| return yield* call(response.json()); | |
| } |
This file contains hidden or 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
| import { createSignal, call, first, each, spawn, sleep, type Operation } from "effection"; | |
| import { render } from "$revolution"; | |
| export default function* TimerIsland(): Operation<void> { | |
| let reset = createSignal<void>(); | |
| let start = createSignal<void>(); | |
| let stop = createSignal<void>(); | |
| let elapsed = 0; | |
| let t0 = performance.now(); |
This file contains hidden or 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
| import { describe, it } from "https://deno.land/[email protected]/testing/bdd.ts" | |
| import { launch } from "https://deno.land/x/[email protected]/mod.ts"; | |
| describe("browser", () => { | |
| it("launches, sleeps, and closes", async () => { | |
| let browser = await launch(); | |
| await new Promise((resolve) => setTimeout(resolve, 2000)); | |
| browser.close(); | |
| }); | |
| }); |
This file contains hidden or 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
| import { posixNormalize } from "https://deno.land/[email protected]/path/_normalize.ts"; | |
| import { selectAll } from "npm:[email protected]"; | |
| import type { Element } from "hastx/jsx-runtime"; | |
| /** | |
| * Rebase an HTML document at a different URL. This replaces all `<a href>` and | |
| * `<img src>` attributes that contain an absolute path. Any path that is | |
| * relative or contains a fully qualitfied URL will be left alone. | |
| * |
This file contains hidden or 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
| import { | |
| call, | |
| createSignal, | |
| each, | |
| type Operation, | |
| spawn, | |
| type Stream, | |
| suspend, | |
| } from "effection"; |
This file contains hidden or 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
| import { type Stream, createQueue, spawn } from "effection"; | |
| /*/ | |
| * @example | |
| * let clicks: Stream<MousEvent> = pipe(on(button, 'click'), buffer(100)); | |
| */ | |
| export function buffer<T, TClose>(limit: number): (stream: Stream<T, TClose>) => Stream<T, TClose> { | |
| return function(stream) { | |
| return { |
This file contains hidden or 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
| import { | |
| createContext, | |
| type Queue, | |
| resource, | |
| type Signal, | |
| type Stream, | |
| } from "https://deno.land/x/[email protected]/mod.ts"; | |
| type Predicate = (value: unknown) => boolean; |
This file contains hidden or 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
| import { type Stream, type Operation, action, each, once, resource, spawn, createChannel, createSignal } from "effection"; | |
| export interface WebSocketHandle extends Stream<MessageEvent, CloseEvent> { | |
| send(value: string): Operation<void>; | |
| close(code?: number, reason?: string): Operation<void>; | |
| } | |
| export function useWebSocket(url: string | URL, protocols?: string | string[]) { | |
| return resource<WebSocketHandle>(function*(provide) { | |
| let input = createChannel<string, {code?: number; reason?: string}>(); |
This file contains hidden or 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
| import { action, spawn, sleep, type Operation } from "effection"; | |
| export function* heartbeat(duration: number, op: () => Operation<unknown>): Operation<void> { | |
| while (true) { | |
| // this action captures a return point. | |
| yield* action(function* (restart) { | |
| // wait for the duration and return to the next loop iteration | |
| yield* spawn(function*() { | |
| yield* sleep(duration); |