I have a view that depends on 3 variables and it should be updated every time the state changes.
I got the value Observable
s by selectors and used them by async
pipe in my template.
The problem is that sometimes the state is changed but the view
is not updated. This happens about every 20 times I refresh the page.
How do I know the state is updated? I subscribed on the store$
and logged the value on any change. So there is sometimes that I see the state changes on console but not in the view!
Is there a way to make sure the view is rendered correctly after all?
Code
In my component:
this.homeFacade.loadOrderTypes();
this.orderTypes$ = this.homeFacade.getOrderTypes();
this.showRegisterButton$ = this.homeFacade.getRegisterButtonVisibility();
The loadOrderTypes
function dispatches an action to load data from web service.
Update:
I extended the async
pipe and tried some logging in that pipe. This is the log when the view is not updated:
@ngrx/store/update-reducers
12:45:31.729 async-test.pipe.ts:10 Subscribed async test pipe!
12:45:31.742 async-test.pipe.ts:10 Subscribed async test pipe!
12:45:32.236 client:52 [WDS] Live Reloading enabled.
12:45:32.273 home.reducer.ts:39 [Home Page] Load order type start
12:45:32.275 home.reducer.ts:39 [Home Page] Load order type success
12:45:32.277 home.reducer.ts:39 [Home Page] Check order type success
And this is the log when view is updated:
@ngrx/store/update-reducers
12:55:15.618 async-test.pipe.ts:10 Subscribed async test pipe!
12:55:15.631 async-test.pipe.ts:10 Subscribed async test pipe!
12:55:16.123 home.reducer.ts:39 [Home Page] Load order type start
12:55:16.126 home.reducer.ts:39 [Home Page] Load order type success
12:55:16.128 home.reducer.ts:39 [Home Page] Check order type success
12:55:16.137 async-test.pipe.ts:10 Subscribed async test pipe!
12:55:16.151 async-test.pipe.ts:10 Subscribed async test pipe!
12:55:16.151 async-test.pipe.ts:10 Subscribed async test pipe!