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

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현