パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v0.8.2

easy_event_bus

使いやすく、洗練されたイベントバスベースのライブラリです。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
699
いいね数
9
Pub ポイント
145

パッケージをインストール

flutter pub add easy_event_bus

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

Easy EventBus は、Flutter アプリケーション向けの軽量で直感的なイベントバスライブラリであり、イベントを通じてコンポーネント間のシンプルかつ効率的な通信を可能にします。タイトな結合を避けながら、イベントの発行と購読を行うための洗練されたAPIを提供し、状態管理やコンポーネント間メッセージングに最適です。Android、iOS、Web、macOS、Windows、Linuxなどすべての主要プラットフォームをサポートしており、クロスプラットフォームでの一貫性を確保します。最小限のセットアップとクリーンな構文により、複雑なアプリにおけるコードの保守性と拡張性を高めます。

用途

  • リアルタイム通知
  • ウィジェット間の通信
  • UIとビジネスロジックの分離
  • イベント駆動型アーキテクチャ
  • 画面間の状態同期
  • プラグインまたはモジュールの統合

主な機能

  • シンプルな発行/購読パターン
  • クロスプラットフォーム対応
  • 最小限のボイラープレート
  • 型安全なイベント処理
  • 軽量な依存関係
  • 洗練された読みやすい API

適している対象

  • 軽量な状態管理を求める開発者
  • 頻繁なコンポーネント間通信を行うアプリ
  • 分離アーキテクチャを必要とするプロジェクト
  • コードのシンプルさを最優先とするチーム
  • Flutterの初心者がイベント駆動型デザインを探求しています

注意事項

  • 大規模な状態管理には適していない
  • 限定された組み込みエラー処理
  • 組み込みの永続化なし
  • 衝突を避けるために、イベント名に注意が必要です
  • 他のステート管理ソリューションと併用するのが最適です

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

pub package GitHub

EasyEventBus

Discord Server Invite Kakao_Talk

It's an easy-to-use and elegant library based on event bus. It was greatly inspired by EventBus and made much simpler.

About Event Bus

An Event Bus follows the publish/subscribe pattern. It allows listeners to subscribe for events and publishers to fire events. This enables objects to interact without requiring to explicitly define listeners and keeping track of them.

The Event Bus pattern is especially helpful for decoupling MVC (or MVP) applications.

One group of MVC is not a problem.

Model-View-Controller

But as soon as there are multiple groups of MVCs, those groups will have to talk to each other. This creates a tight coupling between the controllers.

Multi Model-View-Controllers

By communication through an Event Bus, the coupling is reduced.

Event Bus

Usage

Step 1: Subscribe to an Event

First, set up a subscription for the desired event. This allows you to listen for and react to the event whenever it is triggered.

EasyEventBus.on('sayHello', (event) {
  print(event); // write your code here.
});
Step 2: Trigger the Event

Next, trigger the event at the appropriate time in your application. This will notify all subscribers of the event.

EasyEventBus.fire('sayHello', 'hello world'); // Triggers the event with a any data.

Note: The event data can be of any type, giving you flexibility in what information you pass to the subscribers.

That's All!

Advance

1. Cancel Subscription

To cancel a subscription, you call the cancel method. This example shows how to cancel all subscriptions for the 'sayHello' event, both anonymous and with identifiers.

// Cancel all subscriptions to the 'sayHello' event.
EasyEventBus.cancel('sayHello');
2. Cancel Specific Subscription

Before canceling a specific subscription, you first need to create a subscription with an identifier (id). Here is how to subscribe to an event with an id and then cancel that specific subscription by calling the cancel method with the same id.

First, subscribe to an event with an id:

// Subscribe to the 'sayHello' event with an identifier.
EasyEventBus.on('sayHello', (event) {
  print('Received: $event');
}, id: 'uniqueId123');

Then, cancel the subscription using the same id:

// Cancel the subscription to the 'sayHello' event using the identifier 'uniqueId123'.
EasyEventBus.cancel('sayHello', id: 'uniqueId123');
3. Cancel All Subscriptions

You can cancel all subscriptions by calling the cancelAll method. This method cancels all subscriptions for all events and closes all event controllers.

// Cancel all subscriptions and close all event controllers.
EasyEventBus.cancelAll();

カテゴリー

ソースリポジトリ

このパッケージを使用しているプロジェクト