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













0















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!










share|improve this question

















  • 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















0















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!










share|improve this question

















  • 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













0












0








0








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!










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 21 at 15:26









LiquidLiquid

397




397







  • 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












  • 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







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












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
);



);













draft saved

draft discarded


















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















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript