Comments (5)
This is a good point. One pattern that I've adopted is to have a store that waits for every store, I then register a listener on that store and do snapshots there.
class SnapshotStore {
constructor() {
this.bindActions(whateverActions)
}
onAction() {
this.waitFor(['Store1', 'Store2', 'Store3', 'Store4'])
}
}
var snapshotStore = alt.createStore(SnapshotStore)
snapshotStore.listen(() => alt.takeSnapshot())
Funny you mention this, I have some code sitting in a local branch that does something like this. Here's the proposed change which would register a listener on the alt instance for those actions called:
alt.addActionListener(whateverActions.action, () => {
alt.takeSnapshot()
})
from alt.
I've seen that branch listen-to-actions
. But that's not a solution, because it uses internally dispatcher.register(...)
and this doesn't guarantee calling order of listeners - such listener is just one more between others.
You solution with SnapshotStore
looks interesting, but bug-prone - I have to remember to include every new store there.
For now, I'm using something like this:
class Flux extends Alt {
constructor() {
super();
this.dispatcher.dispatch = _.wrap(this.dispatcher.dispatch, (dispatch, payload) => {
dispatch.call(this.dispatcher, payload);
this.onAction(payload);
});
this.storage = new Storage('state');
}
onAction(payload) {
var state = this.takeSnapshot();
this.storage.writeRaw(state);
}
}
But this feels somewhat hacky, henΡe my proposal. I guess it could be usefull to have official public API for this.
from alt.
Ah, I see what you're looking for. I also wish I had the same thing, essentially a "done" handler for when all dispatches have been completed.
This needs to be provided by flux's dispatcher.
For now your workaround, although hacky, is fine.
from alt.
A similar discussion: facebookarchive/flux#138 (comment)
from alt.
I went ahead and added a helper function for the SnapshotStore
discussed above. You mentioned you didn't want to keep track of including every store in there so I made sure it's automatically done.
The commit is here: c104fb7
Usage is:
var makeFinalStore = require('alt/utils/makeFinalStore');
var FinalStore = makeFinalStore(yourAltInstance)
FinalStore.listen(function () {
console.log('All dispatches have been completed')
})
from alt.
Related Issues (20)
- Is this still alive? HOT 2
- sequentially perform actions that require source retrieval at same time HOT 2
- Error handler does not get triggered for ajax calls HOT 4
- Wait for store function to complete
- Different tests competing in modifying the store
- Multiple input in controlled forms
- Public Method returns state not store; am I guaranteed the Store is updated when the listener fires? HOT 1
- PropTypes in React 16 Deprecated HOT 2
- dispatchIdentity rudely omit all params when the first one is undefined.
- Upgrade to Webpack 3 HOT 1
- Store not listening to actions HOT 4
- can not call DataSource function during an action
- Typescript does not work
- Using bindListeners vs Store.listen emits changes several seconds slower HOT 1
- docs specify file that does not exists
- How to test async actions
- ss state in compoennts HOT 2
- Trato de hacer la mostrar mis registros en paginas HOT 1
- Documentation needs to be fixed HOT 4
- Documentation needs to be fixed
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from alt.