48 lines
1.5 KiB
JavaScript
48 lines
1.5 KiB
JavaScript
import RxClass from '../src/rx-class.js'
|
|
|
|
class Example extends RxClass {
|
|
constructor(opts={}){
|
|
super(opts)
|
|
this.test = {
|
|
yesterday: {bar:'bust', foo:3},
|
|
today: {bing:5, bong:{who:'first',what:'second'}}
|
|
}
|
|
}
|
|
}
|
|
|
|
const example = new Example({
|
|
_rx_ : {
|
|
handler: value => {console.log('-----------default subscription handler-------', value)},
|
|
skip: 0
|
|
}
|
|
})
|
|
|
|
console.log('instance before doing rx on properties\n')
|
|
console.log(example)
|
|
console.log('--------------------------')
|
|
|
|
example.on('changed', (prop) => console.log('emitted----a property changed-----',prop))
|
|
example.on('test', (val) => console.log('emitted value of test',val))
|
|
|
|
console.log('traversing \'test\' and making all leaves reactive')
|
|
example.rxAdd('test',{traverse:true})
|
|
|
|
example.test.today.bong.what = 'third'
|
|
example.setPath('test.today.bong.what','forth')
|
|
example.setPath('test.today.bong.why','do not know')
|
|
|
|
console.log('\'test\', values object >', example.getPath('test'))
|
|
console.log('\'test\', raw object >', example.getPath('test',true))
|
|
console.log('--------------------------')
|
|
console.log('instance after adding rx to leaves\n')
|
|
console.dir(example.test)
|
|
console.dir(example._rx_.props)
|
|
console.log('--------------------------')
|
|
console.log('now remove all rx on \'test.yesterday\'\n')
|
|
example.rxRemove('test.today',{traverse:true})
|
|
console.dir(example.test)
|
|
console.log('rx props')
|
|
console.dir(example._rx_.props)
|
|
console.log('--------------------------')
|
|
console.dir(example)
|