Title: Compile Library away to imperative code · Issue #34 · JavaScriptRegenerated/yieldmachine · GitHub
Open Graph Title: Compile Library away to imperative code · Issue #34 · JavaScriptRegenerated/yieldmachine
X Title: Compile Library away to imperative code · Issue #34 · JavaScriptRegenerated/yieldmachine
Description: Before: 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 ...
Open Graph Description: Before: import { start } from "yieldmachine"; function TrafficLights() { function* Red() { yield on("timer", Green); } function* Green() { yield on("timer", Yellow); } function* Yellow() { yield on...
X Description: Before: import { start } from "yieldmachine"; function TrafficLights() { function* Red() { yield on("timer", Green); } function* Green() { yield on("timer", Yellow); }...
Opengraph URL: https://github.com/JavaScriptRegenerated/yieldmachine/issues/34
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Compile Library away to imperative code","articleBody":"Before:\r\n```js\r\nimport { start } from \"yieldmachine\";\r\n\r\nfunction TrafficLights() {\r\n function* Red() {\r\n yield on(\"timer\", Green);\r\n }\r\n function* Green() {\r\n yield on(\"timer\", Yellow);\r\n }\r\n function* Yellow() {\r\n yield on(\"timer\", Red);\r\n }\r\n\r\n return Red;\r\n}\r\n\r\nconst m = start(TrafficLights);\r\nm.current; // { state: \"Red\", count: 0 }\r\nm.next(\"timer\");\r\nm.current; // { state: \"Green\", count: 1 }\r\nm.next(\"timer\");\r\nm.current; // { state: \"Yellow\", count: 2 }\r\n```\r\n\r\nAfter compiles to:\r\n\r\n```js\r\n\r\nfunction* startTrafficLights() {\r\n let count = 0;\r\n let state = \"Red\";\r\n\r\n return {\r\n get current() {\r\n return Object.freeze({ count, state });\r\n }\r\n next(event) {\r\n if (event === \"timer\") {\r\n count++;\r\n if (state === \"Red\") {\r\n state = \"Green\";\r\n } else if (state === \"Green\") {\r\n state = \"Yellow\";\r\n } else if (state === \"Yellow\") {\r\n state = \"Red\";\r\n }\r\n }\r\n return { value: this.current, done: false };\r\n },\r\n };\r\n}\r\n\r\nconst m = startTrafficLights();\r\nm.current; // { state: \"Red\", count: 0 }\r\nm.next(\"timer\");\r\nm.current; // { state: \"Green\", count: 1 }\r\nm.next(\"timer\");\r\nm.current; // { state: \"Yellow\", count: 2 }\r\n```","author":{"url":"https://github.com/RoyalIcing","@type":"Person","name":"RoyalIcing"},"datePublished":"2022-02-22T02:49:48.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/34/yieldmachine/issues/34"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:550b6841-b1dc-1f18-8eff-a0790afa0f7a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8140:14F335:178FABA:1EC94EF:6974414D |
| html-safe-nonce | ff4e7ae0366dc1843a7e50b6c2b53acfbf3722894be43df177a0d28719203654 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MTQwOjE0RjMzNToxNzhGQUJBOjFFQzk0RUY6Njk3NDQxNEQiLCJ2aXNpdG9yX2lkIjoiNjc4MzUzMzcyMDU4NjY5OTA4NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | bb726d8d832b46484fc631285144c2d022fd6b3bf311feba1dc6931f0e83e302 |
| hovercard-subject-tag | issue:1146393877 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/JavaScriptRegenerated/yieldmachine/34/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1068df2cf6bc5f2040ec18fd2e13bac50b75a81e72ccacf2649c1d56da67b662/JavaScriptRegenerated/yieldmachine/issues/34 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1068df2cf6bc5f2040ec18fd2e13bac50b75a81e72ccacf2649c1d56da67b662/JavaScriptRegenerated/yieldmachine/issues/34 |
| og:image:alt | Before: import { start } from "yieldmachine"; function TrafficLights() { function* Red() { yield on("timer", Green); } function* Green() { yield on("timer", Yellow); } function* Yellow() { yield on... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | RoyalIcing |
| hostname | github.com |
| expected-hostname | github.com |
| None | e0b95d743b7672c9ac0e1032d5f117950182dc164a83434a7db86510e8f0b37c |
| turbo-cache-control | no-preview |
| go-import | github.com/JavaScriptRegenerated/yieldmachine git https://github.com/JavaScriptRegenerated/yieldmachine.git |
| octolytics-dimension-user_id | 91813245 |
| octolytics-dimension-user_login | JavaScriptRegenerated |
| octolytics-dimension-repository_id | 327153192 |
| octolytics-dimension-repository_nwo | JavaScriptRegenerated/yieldmachine |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 327153192 |
| octolytics-dimension-repository_network_root_nwo | JavaScriptRegenerated/yieldmachine |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 56fe7e2e8de6e57740bca50402351ea656f7a4bf |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width