Nearly Perfected Mystique

    unemit
    TypeScript icon, indicating that this package has built-in type declarations

    1.1.1 • Public • Published

    unemit

    Travis Prettier npm License

    Minimal event emitter

    Usage

    const unemit = require("unemit");
    
    const emitter = unemit();
    
    const unsubscribe = emitter.on("type", data => {
      console.log(data);
    });
    
    emitter.emit("type", { foo: "bar" });

    unemit()

    Returns an Emitter object

    Emitter.emit(type, event)

    Emits an event of type type. Will call the handlers with handler(event).

    Emitter.on(type, handler)

    Registers a handler for events of type type. Returns a function that removes the handler.

    const unsubscribe = emitter.on("type", handler);
    
    unsubscribe();

    Unlike other libraries, unevent will prevent registering the same handler twice for the same event type.

    Emitter.off(type, handler)

    Removes a handler from events of type type.

    Emitter.once(type, handler)

    Registers a handler for only the first event of type type. It's equivalent to:

    function handler() {
      emitter.off("type", handler);
    }
    emitter.on("type", handler);

    Credits

    This library was inspired by mitt.

    Install

    npm i unemit

    DownloadsWeekly Downloads

    663

    Version

    1.1.1

    License

    MIT

    Unpacked Size

    4.42 kB

    Total Files

    5

    Last publish

    Collaborators

    • duailibe