Is it bad practice to pass a components scope to a store service - AngularAngular - Use pipes in services and componentsAngular 2 Sibling Component CommunicationAngular2 is this the right way to use Observables?Angular 2 duplicated subscription in componentAngular: Subscribing and Observing in ServicesGet unique/latest value from observable in component class (result of store selector)Angular RxJS - Unsubscribe from mergeMap?Angular 6 http service best practiceWhen Components or Services in Angular 2 get destroyed?Destroy Angular 5 components when move to another menu
Can criminal fraud exist without damages?
Where in the Bible does the greeting ("Dominus Vobiscum") used at Mass come from?
Everything Bob says is false. How does he get people to trust him?
What to do with wrong results in talks?
If you attempt to grapple an opponent that you are hidden from, do they roll at disadvantage?
The plural of 'stomach"
What is the intuitive meaning of having a linear relationship between the logs of two variables?
Can somebody explain Brexit in a few child-proof sentences?
What is the oldest known work of fiction?
Understanding "audieritis" in Psalm 94
is this a spam?
Confused about a passage in Harry Potter y la piedra filosofal
Modify casing of marked letters
The baby cries all morning
Can I use my Chinese passport to enter China after I acquired another citizenship?
Do there exist finite commutative rings with identity that are not Bézout rings?
How do I keep an essay about "feeling flat" from feeling flat?
There is only s̶i̶x̶t̶y one place he can be
voltage of sounds of mp3files
How was Earth single-handedly capable of creating 3 of the 4 gods of chaos?
Efficiently merge handle parallel feature branches in SFDX
What would happen if the UK refused to take part in EU Parliamentary elections?
Is a roofing delivery truck likely to crack my driveway slab?
What would be the benefits of having both a state and local currencies?
Is it bad practice to pass a components scope to a store service - Angular
Angular - Use pipes in services and componentsAngular 2 Sibling Component CommunicationAngular2 is this the right way to use Observables?Angular 2 duplicated subscription in componentAngular: Subscribing and Observing in ServicesGet unique/latest value from observable in component class (result of store selector)Angular RxJS - Unsubscribe from mergeMap?Angular 6 http service best practiceWhen Components or Services in Angular 2 get destroyed?Destroy Angular 5 components when move to another menu
Currently this is how I'm subscribing to relevant parts of my state in components:
this.store.pipe(
select((state: any) => state.data.relevantInfo),
untilDestroyed(this))
.subscribe((relevantInfo: RelevantInfo) =>
this.doSomethingWithInfo(relevantInfo));
untilDestoryed(this)
is an npm package which automatically unsubscribes when the component is destroyed.
Since I subscribe to the same parts of the state in different components, I was thinking about creating a Store Service, which returns the corresponding observable...
selectRelevantInfo(scope)
return this.store.pipe(select((state: State) => state.data.relevantInfo),
untilDestroyed(scope));
...and calling it like this:
this.storeService.selectRelevantInfo(this)
.subscribe((relevantInfo: RelevantInfo) =>
this.doSomethingWithInfo(relevantInfo));
Now my question is, would passing the scope this to the StoreService be considered bad practice? Because it probably is - any idea how I could clean up the subscriptions without following this approach? Thanks!
angular redux ngrx
add a comment |
Currently this is how I'm subscribing to relevant parts of my state in components:
this.store.pipe(
select((state: any) => state.data.relevantInfo),
untilDestroyed(this))
.subscribe((relevantInfo: RelevantInfo) =>
this.doSomethingWithInfo(relevantInfo));
untilDestoryed(this)
is an npm package which automatically unsubscribes when the component is destroyed.
Since I subscribe to the same parts of the state in different components, I was thinking about creating a Store Service, which returns the corresponding observable...
selectRelevantInfo(scope)
return this.store.pipe(select((state: State) => state.data.relevantInfo),
untilDestroyed(scope));
...and calling it like this:
this.storeService.selectRelevantInfo(this)
.subscribe((relevantInfo: RelevantInfo) =>
this.doSomethingWithInfo(relevantInfo));
Now my question is, would passing the scope this to the StoreService be considered bad practice? Because it probably is - any idea how I could clean up the subscriptions without following this approach? Thanks!
angular redux ngrx
1
Why not justthis.storeService.selectRelevantInfo().pipe(untilDestroyed(this)....
instead of doing it in the service. Your services shouldn't be the one handling unsubscribe.
– penleychan
Mar 21 at 15:50
Ah of course, that makes sense. Thanks a lot for your suggestion!
– Liquid
Mar 21 at 15:53
add a comment |
Currently this is how I'm subscribing to relevant parts of my state in components:
this.store.pipe(
select((state: any) => state.data.relevantInfo),
untilDestroyed(this))
.subscribe((relevantInfo: RelevantInfo) =>
this.doSomethingWithInfo(relevantInfo));
untilDestoryed(this)
is an npm package which automatically unsubscribes when the component is destroyed.
Since I subscribe to the same parts of the state in different components, I was thinking about creating a Store Service, which returns the corresponding observable...
selectRelevantInfo(scope)
return this.store.pipe(select((state: State) => state.data.relevantInfo),
untilDestroyed(scope));
...and calling it like this:
this.storeService.selectRelevantInfo(this)
.subscribe((relevantInfo: RelevantInfo) =>
this.doSomethingWithInfo(relevantInfo));
Now my question is, would passing the scope this to the StoreService be considered bad practice? Because it probably is - any idea how I could clean up the subscriptions without following this approach? Thanks!
angular redux ngrx
Currently this is how I'm subscribing to relevant parts of my state in components:
this.store.pipe(
select((state: any) => state.data.relevantInfo),
untilDestroyed(this))
.subscribe((relevantInfo: RelevantInfo) =>
this.doSomethingWithInfo(relevantInfo));
untilDestoryed(this)
is an npm package which automatically unsubscribes when the component is destroyed.
Since I subscribe to the same parts of the state in different components, I was thinking about creating a Store Service, which returns the corresponding observable...
selectRelevantInfo(scope)
return this.store.pipe(select((state: State) => state.data.relevantInfo),
untilDestroyed(scope));
...and calling it like this:
this.storeService.selectRelevantInfo(this)
.subscribe((relevantInfo: RelevantInfo) =>
this.doSomethingWithInfo(relevantInfo));
Now my question is, would passing the scope this to the StoreService be considered bad practice? Because it probably is - any idea how I could clean up the subscriptions without following this approach? Thanks!
angular redux ngrx
angular redux ngrx
asked Mar 21 at 15:26
LiquidLiquid
397
397
1
Why not justthis.storeService.selectRelevantInfo().pipe(untilDestroyed(this)....
instead of doing it in the service. Your services shouldn't be the one handling unsubscribe.
– penleychan
Mar 21 at 15:50
Ah of course, that makes sense. Thanks a lot for your suggestion!
– Liquid
Mar 21 at 15:53
add a comment |
1
Why not justthis.storeService.selectRelevantInfo().pipe(untilDestroyed(this)....
instead of doing it in the service. Your services shouldn't be the one handling unsubscribe.
– penleychan
Mar 21 at 15:50
Ah of course, that makes sense. Thanks a lot for your suggestion!
– Liquid
Mar 21 at 15:53
1
1
Why not just
this.storeService.selectRelevantInfo().pipe(untilDestroyed(this)....
instead of doing it in the service. Your services shouldn't be the one handling unsubscribe.– penleychan
Mar 21 at 15:50
Why not just
this.storeService.selectRelevantInfo().pipe(untilDestroyed(this)....
instead of doing it in the service. Your services shouldn't be the one handling unsubscribe.– penleychan
Mar 21 at 15:50
Ah of course, that makes sense. Thanks a lot for your suggestion!
– Liquid
Mar 21 at 15:53
Ah of course, that makes sense. Thanks a lot for your suggestion!
– Liquid
Mar 21 at 15:53
add a comment |
0
active
oldest
votes
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%2f55283893%2fis-it-bad-practice-to-pass-a-components-scope-to-a-store-service-angular%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
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%2f55283893%2fis-it-bad-practice-to-pass-a-components-scope-to-a-store-service-angular%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
1
Why not just
this.storeService.selectRelevantInfo().pipe(untilDestroyed(this)....
instead of doing it in the service. Your services shouldn't be the one handling unsubscribe.– penleychan
Mar 21 at 15:50
Ah of course, that makes sense. Thanks a lot for your suggestion!
– Liquid
Mar 21 at 15:53