0.7.4 • Published 10 months ago
james-bond v0.7.4
James Bond
Hire James Bond to observe your (object) targets.
Summary
Use james-bond
to observe changes to properties in objects.
Usage
observe(obj)
/unobserve(obj)
Observe particular properties of an object (non-deeply).
import * as bond from 'james-bond'
const janus = {
name: 'Alec Trevelyan',
stats: {
kills: 8,
},
kill(someone) {
console.log('killed ' + someone)
this.stats.kills++
},
}
const callback = (key, value) => {
console.log(key, value)
}
bond.observe(janus, ['name'], callback)
bond.observe(janus.stats, ['kills'], callback)
setTimeout(() => {
janus.name = 'Janus' // logs "name Janus"
janus.kill('someone') // logs "kills 9"
}, 1000)
Later, unobserve when done:
// Unobserve all props for the given callback (in this case, just "kills")
bond.unobserve(janus.stats, callback)
// Alternatively, unobserve specific props for the given callback.
bond.unobserve(janus, ['name'], callback)
Roadmap
- Add deferral options, f.e. to have updates batched into a microtask or animation frame.
0.7.4
10 months ago
0.7.3
2 years ago
0.7.2
2 years ago
0.7.1
2 years ago
0.7.0
2 years ago
0.6.0
2 years ago
0.5.1
2 years ago
0.5.0
3 years ago
0.4.5
4 years ago
0.4.4
5 years ago
0.4.3
5 years ago
0.4.2
7 years ago
0.4.1
7 years ago
0.4.0
7 years ago
0.3.0
7 years ago
0.2.1
7 years ago
0.2.0
7 years ago
0.1.1
7 years ago
0.1.0
7 years ago
0.0.0
11 years ago