I was searching what is the best way to send messages between components in dart-angular applications, and I was kind of confused. I found that in old versions, I would use ScopeAware, as shown in this question: Angular Dart component events, but now this was replaced to Streams.
It seems to me that ScopeAware created a "global" way of managing events between components not directly related, right? Using streams, how can I do create this context?
I have this code, to work with "global" events:
class PostEvent {
final StreamController<ComponentEvent> _onEventStream = new StreamController.broadcast();
Stream<ComponentEvent> onEventStream = null;
static final PostEvent _singleton = new PostEvent._internal();
factory PostEvent() {
return _singleton;
}
PostEvent._internal() {
onEventStream = _onEventStream.stream;
}
onEvent(ComponentEvent event) {
_onEventStream.add(event);
}
}
In my project, I have this structure of components:
Home
-> Products
-> Product Item
-> Header
-> Cart Products Count
When one product is add or remove, "Cart Products Count" should be notified. My code, in this case, is a good idea?
Thanks!