bitbox

1.2.32 • Public • Published

bitbox

// create observable app box
const app = bitbox(observable)

// some helpers
const inc = count => count + 1 // increment operator
const set = (box, value) => obj => bitbox.set(obj, box, value) // setter factory

// target object
const obj = {
	name: 'bitbox',
	count: 0
}

// mapping
const map = bitbox({
	count: app.count,
	name: app.name(name => name.toUpperCase())
})

// connect with target
const props = map(obj)

// observe changes to mapped props
observe(() => console.log(`${props.name} - count(${props.count})`))

// set / classic
app(obj).count++
// use operator
app.count(inc, obj)
// action factory, if no target argument
app.count(inc) // -> (obj)

// using handler / set(target, box/path, value)
bitbox.set(obj, app.count, 10)
bitbox.set(obj, app.count, app.count(inc))

// array path
bitbox.set(obj, ['app', 'count'], ['app', 'count', inc])

// factory
set(app.name, `Demo App`) // -> (obj)

// conditional
set(app.name, app.count(n => n > 10 ? `Foo` : `Bar`))

// select...
app(JSON.stringify, console.log, obj)
yarn start

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.2.322latest

Version History

VersionDownloads (Last 7 Days)Published
1.2.322
1.2.310
1.2.30
1.2.280
1.2.270
1.2.260
1.2.250
1.2.240
1.2.230
1.2.220
1.2.210
1.2.201
1.2.190
1.2.170
1.0.520
1.0.510
1.0.500
1.0.490
1.0.480
1.0.470
1.0.460
1.0.450
1.0.440
1.0.430
1.0.420
1.0.410
1.0.400
1.0.390
1.0.350
1.0.340
1.0.330
1.0.320
1.0.310
1.0.300
1.0.290
1.0.280
1.0.270
1.0.250
1.0.240
1.0.230
1.0.220
1.0.210
1.0.200
1.0.190
1.0.180
1.0.170
1.0.160
1.0.150
1.0.141
1.0.130
1.0.120
1.0.80
1.0.70
1.0.60
1.0.50
1.0.40
1.0.30
1.0.20
1.0.10

Package Sidebar

Install

npm i bitbox

Weekly Downloads

4

Version

1.2.32

License

Apache2

Last publish

Collaborators

  • sertod