2020-06-07 21:56:54 -07:00
|
|
|
import RxClass from '../src/rx-class.js'
|
|
|
|
|
|
|
|
class Example extends RxClass {
|
|
|
|
constructor(opts={}){
|
|
|
|
super(opts)
|
|
|
|
this.test = {
|
2020-06-08 14:32:52 -07:00
|
|
|
tomrrow: {bar:'fight', foo:'fighters'},
|
|
|
|
today: {bing:'bing', bong:{who:'first',what:'second'}}
|
2020-06-07 21:56:54 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const example = new Example({
|
|
|
|
_rx_ : {
|
|
|
|
handler: value => {console.log('-----------default subscription handler-------', value)},
|
2020-06-08 14:32:52 -07:00
|
|
|
skip: 1
|
2020-06-07 21:56:54 -07:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-06-08 14:32:52 -07:00
|
|
|
example.foundation = null
|
|
|
|
|
|
|
|
console.log('-----EXAMPLE: TRAVERSE OF EXISTING OBJECT OR WHEN SETTING A PLAIN OBJECT-----------')
|
2020-06-07 21:56:54 -07:00
|
|
|
console.log('instance before doing rx on properties\n')
|
|
|
|
console.log(example)
|
|
|
|
console.log('--------------------------')
|
|
|
|
|
2020-06-08 14:32:52 -07:00
|
|
|
// example.on('changed', (prop) => console.log('emitted----a property changed-----',prop))
|
|
|
|
// example.on('test', (val) => console.log('emitted value of test',val))
|
2020-06-07 21:56:54 -07:00
|
|
|
|
2020-06-08 14:32:52 -07:00
|
|
|
console.log('traversing exitings object \'test\' and making all leaves reactive')
|
|
|
|
console.log(example.test)
|
2020-06-07 21:56:54 -07:00
|
|
|
example.rxAdd('test',{traverse:true})
|
|
|
|
|
2020-06-08 14:32:52 -07:00
|
|
|
console.log('adding new property which is made reactive by default \'test.today.bong.why\'')
|
|
|
|
example.set('test.today.bong.why','do not know')
|
2020-06-07 21:56:54 -07:00
|
|
|
|
2020-06-15 10:08:52 -07:00
|
|
|
console.log('------\'test\', raw object ------ \n', example.$get('test'))
|
2020-06-08 14:32:52 -07:00
|
|
|
console.log('------ \'test\', values object ------\n>', example.get('test'))
|
2020-06-15 10:08:52 -07:00
|
|
|
console.log(example)
|
|
|
|
console.log('now removing reactivty from \'test\'')
|
|
|
|
example.rxRemove('test',{confirm:true})
|
|
|
|
console.log(example.$get('test'))
|
|
|
|
console.log('-------------------------')
|
2020-06-08 14:32:52 -07:00
|
|
|
|
|
|
|
console.log('now add a completely new object to root of \'foundation\' and make it reactive')
|
|
|
|
const obj = {giskard:'daneel', hari: {name:'seldon', planet:'Helcion'}}
|
|
|
|
example.set('foundation',obj)
|
|
|
|
|
2020-06-15 10:08:52 -07:00
|
|
|
console.log('------\'foundation\', raw object ------ \n', example.$get('foundation'))
|
2020-06-08 14:32:52 -07:00
|
|
|
console.log('------ \'foundation\', values object ------\n>', example.get('foundation'))
|
|
|
|
|
|
|
|
console.log('--------instance after doing rx----\n')
|
|
|
|
console.log(example)
|
2020-06-07 21:56:54 -07:00
|
|
|
console.log('--------------------------')
|
2020-06-08 14:32:52 -07:00
|
|
|
|
|
|
|
console.log('now change a reactive property directly like')
|
|
|
|
console.log('example.foundation.giskard = \'daneel a robot\'')
|
|
|
|
example.foundation.giskard = 'daneel a robot'
|
|
|
|
console.log('the new value extracted by the getter is',example.foundation.giskard)
|