eventemitter3 vs mitt vs nanoevents vs tiny-emitter
JavaScript イベントエミッターライブラリ
eventemitter3mittnanoeventstiny-emitter

JavaScript イベントエミッターライブラリ

イベントエミッターライブラリは、オブジェクト間の通信を効率的に管理するためのツールです。これらのライブラリは、イベントの発行とリスニングを簡素化し、アプリケーションの構造をよりモジュール化するのに役立ちます。特に、非同期処理やユーザーインタラクションが多いアプリケーションにおいて、イベント駆動型のアプローチは非常に有効です。

npmのダウンロードトレンド

3 年

GitHub Starsランキング

統計詳細

パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
eventemitter303,53274.4 kB215ヶ月前MIT
mitt011,87326.4 kB263年前MIT
nanoevents01,6305.43 kB02年前MIT
tiny-emitter0971-97年前MIT

機能比較: eventemitter3 vs mitt vs nanoevents vs tiny-emitter

パフォーマンス

  • eventemitter3:

    eventemitter3は、非常に高いパフォーマンスを誇ります。特に、リスナーの管理が効率的で、大量のイベントを処理する際にもスムーズに動作します。

  • mitt:

    mittは非常に軽量で、パフォーマンスに優れています。シンプルな設計により、オーバーヘッドが少なく、迅速にイベントを発行できます。

  • nanoevents:

    nanoeventsは、最小限のオーバーヘッドで高いパフォーマンスを提供します。特に、イベントの発行とリスニングが迅速で、パフォーマンスを重視するプロジェクトに適しています。

  • tiny-emitter:

    tiny-emitterは、非常に軽量で、シンプルなイベントエミッターです。オーバーヘッドが少なく、パフォーマンスが求められる小規模なプロジェクトに最適です。

APIのシンプルさ

  • eventemitter3:

    eventemitter3は、豊富な機能を提供しつつも、直感的なAPIを持っています。リスナーの追加や削除が簡単で、使いやすさが考慮されています。

  • mitt:

    mittは、非常にシンプルなAPIを持ち、イベントの発行とリスニングが簡単です。初心者でもすぐに理解できる設計です。

  • nanoevents:

    nanoeventsは、シンプルでクリーンなAPIを提供し、イベント管理を簡素化します。特に、少ないコードでイベントを管理できる点が魅力です。

  • tiny-emitter:

    tiny-emitterは、非常にシンプルなAPIを持ち、すぐに使い始めることができます。イベントの発行とリスニングが直感的に行えます。

機能の拡張性

  • eventemitter3:

    eventemitter3は、カスタムイベントや複雑なイベント管理が可能で、拡張性に優れています。大規模なアプリケーションでも柔軟に対応できます。

  • mitt:

    mittは、シンプルな設計のため、拡張性は制限されますが、基本的なイベント管理には十分です。

  • nanoevents:

    nanoeventsは、拡張性が高く、必要に応じてカスタマイズが可能です。シンプルな設計ながら、柔軟性を持っています。

  • tiny-emitter:

    tiny-emitterは、基本的なイベント管理に特化しており、拡張性は限られていますが、シンプルな用途には適しています。

学習曲線

  • eventemitter3:

    eventemitter3は、機能が豊富であるため、初めて使用する際には多少の学習が必要ですが、ドキュメントが充実しているため、習得は容易です。

  • mitt:

    mittは、非常にシンプルなAPIのため、学習曲線はほとんどありません。すぐに使い始めることができます。

  • nanoevents:

    nanoeventsは、シンプルな設計で、学習曲線は緩やかです。基本的な使い方を理解するのは容易です。

  • tiny-emitter:

    tiny-emitterは、非常にシンプルなため、学習曲線はほぼなく、すぐに使いこなせるでしょう。

ユースケース

  • eventemitter3:

    eventemitter3は、複雑なアプリケーションや大規模なプロジェクトに最適です。多くのイベントを管理する必要がある場合に特に効果的です。

  • mitt:

    mittは、小規模なプロジェクトや簡単なイベント管理に適しています。シンプルなユースケースに最適です。

  • nanoevents:

    nanoeventsは、パフォーマンスが求められるアプリケーションに適しており、特にリアルタイムのイベント処理に向いています。

  • tiny-emitter:

    tiny-emitterは、軽量なプロジェクトやシンプルなイベント管理に最適です。すぐに導入できる点が魅力です。

選び方: eventemitter3 vs mitt vs nanoevents vs tiny-emitter

  • eventemitter3:

    高パフォーマンスで多機能なイベントエミッターが必要な場合は、eventemitter3を選択してください。特に、イベントの発行とリスニングの機能が豊富で、TypeScriptのサポートも充実しています。

  • mitt:

    シンプルで軽量なイベントエミッターを求める場合は、mittが最適です。APIが非常に簡潔で、特に小規模なプロジェクトや簡単なイベント管理に適しています。

  • nanoevents:

    最小限のオーバーヘッドで高いパフォーマンスを提供するnanoeventsを選ぶと良いでしょう。特に、パフォーマンスが重要な場合や、シンプルなイベント管理が必要な場合に適しています。

  • tiny-emitter:

    小さくて使いやすいイベントエミッターを探している場合は、tiny-emitterが適しています。シンプルなAPIで、すぐに使い始めることができ、軽量なプロジェクトに最適です。

eventemitter3 のREADME

EventEmitter3

Version npmCICoverage Status

EventEmitter3 is a high performance EventEmitter. It has been micro-optimized for various of code paths making this, one of, if not the fastest EventEmitter available for Node.js and browsers. The module is API compatible with the EventEmitter that ships by default with Node.js but there are some slight differences:

  • Domain support has been removed.
  • We do not throw an error when you emit an error event and nobody is listening.
  • The newListener and removeListener events have been removed as they are useful only in some uncommon use-cases.
  • The setMaxListeners, getMaxListeners, prependListener and prependOnceListener methods are not available.
  • Support for custom context for events so there is no need to use fn.bind.
  • The removeListener method removes all matching listeners, not only the first.

It's a drop in replacement for existing EventEmitters, but just faster. Free performance, who wouldn't want that? The EventEmitter is written in EcmaScript 3 so it will work in the oldest browsers and node versions that you need to support.

Installation

$ npm install --save eventemitter3

CDN

Recommended CDN:

https://unpkg.com/eventemitter3@latest/dist/eventemitter3.umd.min.js

Usage

After installation the only thing you need to do is require the module:

var EventEmitter = require('eventemitter3');

And you're ready to create your own EventEmitter instances. For the API documentation, please follow the official Node.js documentation:

http://nodejs.org/api/events.html

Contextual emits

We've upgraded the API of the EventEmitter.on, EventEmitter.once and EventEmitter.removeListener to accept an extra argument which is the context or this value that should be set for the emitted events. This means you no longer have the overhead of an event that required fn.bind in order to get a custom this value.

var EE = new EventEmitter()
  , context = { foo: 'bar' };

function emitted() {
  console.log(this === context); // true
}

EE.once('event-name', emitted, context);
EE.on('another-event', emitted, context);
EE.removeListener('another-event', emitted, context);

Tests and benchmarks

To run tests run npm test. To run the benchmarks run npm run benchmark.

Tests and benchmarks are not included in the npm package. If you want to play with them you have to clone the GitHub repository. Note that you will have to run an additional npm i in the benchmarks folder before npm run benchmark.

License

MIT