0.44.0 • Published 4 years ago

boxes v0.44.0

Weekly downloads
8
License
MIT
Repository
github
Last release
4 years ago

Boxes

(Work in progress)

Reactive state containers focused on DOM performance

import { getBox, on } from 'Boxes'

const origin = {
  a: 1
}

const box = getBox(origin)
box // { a: 1 }
box === origin // false

on(box, 'a', (...change) => console.log(change))
box.a = 'hello'
// logs: [{ a: 'hello' }, 'a', 'set', 1, 'hello']

API

  • getBox
  • on
  • off

on(box, prop, handler)

Adds handler to box

const box = getBox({ a: 1 })
const handler = (...change) => console.log(change)
boxes.on(box, 'a', handler)

box.a = 'hello'
// logs: [{ a: 'hello' }, 'a', 'set', 1, 'hello']

It also works with dot notation:

const box = getBox({ o: { a: 1  } })
const handler = (...change) => console.log(change)
boxes.on(box, 'o.a', handler)

box.o.a = 'hello'
['set', 'a', 1, 'hello', { a: 'hello' }]

box.o = { a: 'bye' }
// logs: [{ a: 'bye' }, 'a', 'set', 'hello', 'bye']

off(box, prop, handler)

Removes handler from the box

boxes.off(box, 'propName', action)

Emitter

Boxes will emit the changes made in the observed objects.

Change signatures:

Generic signature: [box, property, changeType, oldValue, newValue]

Object:

  • set:
    • signature: [box, property, 'set', oldValue, newValue]
    • on: literal assignation, Object.assign, ...
  • delete:
    • signature: [box, property, 'delete', oldValue, undefined]
    • on: delete operator

Array:

  • set:
    • signature: [box, property, 'set', oldValue, newValue]
    • on: copyWithin, fill, splice and literal assignation
  • delete:
    • signature: [box, property, 'delete', oldValue, undefined]
    • on: delete operator
  • insert:
    • signature: [box, property, 'insert', undefined, newValue]
    • on: push, splice, unshift
  • remove:
    • signature: [box, property, 'remove', oldValue, undefined]
    • on: pop, shift, splice
  • swap:
    • signature: [box, property, 'swap', oldValue, newValue]
    • on: reverse , sort
  • length:
    • signature: [box, firstIndexChanged || undefined, 'length', oldLength, newLength]
    • on: pop, push, shift, splice, unshift
    • firstIndexChanged will be passed only on shift, splice and unshift because on pop and push no index will change
0.44.0

4 years ago

0.43.0

4 years ago

0.42.0

4 years ago

0.41.0

4 years ago

0.40.0

4 years ago

0.39.0

4 years ago

0.38.0

4 years ago

0.37.0

4 years ago

0.36.0

4 years ago

0.34.0

4 years ago

0.35.0

4 years ago

0.33.0

4 years ago

0.32.0

4 years ago

0.30.1

4 years ago

0.30.0

4 years ago

0.19.6

8 years ago

0.19.5

8 years ago

0.19.4

8 years ago

0.19.2

8 years ago

0.19.1

8 years ago

0.19.0

8 years ago

0.18.0

8 years ago

0.17.0

8 years ago

0.16.5

8 years ago

0.16.4

8 years ago

0.16.3

8 years ago

0.16.2

8 years ago

0.16.1

8 years ago

0.16.0

8 years ago

0.15.0

8 years ago

0.14.0

8 years ago

0.13.1

8 years ago

0.13.0

8 years ago

0.12.3

8 years ago

0.12.2

8 years ago

0.12.1

8 years ago

0.12.0

8 years ago

0.11.2

8 years ago

0.11.1

8 years ago

0.11.0

8 years ago

0.10.0

8 years ago

0.9.4

8 years ago

0.9.2

8 years ago

0.9.1

8 years ago

0.9.0

8 years ago

0.8.2

8 years ago

0.8.1

8 years ago

0.8.0

8 years ago

0.7.1

8 years ago

0.7.0

8 years ago

0.6.1

8 years ago

0.6.0

8 years ago

0.5.3

8 years ago

0.5.2

8 years ago

0.5.1

8 years ago

0.5.0

8 years ago

0.4.1

8 years ago

0.4.0

8 years ago

0.3.1

8 years ago

0.3.0

8 years ago

0.2.0

8 years ago

0.1.0

8 years ago

0.0.10

10 years ago

0.0.9

10 years ago

0.0.8

10 years ago

0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago