-
Notifications
You must be signed in to change notification settings - Fork 311
state snapshot #343
Comments
The thing is.. usually when you need a state snapshot, you are doing something "wrong". So what is the use case here? There used to be |
You're scaring me, I'm doing this a lot on effects !!. Usually when my actions refer to an entity in my state the payload is the entity id like : SelectItemAction(payload/* id*/: string) and on my effects I need the item instance so I do : actions$.ofType(SELECT_ITEM)
.map(toPayload)
.withLatestFrom( this.store.select( getItems ) )
.map( ([id, items]) => items[id] ) I think I could also do : actions$.ofType(SELECT_ITEM)
.withLatestFrom( () => this.store.select( getSelectedItem ) ) But it feels weird and It's still accessing the state. |
Doing it in effects the reactive way is perfectly fine. The "problem" would be if you wanted to do something like.. http.post('/foo', state.value.people['3'].name); // accessing the "sync" state value .. since there are better ways to handle this |
What's wrong with accessing the state value ? Because I've replaced
with
in some of my effects and it seems to work good. |
@fxck What are those better ways? Can you show me where I should look for them? |
For me the only time I need a snapshot is in my logging service. If an error occurs I send a Request with the current state and the error message back to the server. It would be convenient to have something shorter as |
I don't buy into the blanket statement that accessing the current state in a non-reactive manner is always bad. I know my code and at some points in my code I know that the store already contains the data that I need to retrieve. I also don't care if the data is subject to (frequent) changes. A snapshot is usually enough. That means I don't need to wait for data to become available and I should not need to subscribe to state changes just to get the latest available state. Please provide some examples of why this is bad, or point me to a commit or issue where the removal of |
Please check this against NgRx v4, and if it’s still an issue, please reopen on https://github.com/ngrx/platform. Thanks! |
Sometimes we need to simply access the current state and not react to it.
To do so, we still have to use observable like :
or in effects :
But it really seems like doing complicated things to achieve a simple task.
Would it be really bad if we could access the state directly ??
I've created an hacky
getStateSnapshot( selector )
in some of my effects to experiment and didn't come into any trouble yet.The text was updated successfully, but these errors were encountered: