GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Compile Library away to imperative code · Issue #34 · JavaScriptRegenerated/yieldmachine Open DescriptionBefore: import { start } from "yieldmachine"; function TrafficLights() { function* Red() { yield on("timer", Green); } function* Green() { yield on("timer", Yellow); } function* Yellow() { yield on("timer", Red); } return Red; } const m = start(TrafficLights); m.current; // { state: "Red", count: 0 } m.next("timer"); m.current; // { state: "Green", count: 1 } m.next("timer"); m.current; // { state: "Yellow", count: 2 } After compiles to: function* startTrafficLights() { let count = 0; let state = "Red"; return { get current() { return Object.freeze({ count, state }); } next(event) { if (event === "timer") { count++; if (state === "Red") { state = "Green"; } else if (state === "Green") { state = "Yellow"; } else if (state === "Yellow") { state = "Red"; } } return { value: this.current, done: false }; }, }; } const m = startTrafficLights(); m.current; // { state: "Red", count: 0 } m.next("timer"); m.current; // { state: "Green", count: 1 } m.next("timer"); m.current; // { state: "Yellow", count: 2 } ActivityMetadataMetadataAssigneesLabelsNo labels TypeProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |