Skip to content

Latest commit

 

History

History
50 lines (31 loc) · 878 Bytes

README.md

File metadata and controls

50 lines (31 loc) · 878 Bytes

@netcodejs/event User Guide

This is the TypeScript framework of the "observer model". It provides fewer but efficient interfaces, such as on, off and so on.

Installation

For npm:

$ npm install @netcodejs/event --save

For Yarn:

$ yarn add @netcodejs/event

Usage

For esmodule:

import { Event } from "@netcodejs/event"

For commonjs:

var Event = require("@netcodejs/event")

Simple Example

const event = new Event();

function logHelloWorld(author: string) {
    console.log("Hello, world. Author: " + author + ".");
}
event.on("hello", logHelloWorld);

event.emit("hello", "LittleMoi"); // It will log "Hello, world. Author: LittleMoi".
event.emit("hello", "netcodejs"); // Similaryly, "Hello, world. Author: netcodejs".
event.emit("hi"); // No throws, no things.