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/numbers.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 { repeat } from "https://unpkg.com/ixfx/dist/flow.js"
let loops = 0;
const randomGenerator = repeat(() => Math.random(), 1000);
for await (const r of randomGenerator) {
// A new random number every second
r;
if (++loops > 10) break;
}
Example 6 - Alt import
import { Numbers } from "https://unpkg.com/ixfx"
// Yields the array: [0,1,2,3,4]
const a = [...Numbers.count(5)];
for (let i of Numbers.count(5)) {
// Loop runs five times, with i being 0, 1, 2, 3 and then 4
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 = shuffle([1,2,3,4,5,6,7,8,9,10]);