Since we have a global store that is accessible anywhere, is it safe to use it as needed? Sometime outside of ReSwift we might want to check on the current state.
var myState = store.state.foo
or should all of this done inside actions / action creators?
For adhoc state querying, it's perfectly fine to access the store. You will be able to retrieve the state at any point in time without creating strong references to state. The alternative being subscribing to the state updates and mapping changes into a local variable. Keep it simple first and see where you run into issues.
Querying of state like that is done a fair bit in Middleware too.
I think the only warning I would give is to watch out actual globals (ie, shared instances). I'm guessing though you are doing it the right way, and by 'global store' you are referring to the store only being instantiated once and then being injected around the app.
@eschan Another important gotcha to be aware of is that you should only ever access the Store from the main thread. ReSwift operates under the assumption that all actions are being dispatched on the main thread and that all accesses to the store happen there as well.
I plan on encoding that in future, for now developers need to keep that in mind themselves.
Seems like we've resolved this issue! Closing it out.
Most helpful comment
@eschan Another important gotcha to be aware of is that you should only ever access the
Storefrom the main thread. ReSwift operates under the assumption that all actions are being dispatched on the main thread and that all accesses to the store happen there as well.I plan on encoding that in future, for now developers need to keep that in mind themselves.