@linxuekai/event-proxy
v0.1.3
Published
Make an ordinary object have events functionality.
Downloads
1
Readme
// ES
import EventEmitter from '@linxuekai/event-proxy'
let state = {someKey: 'someValue'}
let stateProxy = EventEmitter.init(state)
// proxy properties
console.log(stateProxy.someKey)
// 'someValue'
// listen events
stateProxy.on('foo', data => {
console.log(data)
})
stateProxy.emit('foo', 'bar')
// bar
// auto listening properties change
stateProxy.on('update_someKey', newVal => {
console.log('listen update: state.someKey is updated to ' + newVal)
})
stateProxy.someKey = 'haha~'
// listen update: state.someKey is updated to haha~
console.log(state.someKey)
// haha~