standalone component store effect #3727
tomalaforge
started this conversation in
Ideas
Replies: 1 comment 2 replies
-
You can do this already by injecting the import { Component, inject, Input } from '@angular/core';
import { ComponentStore } from '@ngrx/component-store';
import { pipe, tap } from 'rxjs';
@Component({
selector: 'hello',
template: `<h1>Hello {{namer}}!</h1>`,
styles: [`h1 { font-family: Lato; }`],
providers: [ComponentStore],
})
export class HelloComponent {
@Input() namer = 'standalone effect';
myEffect = inject(ComponentStore);
private readonly doThing = this.myEffect.effect<boolean | undefined>(
pipe(
tap(() => {
console.log('done');
})
)
);
ngOnInit() {
this.doThing(true);
}
ngOnDestroy() {}
}
|
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I often find myself in a situation where I want to use an effect to create a subscription without subscribing manually. I do it the following way but it's far from optimal.
However, you can only extends once per class and I don't want to create a service for one small effect inside a small component.
I know that RxAngular has a RxEffect for this purpose.
What do you think about adding one inside Component store ? I think this will be a great add.
Something which can look like this.
Beta Was this translation helpful? Give feedback.
All reactions