Agent Skills by ALSEL
汎用ソフトウェア開発⭐ リポ 15品質スコア 77/100

fetcher-eventbus

型指定されたイベントバス(Serial、Parallel、Broadcast)とクロスタブ通信に対応します。ユーザーがイベントバス、イベント、ブロードキャスト、クロスタブ、シリアル/パラレル実行、BroadcastChannel、または型指定されたイベント処理について言及した場合に使用してください。

description の原文を見る

Work with typed event buses (Serial, Parallel, Broadcast) and cross-tab communication. Use when users mention event bus, events, broadcasting, cross-tab, serial/parallel execution, BroadcastChannel, or typed event handling.

SKILL.md 本文

fetcher-eventbus Skill

使用時期

@ahoo-wang/fetcher-eventbus パッケージを操作する場合にこのスキルを使用してください。以下の場合にトリガーします:

  • ユーザーがイベントバスイベントブロードキャスト、またはクロスタブ通信について言及する
  • ユーザーがSerialまたはParallelなイベント実行を望んでいる
  • ユーザーがBroadcastChannelまたはStorageMessengerについて質問する
  • ユーザーがTypeScriptサポート付きの型付きイベントハンドリングが必要である

主要概念

イベントバスの実装

このパッケージは3つのイベントバス実装を提供します:

1. SerialTypedEventBus

ハンドラーは優先度順(orderプロパティで決定)に実行されます。各ハンドラーが完了してから次が開始されます。

import { SerialTypedEventBus } from '@ahoo-wang/fetcher-eventbus';

const bus = new SerialTypedEventBus<string>('my-events');

bus.on({
  name: 'logger',
  order: 1,
  handle: event => console.log('Event:', event),
});

bus.on({
  name: 'processor',
  order: 2,
  handle: event => console.log('Processing:', event),
});

await bus.emit('hello'); // Executes in order: logger then processor

2. ParallelTypedEventBus

ハンドラーは順序に関係なく並行して実行されます。ハンドラーが独立している場合に使用します。

import { ParallelTypedEventBus } from '@ahoo-wang/fetcher-eventbus';

const bus = new ParallelTypedEventBus<string>('my-events');

bus.on({
  name: 'handler1',
  order: 1,
  handle: async event => console.log('Handler 1:', event),
});

bus.on({
  name: 'handler2',
  order: 2,
  handle: async event => console.log('Handler 2:', event),
});

await bus.emit('hello'); // Both execute in parallel

3. BroadcastTypedEventBus

デリゲートバスを使用して、イベントを他のブラウザタブにブロードキャストします。ローカルおよびクロスタブで動作します。

import {
  BroadcastTypedEventBus,
  SerialTypedEventBus,
} from '@ahoo-wang/fetcher-eventbus';

const delegate = new SerialTypedEventBus<string>('shared-events');
const bus = new BroadcastTypedEventBus({ delegate });

bus.on({
  name: 'cross-tab-handler',
  order: 1,
  handle: event => console.log('Received from other tab:', event),
});

await bus.emit('broadcast-message'); // Local + cross-tab

クロスタブメッセンジャー

ダイレクトなクロスタブ通信用の2つのメッセンジャー実装:

BroadcastChannelMessenger

効率的なクロスタブメッセージング用にネイティブBroadcastChannel APIを使用します。

import { BroadcastChannelMessenger } from '@ahoo-wang/fetcher-eventbus';

const messenger = new BroadcastChannelMessenger('my-channel');

messenger.onmessage = message => {
  console.log('Received:', message);
};

messenger.postMessage('Hello from another tab!');
messenger.close();

StorageMessenger

BroadcastChannelが利用不可な場合のフォールバックとしてlocalStorageイベントを使用します。TTLとクリーンアップをサポートします。

import { StorageMessenger } from '@ahoo-wang/fetcher-eventbus';

const messenger = new StorageMessenger({
  channelName: 'my-channel',
  ttl: 5000, // Messages expire after 5 seconds
  cleanupInterval: 1000, // Clean expired messages every 1 second
});

messenger.onmessage = message => {
  console.log('Received:', message);
};

messenger.postMessage('Hello from another tab!');
messenger.close();

createCrossTabMessenger

利用可能な最適なメッセンジャーを自動選択します:

import { createCrossTabMessenger } from '@ahoo-wang/fetcher-eventbus';

const messenger = createCrossTabMessenger('my-channel');
if (messenger) {
  messenger.onmessage = msg => console.log(msg);
  messenger.postMessage('Hello!');
}

イベントハンドラー

ハンドラーインターフェース

interface EventHandler<EVENT> {
  name: string; // Unique identifier
  order: number; // Execution priority (lower = earlier)
  handle: (event: EVENT) => void | Promise<void>;
  once?: boolean; // If true, auto-removes after first execution
}

Onceハンドラー

once: trueを指定したハンドラーは最初の実行後に自動的に登録解除されます:

bus.on({
  name: 'one-time-handler',
  order: 1,
  once: true,
  handle: event => console.log('This runs only once:', event),
});

汎用EventBus

遅延ロードされたバスで複数のイベントタイプを管理します:

import { EventBus, SerialTypedEventBus } from '@ahoo-wang/fetcher-eventbus';

const supplier = (type: string) => new SerialTypedEventBus(type);
const bus = new EventBus<{
  'user-login': string;
  'order-update': number;
}>(supplier);

bus.on('user-login', {
  name: 'welcome',
  order: 1,
  handle: username => console.log(`Welcome ${username}!`),
});

await bus.emit('user-login', 'john-doe');

エラーハンドリングパターン

  1. ハンドラー内のtry-catch: 非同期操作をtry-catchで囲む
  2. エラーバスデリゲーション: エラーを専用のエラー処理バスに渡す
  3. ログ記録: 組み込みロガーを使用してエラーの可視化を行う
bus.on({
  name: 'safe-handler',
  order: 1,
  handle: async event => {
    try {
      await riskyOperation(event);
    } catch (error) {
      console.error('Handler failed:', error);
    }
  },
});

APIリファレンス

メソッド説明
on(handler)イベントハンドラーを登録する
off(name)名前でハンドラーを削除する
emit(event)すべてのハンドラーにイベントを発火
destroy()すべてのハンドラーとリソースをクリーンアップする

ブラウザサポート

  • BroadcastTypedEventBus: Chrome 54+、Firefox 38+、Safari 15.4+
  • StorageMessenger: localStorageをサポートするすべてのブラウザ
  • その他の実装: ES2020+ 環境(Node.js、ブラウザ)

ファイルロケーション

  • パッケージ: /Users/ahoo/work/ahoo-git/agent-coder/fetcher/packages/eventbus/
  • テスト: /Users/ahoo/work/ahoo-git/agent-coder/fetcher/packages/eventbus/test/

ライセンス: Apache-2.0(寛容ライセンスのため全文を引用しています) · 原本リポジトリ

詳細情報

作者
Ahoo-Wang
リポジトリ
Ahoo-Wang/fetcher
ライセンス
Apache-2.0
最終更新
2026/5/10

Source: https://github.com/Ahoo-Wang/fetcher / ライセンス: Apache-2.0

関連スキル

汎用ソフトウェア開発⭐ リポ 39,967

doubt-driven-development

重要な判断はすべて、本番環境への展開前に新しい視点から対抗的レビューを実施します。速度より正確性が重要な場合、不慣れなコードを扱う場合、本番環境・セキュリティに関わるロジック・取り消し不可の操作など影響度が高い場合、または後でバグを修正するよりも今検証する方が効率的な場合に活用してください。

by addyosmani
汎用ソフトウェア開発⭐ リポ 1,175

apprun-skills

TypeScriptを使用したAppRunアプリケーションのMVU設計に関する総合的なガイダンスが得られます。コンポーネントパターン、イベントハンドリング、状態管理(非同期ジェネレータを含む)、パラメータと保護機能を備えたルーティング・ナビゲーション、vistestを使用したテストに対応しています。AppRunコンポーネントの設計・レビュー、ルートの配線、状態フローの管理、AppRunテストの作成時に活用してください。

by yysun
OpenAIソフトウェア開発⭐ リポ 797

desloppify

コードベースのヘルスチェックと技術負債の追跡ツールです。コード品質、技術負債、デッドコード、大規模ファイル、ゴッドクラス、重複関数、コードスメル、命名規則の問題、インポートサイクル、結合度の問題についてユーザーが質問した場合に使用してください。また、ヘルススコアの確認、次の改善項目の提案、クリーンアップ計画の作成をリクエストされた際にも対応します。29言語に対応しています。

by Git-on-my-level
汎用ソフトウェア開発⭐ リポ 39,967

debugging-and-error-recovery

テストが失敗したり、ビルドが壊れたり、動作が期待と異なったり、予期しないエラーが発生したりした場合に、体系的な根本原因デバッグをガイドします。推測ではなく、根本原因を見つけて修正するための体系的なアプローチが必要な場合に使用してください。

by addyosmani
汎用ソフトウェア開発⭐ リポ 39,967

test-driven-development

テスト駆動開発により実装を進めます。ロジックの実装、バグの修正、動作の変更など、あらゆる場面で活用できます。コードが正常に動作することを証明する必要がある場合、バグ報告を受けた場合、既存機能を修正する予定がある場合に使用してください。

by addyosmani
汎用ソフトウェア開発⭐ リポ 39,967

incremental-implementation

変更を段階的に実施します。複数のファイルに影響する機能や変更を実装する場合に使用してください。大量のコードを一度に書こうとしている場合や、タスクが一度では完結できないほど大きい場合に活用します。

by addyosmani
本サイトは GitHub 上で公開されているオープンソースの SKILL.md ファイルをクロール・インデックス化したものです。 各スキルの著作権は原作者に帰属します。掲載に問題がある場合は info@alsel.co.jp または /takedown フォームよりご連絡ください。
原作者: Ahoo-Wang · Ahoo-Wang/fetcher · ライセンス: Apache-2.0