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
| export function Loader() { | |
| function* Loading() { | |
| yield on("error", Failed); | |
| yield on("timeout", TimedOut); | |
| yield on("abort", Aborted); | |
| yield on("success", Loaded); | |
| } | |
| function* Failed() {} | |
| function* TimedOut() {} | |
| function* Aborted() {} |
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
| export function* TrafficLights() { | |
| function* Green() { | |
| yield on("timer", Yellow); | |
| } | |
| function* Yellow() { | |
| yield on("timer", Red); | |
| } | |
| function* Red() { | |
| yield on("timer", Green); | |
| } |
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
| function* VideoID() { | |
| const [videoID] = yield /^[a-zA-Z0-9_]+$/; | |
| return videoID; | |
| } | |
| function* Long() { | |
| yield "https://www.youtube.com/watch?v="; | |
| const videoID = yield VideoID; | |
| return videoID; | |
| } | |
| function* Embed() { |
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
| const S1Time = Symbol('S1Time'); | |
| function DriverTime() { | |
| function* NoTime() { | |
| yield on('sector1Set', SectorTime, id('Sector1')); | |
| yield on('sector2Set', SectorTime, id('Sector2')); | |
| yield on('sector3Set', SectorTime, id('Sector3')); | |
| } | |
| function* SectorTime() { |
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
| export function* OpenFilter() { | |
| function* Closed() { | |
| yield on("First", First); | |
| yield on("Second", Second); | |
| } | |
| function* First() { | |
| yield on("First", Closed); | |
| yield on("Second", Second); | |
| } | |
| function* Second() { |
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
| // See: https://twitter.com/buildsghost/status/1529258931809202176 | |
| // And: https://twitter.com/lewisl9029/status/1529360924343095296 | |
| let db | |
| function allProps(object) { | |
| Object.fromEntries( | |
| await Promise.all( | |
| Object.entries(object).map(async ([key, promise]) => { | |
| return [key, await promise] |
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
| const Key = primaryKeyText('key'); | |
| const Count = column('count', int(1)); | |
| const CountersTable = table('counters', [Key, Count]); | |
| function* Create() { | |
| yield create(CounterTable); | |
| } | |
| function* QueryCountFor(key) { | |
| return select([Count], [where(Key(key))]); |
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
| export function* ReactComponent() { | |
| function* Initial() { | |
| yield on("render", Rendering); | |
| } | |
| function* Rendering() { | |
| yield on("resourceSuspended", Suspended); | |
| yield on("error", Errored); | |
| yield on("commit", Committed); | |
| } | |
| function* Suspended() { |
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 { start, on } from "https://unpkg.com/[email protected]/dist/yieldmachine.module.js" | |
| function TrafficLightsMachine() { | |
| const { Green, Yellow, Red } = { | |
| *Green() { | |
| yield on("timer", Yellow); | |
| }, | |
| *Yellow() { | |
| yield on("timer", Red); | |
| }, |
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
| // Constants are values with names. | |
| // Functions accept values and return values. | |
| const favoriteNumber = 7 | |
| const favoriteNumber2 = (n: number) => n * 2 | |
| const doubleNumber = (n: number) => n * 2 | |
| const a = doubleNumber(favoriteNumber) | |
| // = 14 |