https://github.com/serebano/bitbox
bitbox(...)
https://github.com/serebano/bitbox
bitbox components observable state
Last synced: about 1 year ago
JSON representation
bitbox(...)
- Host: GitHub
- URL: https://github.com/serebano/bitbox
- Owner: serebano
- License: apache-2.0
- Created: 2017-02-18T09:32:10.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-08-14T09:19:49.000Z (almost 9 years ago)
- Last Synced: 2025-03-11T01:57:25.681Z (over 1 year ago)
- Topics: bitbox, components, observable, state
- Language: JavaScript
- Homepage:
- Size: 849 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# bitbox
```js
// 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(obj, app.count(inc))
// 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
```