-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clarify/improve existing behavior in component-store initState method #2991
Comments
I could prepare the fix PR if the expected behavior will be confirmed. |
It would be great to use new instance of queueScheduler per component store. It will solve problem with recursive updates. Also it solves problem when store is created inside queueScheduler executing task and store might be uninitialized after instantiating altough initialState is passed through constructor. |
I'm facing a similar issue, during component initialization I conditionally load some data based on whether there's a parameter in the route. I want to set the loading state in my store, however by the time I make that call, the store is yet to be initialized. The code looks something like this: interface Data {
readonly loading: boolean
}
class MyStore extends ComponentStore<Data> {
constructor() {
super({
loading: false
})
}
loadId(id) {
// Can't set state here, not initialized.
this.setState({
loading: true
})
// Remote call here
return of({})
}
}
@Component({
selector: 'app-my-component',
providers: [MyStore],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class MyComponent {
constructor(
route: ActivatedRoute,
private readonly store: MyStore
) {
const loader$ = route.params.pipe(
map((p) => ({
routeId: getRouteId('foo', p)
})),
switchMap(({ routeId }) => {
if (route !== null) {
return this.store.loadById(routeId);
} else {
return of(false);
}
}),
shareReplay(1)
);
// Other stuff
}
} Would appreciate any advice. |
I am having a similar issue. My component store is initialized in the constructor, yet I get a not-initialized error. I only get this error if I start the app on the view that has the component store (i.e. refresh the browser on that view), not if I navigate there from within the app. Most probably because there is a lot qued on app initialization. |
Any news? |
I have the same issue |
Same issue here, using component store in a modal, requires us to provide the store in root, which raises above error. |
Having the same issue in the
|
I was getting the same issue |
…ext on state update Closes ngrx#2991
Description:
Displaying of
${this.constructor.name} has not been initialized yet. Please make sure it is initialized before updating/getting.
looks incorrect for multiple component-stores and possible for store + component-store integration in some cases.Usually call of some store action in subscriber callback is bad practice, but in some cases it could be chain of calls where subscription from one store triggers initialization of another component-store.
What is the current behavior?
Initialized component-store actions throw the same error:
${this.constructor.name} has not been initialized yet. Please make sure it is initialized before updating/getting.
Expected behavior:
Actions of initialized store should work as expected.
Error should not be displayed.
Minimal reproduction of the problem with instructions:
native issue reproduction
Other information:
For practice usage in angular world:
Angular supports performance improvements like
changeDetectionStrategy: OnPush
. It means user need to handle view synchronisation manually in case if changes comes outside of angular word (any action which does not trigger change detection).For these cases angular provides two options to update view:
marckForCheck
marks all components tree modified to the root entry to validate them on the next change detection calldetectChanges
runs change detection directly for the affected component.Usage of both methods depends on the used libraries and performance criteria.
If we have two components with different store instances we could not make them dependent if parent component trigger
detectChanges
inside the callback. In other words children component with its own store instance cannot be created from the subscription result of the parent component like next:Reason:
Looks like it is regression after this PR #2606
Possible solutions if expected behaviour will be confirmed
to this way
workarounds for angular:
detectChanges
call and it's correct for the application to postpone to call changeDetection. Simple replace its call tomarkForCheck
The text was updated successfully, but these errors were encountered: