diff --git a/examples/example.js b/examples/example.js index 70fd6e7..fcb0a2e 100644 --- a/examples/example.js +++ b/examples/example.js @@ -19,7 +19,7 @@ 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('changed', prop => console.log('emitted----a property changed-----',prop)) example.on('test', (val) => console.log('emitted value of test',val)) console.log('making \'test\' reactive with default amend of add 3') @@ -44,6 +44,9 @@ console.log('making a deeper property \'another.foo\' reactive') console.log('changing any default amend function ',example.rxAmendValue(val=> val + ':amended')) example.rxAdd('another.foo') +example.on('foo', (val,path) => { console.log('emitted via just \'foo\' ',val,'path is also emitted:',path)}) +example.on('another.foo', (val,path) => { console.log('emitted via just \'another.foo\',',val,'path is undefined',path)}) + example.another.foo = 7 console.log('direct access of another.foo',example.another.foo) @@ -77,3 +80,8 @@ console.log('getting directy:',example.a) console.log('using $get with passed object:',example.$get(example.a.test,'object.do')) console.log('deleting do prop only', example.$del(example.a,'test.object.do',true)) console.log('it\'s gone see:',example.a) + +example.on('demo',(value) => { + console.log('shoud do simple emit of test>', value) +}) +example.emit('demo','test') diff --git a/package.json b/package.json index da2005b..312e165 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@uci-utils/rx-class", - "version": "0.1.2", + "version": "0.1.3", "description": "class that support reactive properites", "main": "src/rx-class.js", "scripts": { diff --git a/src/rx-class.js b/src/rx-class.js index 5dc43a0..c394db2 100644 --- a/src/rx-class.js +++ b/src/rx-class.js @@ -99,8 +99,9 @@ export default class RxClass extends EventEmitter { rx.value = value value = rx.amendValue(value,path) rx.obs.next(value) - self.emit(opts.event || self._rx_.event,value) + self.emit(opts.event || self._rx_.event,value,path) self.emit(path,value) + self.emit(name,value,path) // any hook function that already bound will use that context self._rx_.hooks.forEach(hook=>hook.call(self,value)) rx.hooks.forEach(hook=>hook.call(self,value)) @@ -174,12 +175,6 @@ export default class RxClass extends EventEmitter { } } return false - // else { - // if (name && name!=='_default') { - // console.log('*********no rx object at that path*******') - // console.log('================================') - // } - // } } // takes several formats for a path to an objects property and return only the . string