0.1.2 • Published 5 years ago

@antfu/ts-event v0.1.2

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

Typescript Event Emitter with the same API of VS Code

Basic Usage

class Counter {
  // define the emitter
  private _onChanged = new EventEmitter<number>()
  public readonly onChanged = this._onChanged.event

  private _value = 0

  get value() {
    return this._value
  }

  set value(v) {
    this._value = v
    this._onChanged.fire(this.value)
  }
}

const counter = new Counter()

counter.onChanged(n => { // n is number here
  console.log(`The new value is ${n}`)
})

counter.value = 5 // Output: The new value is 5

License

MIT © antfu 2019