mitt

  • Version 3.0.0
  • Published
  • 27 kB
  • No dependencies
  • MIT license

Install

npm i mitt
yarn add mitt
pnpm add mitt

Overview

Tiny 200b functional Event Emitter / pubsub.

Index

Functions

function mitt

mitt: <Events extends Record<EventType, unknown>>(
all?: EventHandlerMap<Events>
) => Emitter<Events>;
  • Mitt: Tiny (~200b) functional event emitter / pubsub. mitt

    Returns

    {Mitt}

Interfaces

interface Emitter

interface Emitter<Events extends Record<EventType, unknown>> {}

    property all

    all: EventHandlerMap<Events>;

      method emit

      emit: {
      <Key extends keyof Events>(type: Key, event: Events[Key]): void;
      <Key extends keyof Events>(
      type: undefined extends Events[Key] ? Key : never
      ): void;
      };

        method off

        off: {
        <Key extends keyof Events>(type: Key, handler?: Handler<Events[Key]>): void;
        (type: '*', handler: WildcardHandler<Events>): void;
        };

          method on

          on: {
          <Key extends keyof Events>(type: Key, handler: Handler<Events[Key]>): void;
          (type: '*', handler: WildcardHandler<Events>): void;
          };

            Type Aliases

            type EventHandlerList

            type EventHandlerList<T = unknown> = Array<Handler<T>>;

              type EventHandlerMap

              type EventHandlerMap<Events extends Record<EventType, unknown>> = Map<
              keyof Events | '*',
              EventHandlerList<Events[keyof Events]> | WildCardEventHandlerList<Events>
              >;

                type EventType

                type EventType = string | symbol;

                  type Handler

                  type Handler<T = unknown> = (event: T) => void;

                    type WildCardEventHandlerList

                    type WildCardEventHandlerList<T = Record<string, unknown>> = Array<
                    WildcardHandler<T>
                    >;

                      type WildcardHandler

                      type WildcardHandler<T = Record<string, unknown>> = (
                      type: keyof T,
                      event: T[keyof T]
                      ) => void;

                        Package Files (1)

                        Dependencies (0)

                        No dependencies.

                        Dev Dependencies (19)

                        Peer Dependencies (0)

                        No peer dependencies.

                        Badge

                        To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                        You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/mitt.

                        • Markdown
                          [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/mitt)
                        • HTML
                          <a href="https://www.jsdocs.io/package/mitt"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>