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
| type Config = { | |
| logPerformance?: boolean; | |
| timeout?: number; // Timeout in milliseconds | |
| }; | |
| function createTestRunner(initialConfig?: Config) { | |
| let globalConfig: Config = { | |
| logPerformance: false, | |
| timeout: 5000, | |
| ...initialConfig, |
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
| // Available variables: | |
| // - Machine | |
| // - interpret | |
| // - assign | |
| // - send | |
| // - sendParent | |
| // - spawn | |
| // - raise | |
| // - actions |
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
| // The Door - state machine | |
| const fetchMachine = Machine({ | |
| id: 'TheDoor', | |
| initial: 'locked', | |
| context: {}, | |
| states: { | |
| locked:{ | |
| id:'locked', | |
| on: { UNLOCK: 'unlocked' } | |
| }, |
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 wait = ms => new Promise(r => setTimeout(() => r(), ms)) | |
| const fetchResource = async ({ url, fakeDelayMs = 0 }) => { | |
| await wait(fakeDelayMs) | |
| return fetch(url).then(res => res.json()) | |
| } | |
| const constants = { | |
| MAX_QUESTION_SCORE: 3, | |
| MAX_RETRIES: 15, | |
| FAILURE_DELAY: 2000, |
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 wait = ms => new Promise(r => setTimeout(() => r(), ms)); | |
| const fetchPosts = (context, event) => { | |
| const { q: num } = context; | |
| console.log('> fetchPosts',num) | |
| if (num == 5) { | |
| return new Promise((r, reject) => reject(new Error('Oh too bad...'))); | |
| } |
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 wait = ms => new Promise(r => setTimeout(() => r(), ms)) | |
| const fetchResource = async ({ url, fakeDelayMs = 0 }) => { | |
| await wait(fakeDelayMs) | |
| return fetch(url).then(res => res.json()) | |
| } | |
| const constants = { | |
| MAX_QUESTION_SCORE: 3, | |
| MAX_RETRIES: 15, |
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 redditMachine = Machine( | |
| { | |
| id: 'reddit', | |
| initial: 'idle', | |
| context: { | |
| question: 'em', | |
| }, | |
| states: { |
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 lessThan = function(end, value) { | |
| return function(value) { | |
| return value < end; | |
| }; | |
| } | |
| // 25 alphabet character letters | |
| const lessThan26 = lessThan(26); | |
| const lazyMap = function* (iterable, callback) { |
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 isPromise = obj => Boolean(obj) && typeof obj.then === 'function'; | |
| const next = (iter, callbacks, prev = undefined) => { | |
| const { onNext, onCompleted } = callbacks; | |
| const item = iter.next(prev); | |
| const value = item.value; | |
| if (item.done) { | |
| return onCompleted(); |
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
| var stats = new Stats(); | |
| document.body.appendChild(stats.dom); | |
| requestAnimationFrame(function loop() { | |
| stats.update(); | |
| requestAnimationFrame(loop) | |
| }); | |
NewerOlder