Conversation
fa3ca9f to
f6101c2
Compare
|
This is pretty useful, I was hoping to be able to use it to replay dispatches and to send them via postMessage (for example, when having stores in a sharedWorker). |
|
@nelix Not sure quite what you mean about dispatch replaying; can you clarify? As for alternative dispatch implementations, what about an API that looked more like this? flux.setDispatchWrapper(function(action, dispatch));where and the and custom implementations (e.g. with web workers) could forego the original implementation completely: (FWIW, these kinds of scenarios will be much better supported by the v2 API, which I swear I'm working on :) |
|
That would do nicely. |
React automatically batches updates when inside a synthetic event handler, but asynchronous updates do not get the same treatment. Consider the following scenario: 1. A button in ComponentA calls an action creator 2. The action creator calls an async API 3. As a result of the async call, the action creator dispatches an action 4. That action sets new state in a store 5. The new store data causes a new child to be mounted inside ComponentA (let's call it ComponentB) 6. ComponentB fires an action immediately, via componentDid/WillMount Unlike re-renders from synchronous action dispatches (which generally happen in the context of a synthetic event), asynchronous dispatches aren't called within the context of React's batching strategy. This means the dispatch loop is still in progress when ComponentB mounts, causing a cascading dispatch exception. `Flux#setBatchingFunction` allows you to pass a batching function to wrap dispatches in; in most (all?) cases, you'll want to pass `React.addons.batchedUpdates` in order to force all dispatches to happen in the context of React's batched updates. Fixes #92
56a65e4 to
7ac2074
Compare
|
Updated the API to |
|
Landed in master as d35b604...b35d28b |
React automatically batches updates when inside a synthetic event handler, but asynchronous updates do not get the same treatment. Consider the following scenario:
Unlike re-renders from synchronous action dispatches (which generally happen in the context of a synthetic event), asynchronous dispatches aren't called within the context of React's batching strategy. This means the dispatch loop is still in progress when ComponentB mounts, causing a cascading dispatch exception.
Flux#setDispatchWrapperallows you to pass a function to wrap dispatches in; in most (all?) cases, you'll want to passReact.addons.batchedUpdates(or some custom function that calls it) in order to force all dispatches to happen in the context of React's batched updates.Fixes #92