-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathadder.js
27 lines (18 loc) · 804 Bytes
/
adder.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// same example as https://github.com/cujojs/most#simple-example
import { fromEvent, combine } from "../lib/index.js";
const xInput = document.querySelector('input.x');
const yInput = document.querySelector('input.y');
const resultNode = document.querySelector('.result');
const add = (x, y) => x + y;
const toNumber = e => Number(e.target.value);
const renderResult = result => {
resultNode.textContent = result
};
// x represents the current value of xInput
const x = fromEvent('input', xInput).map(toNumber);
// y represents the current value of yInput
const y = fromEvent('input', yInput).map(toNumber);
// result is the live current value of adding x and y
const result = combine([x, y], add);
// Observe the result value by rendering it to the resultNode
result.subscribe(renderResult);