xcell
TypeScript icon, indicating that this package has built-in type declarations

0.0.10 • Public • Published

xcell

Tiny library for building reactive spreadsheet-like calculations in JavaScript.

Installation

npm install xcell

Usage (node)

const assert = require('assert')
const xcell = require('xcell')
 
const $a = xcell(1)
const $b = xcell(2)
const $c = xcell([$a, $b], (a, b) => a + b)
 
$a.value = 100
assert.equals($c.value, 102) // 100 + 2
 
$b.value = 200
assert.equals($c.value, 300) // 100 + 200

A Cell is an EventEmitter:

$c.on('change', ({ value }) => console.log(value))

Usage (browser)

<script src="https://unpkg.com/xcell"></script>
<input id="A"> + <input id="B"> = <input id="C" readonly>
<script>
  const $a = xcell(1)
  const $b = xcell(2)
  const $c = xcell([$a, $b], (a, b) => a + b)
 
  A.value = $a.value
  B.value = $b.value
  C.value = $c.value
 
  A.addEventListener('input', e => $a.value = +e.target.value)
  B.addEventListener('input', e => $b.value = +e.target.value)
 
  $c.on('change', ({ value }) => C.value = value)
</script> 

License

MIT

Package Sidebar

Install

npm i xcell

Weekly Downloads

3

Version

0.0.10

License

MIT

Unpacked Size

26.7 kB

Total Files

16

Last publish

Collaborators

  • tomazy