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

GitHub リポジトリmelodysdreamj/easy_event_bus

easy_event_bus

melodysdreamj/easy_event_bus open-source repository details.

easy_event_bus のプロジェクト画像
スター
2
フォーク
0
最終プッシュ(UTC)
2024/03/23
プロジェクト状態
公開中

元の README

以下は英語原文のスナップショットです。最新版は GitHub をご覧ください。

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();
june lee GitHub avatar
GitHub 作者

june lee ↗

A developer in Songdo who loves cafes and good restaurants.

言語C++CMakeDartHTMLSwiftCKotlinObjective-C

このリポジトリが公開するパッケージ

使用している依存関係

依存関係一覧 3 件

  • flutter{"sdk":"flutter"}
  • flutter_test開発用{"sdk":"flutter"}
  • flutter_lints開発用^3.0.0

プロジェクトに合うリポジトリを選ぶには?

用途で絞り込み、開発状況を比較し、採用前に元のリポジトリで要件を確認しましょう。

  1. 名前・作者・説明で検索し、技術トピックで絞り込みます。
  2. スター、フォーク、最近のプッシュを比較します。スターは関心の目安であり、品質の保証ではありません。
  3. 利用前に GitHub で README、ライセンス、Issues を確認します。

情報源と管理

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗