Skip to content
Typescript Event Emitter
TypeScript JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci
.vscode
src
test
.editorconfig
.eslintignore
.eslintrc.js
.gitignore
CHANGELOG.md
LICENSE
README.md
jest.config.js
package-lock.json
package.json
renovate.json
tsconfig.json
tsconfig.module.json

README.md

TS-Event

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

Install

npm i @antfu/ts-event

License

MIT © antfu 2019

You can’t perform that action at this time.