0.1.3 • Published 5 years ago

@linxuekai/event-proxy v0.1.3

Weekly downloads
1
License
ISC
Repository
-
Last release
5 years ago
// 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~

You can also use this like the native node module events, they are the some thing!

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago