0.0.1 • Published 3 years ago

@livestd/simple-event-model v0.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

NPM

Simple event model

Installation

npm install --save @livestd/simple-event-model

Simple Event Model

Usage

import EmitterModel from '@livestd/simple-event-model';

enum Events {
  select = 'select'
}
type EventsType = keyof typeof Events;

class Model extends EmitterModel<EventsType> {
  constructor() {
    super();
  }
  listenSelect = (id: string, callback: (value: string) => void) => {
    this.listen({ id: id, event: Events.select, callback: callback });
  };
  emitSelect = (value: string) => {
    this.emit({ event: CategoryEvents.select, data: value });
  };
}

const model = new Model();

model.listenEvent("1", (v) => console.log(v));
model.emitSelect("test")
2.0.0-alpha.0

3 years ago

0.0.1

4 years ago