What is better way to communicate between components angular-dart?
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!
angular dart angular-dart
add a comment |
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!
angular dart angular-dart
add a comment |
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!
angular dart angular-dart
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!
angular dart angular-dart
angular dart angular-dart
asked Nov 16 '18 at 2:53
Ricardo BocchiRicardo Bocchi
151139
151139
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Using a stream is a good idea.
Now make this class a service, provide it at the root injector and inject it where you want to get notified about updates and subscribe there.
There there are more than one subscriber you need a multicast stream.
I already do this, I did not put the complete code. My question was whether this is the best form for this context.
– Ricardo Bocchi
Nov 16 '18 at 12:07
1
There is not really another way, except perhaps for the special cases parent-child and direct siblings where other variants can be used (based on data-binding), but for the general case a shared service with streams is the way to go.
– Günter Zöchbauer
Nov 16 '18 at 13:10
1
Btw. Angular services are singletons by default, you shouldn't add explicit code to make services singletons.
– Günter Zöchbauer
Nov 16 '18 at 13:11
Nice! I'll modify my code. Thank you!
– Ricardo Bocchi
Nov 16 '18 at 20:24
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53330754%2fwhat-is-better-way-to-communicate-between-components-angular-dart%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Using a stream is a good idea.
Now make this class a service, provide it at the root injector and inject it where you want to get notified about updates and subscribe there.
There there are more than one subscriber you need a multicast stream.
I already do this, I did not put the complete code. My question was whether this is the best form for this context.
– Ricardo Bocchi
Nov 16 '18 at 12:07
1
There is not really another way, except perhaps for the special cases parent-child and direct siblings where other variants can be used (based on data-binding), but for the general case a shared service with streams is the way to go.
– Günter Zöchbauer
Nov 16 '18 at 13:10
1
Btw. Angular services are singletons by default, you shouldn't add explicit code to make services singletons.
– Günter Zöchbauer
Nov 16 '18 at 13:11
Nice! I'll modify my code. Thank you!
– Ricardo Bocchi
Nov 16 '18 at 20:24
add a comment |
Using a stream is a good idea.
Now make this class a service, provide it at the root injector and inject it where you want to get notified about updates and subscribe there.
There there are more than one subscriber you need a multicast stream.
I already do this, I did not put the complete code. My question was whether this is the best form for this context.
– Ricardo Bocchi
Nov 16 '18 at 12:07
1
There is not really another way, except perhaps for the special cases parent-child and direct siblings where other variants can be used (based on data-binding), but for the general case a shared service with streams is the way to go.
– Günter Zöchbauer
Nov 16 '18 at 13:10
1
Btw. Angular services are singletons by default, you shouldn't add explicit code to make services singletons.
– Günter Zöchbauer
Nov 16 '18 at 13:11
Nice! I'll modify my code. Thank you!
– Ricardo Bocchi
Nov 16 '18 at 20:24
add a comment |
Using a stream is a good idea.
Now make this class a service, provide it at the root injector and inject it where you want to get notified about updates and subscribe there.
There there are more than one subscriber you need a multicast stream.
Using a stream is a good idea.
Now make this class a service, provide it at the root injector and inject it where you want to get notified about updates and subscribe there.
There there are more than one subscriber you need a multicast stream.
answered Nov 16 '18 at 6:14
Günter ZöchbauerGünter Zöchbauer
334k721009942
334k721009942
I already do this, I did not put the complete code. My question was whether this is the best form for this context.
– Ricardo Bocchi
Nov 16 '18 at 12:07
1
There is not really another way, except perhaps for the special cases parent-child and direct siblings where other variants can be used (based on data-binding), but for the general case a shared service with streams is the way to go.
– Günter Zöchbauer
Nov 16 '18 at 13:10
1
Btw. Angular services are singletons by default, you shouldn't add explicit code to make services singletons.
– Günter Zöchbauer
Nov 16 '18 at 13:11
Nice! I'll modify my code. Thank you!
– Ricardo Bocchi
Nov 16 '18 at 20:24
add a comment |
I already do this, I did not put the complete code. My question was whether this is the best form for this context.
– Ricardo Bocchi
Nov 16 '18 at 12:07
1
There is not really another way, except perhaps for the special cases parent-child and direct siblings where other variants can be used (based on data-binding), but for the general case a shared service with streams is the way to go.
– Günter Zöchbauer
Nov 16 '18 at 13:10
1
Btw. Angular services are singletons by default, you shouldn't add explicit code to make services singletons.
– Günter Zöchbauer
Nov 16 '18 at 13:11
Nice! I'll modify my code. Thank you!
– Ricardo Bocchi
Nov 16 '18 at 20:24
I already do this, I did not put the complete code. My question was whether this is the best form for this context.
– Ricardo Bocchi
Nov 16 '18 at 12:07
I already do this, I did not put the complete code. My question was whether this is the best form for this context.
– Ricardo Bocchi
Nov 16 '18 at 12:07
1
1
There is not really another way, except perhaps for the special cases parent-child and direct siblings where other variants can be used (based on data-binding), but for the general case a shared service with streams is the way to go.
– Günter Zöchbauer
Nov 16 '18 at 13:10
There is not really another way, except perhaps for the special cases parent-child and direct siblings where other variants can be used (based on data-binding), but for the general case a shared service with streams is the way to go.
– Günter Zöchbauer
Nov 16 '18 at 13:10
1
1
Btw. Angular services are singletons by default, you shouldn't add explicit code to make services singletons.
– Günter Zöchbauer
Nov 16 '18 at 13:11
Btw. Angular services are singletons by default, you shouldn't add explicit code to make services singletons.
– Günter Zöchbauer
Nov 16 '18 at 13:11
Nice! I'll modify my code. Thank you!
– Ricardo Bocchi
Nov 16 '18 at 20:24
Nice! I'll modify my code. Thank you!
– Ricardo Bocchi
Nov 16 '18 at 20:24
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53330754%2fwhat-is-better-way-to-communicate-between-components-angular-dart%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown