Web ページ上の多数の Web コンポーネントのグローバルな状態を管理する必要があります。(たとえば、各 Web コンポーネントには「選択」ボタン/機能があり、一度に 1 つのコンポーネントのみが選択されるようにコンポーネントを追跡します。)
コンポーネントのグローバルな状態を管理するために、各 Web コンポーネントはメイン Web アプリの共通ハンドラーにイベントのストリームを提供します。残念ながら、グローバル状態を管理するために、ハンドラーがどのストリーム/Web コンポーネントから呼び出されたかを知る必要があります。ハンドラーがこの情報を取得するにはどうすればよいですか?
ここに私のサンプルコードがあります:
// _webComponents is a list of references to each component.
// getStream() gets a stream of events from each component.
// connections is a list of streams from all my web components.
_webComponents.forEach((connection)=>connections.add(connection.getStream()));
connections.forEach((Stream<String> connection)=>connection.listen(eventHandler));
void eventHandler(webComponentEvent){
// ?? How do i find out which web component the event came from ??
// ToDo: use event and web component info to manage a global state of web components.
}