repl-pad demo
Demonstrates taking some static HTML and decorating with repl-pad 'edit' links.
Click one of these edit links to see repl-pad in action.
Example 1 - Simple
const x = 1; x;
Example 2 - Loops and timeout
Math.random(); const x = Math.random(); for (let i=0;i<10;i++) { i; } const fn = (x) => x * 2; setTimeout(() => { console.log(`result: ${fn(10)}`); }, 5000);
Example 3 - Import
import {Normalise} from 'https://unpkg.com/ixfx/dist/temporal.js'; // Initialise a streaming normaliser const n = Normalise.stream(); // Yields 1, because 5 is the highest seen n(5); // Yields 1, because now 10 is the highest seen n(10); // Yields 0, because it's so far the lowest seen n(5); // Yields 0.5, becaause it's in the middle of the range seen thus far n(7.5); // Yields 1, because now it's the largest seen n(11);
Example 4 - Fault tolerance
let x = 0; const fn = () => x++; fn(); some-error fn(); fn();
Example 5 - Async
import { interval } from "https://unpkg.com/ixfx/dist/flow.js" console.log(`Before`); let loops = 0; const randomGenerator = interval(() => Math.random(), 1000); for await (const r of randomGenerator) { // Prints a new random number every second console.log(r); if (++loops > 10) break; } console.log(`After`);
Example 6 - Alt import
import * as Generators from "https://unpkg.com/ixfx/dist/generators.js" // Yields the array: [0,1,2,3,4] const a = [...Generators.count(5)]; for (let i of Generators.count(5)) { // Loop runs five times, with i being 0, 1, 2, 3 and then 4 console.log(i); }
Example 7 - Loop
import {shuffle} from 'https://unpkg.com/ixfx/dist/arrays.js'; const a = [`apples`, `oranges`, `melons`, `bananas`]; // Yields a randomly ordered version, eg: [`melons`,`apples`,`bananas`,`oranges`]; const b = shuffle(a); const items = [1,2,3,4,5,6,7,8,9,10]; for (const i of shuffle(items)) { console.log(i); }