vigour-observable
Simple, extendable observables - does not require knowledge of flatmaps, reduce or event streams, inspired by rx-js and modelled as observ-struct.
Adds unqiue change stamps see vigour-stamp for more information
Inherits from vigour-base
####operators and set
var Observable = require('vigour-observable')
var name = new Observable({
val: 'a name',
$transform (val) {
return val.toUpperCase()
}
})
var person = new Observable({ name: 'a name' })
person.name.on(() => {
console.log('hey a name!', person.name.compute())
})
person.name.set(name)
name.set('james')
####on and off
var Observable = require('vigour-observable')
var fruits = new Observable()
fruits.on((data, stamp) => {
console.log('fruits!', data, stamp)
})
fruits.set({ banana: 1, kiwi: 1 })
fruits.banana.once(() => {
console.log('banana!')
})
fruits.banana.set(2)
fruits.set({
on: {
data () {
console.log('any fruit?')
}
}
})
fruits.kiwi.set(null)
fruits.on('purchase', (fruit) => {
console.log('a purchase!', data)
this.set({ purchaseHistory: { [fruit]: 1 } })
}, 'history')
fruits.emit('pruchase', 'kiwi')
fruits.off('purchase', 'history')
fruits.off('purchase')
fruits.set({
on: {
purchase: {
history (fruit) {
this.set({ purchaseHistory: { [fruit]: 1 } })
}
}
}
})