Comments (3)
If I understand correctly, you want to clear the stores whenever a new query is submitted?
Sounds like it could be a good use case for the async action handling API we discussed in #14
class MyStore extends Store {
constructor(flux) {
super();
let actions = flux.getActions('myActions');
this.registerAsync(actions.search, this.handleSearchBegin, this.handleSearchSuccess, this.handleSearchFailure);
}
handleSearchBegin() {
// Clear results
this.setState({
results: Immutable.List()
});
}
handleSearchSuccess(results) {
this.setState({ results });
}
handleSearchFailure(error) {
// handle error somehow
}
}
(Note that this feature isn't implemented yet... I'll start working on it sometime today)
Also, you should never set store state using assignment (this.state.data = ...
). Always use setState()
, as in React. This ensures that the change event is fired properly.
from flummox.
Yes it's exactly what I meant.
I'd like to find a way to restore the store state while querying for new results.
Your solution looks good, otherwise the only solution would be to fire an action to clean the store, before fetching new data.
Honestly I don't think we have other solution without polluting the one way data flow.
from flummox.
Not sure if this applies in your particular scenario, but I've started using this pattern (from the flummox demo) in my handler views:
statics: {
async routerWillRun(state, flux) {
let itemActionIds = flux.getActions('item');
return itemActions.getItems();
}
}
And the main snippet:
Router.run(routes, function (Handler, state) {
async function run() {
await performRouteHandlerStaticMethod(state.routes, 'routerWillRun', state, flux);
React.withContext(
{ flux },
() => React.render(<Handler />, document.getElementById('app'))
);
}
run().catch(error => {
throw error;
});
});
And the performRouteHandlerStaticMethod
function:
async function performRouteHandlerStaticMethod(routes, methodName, ...args) {
return Promise.all(routes
.map(route => route.handler[methodName])
.filter(method => typeof method === 'function')
.map(method => method(...args))
);
}
Coming from Angular, this is essentially the same as resolving some data before instantiating the next controller. In some cases I use this to make sure the new data has arrived before rendering the next route's view. In other cases, when I don't want the delay or I'm not actually changing routes, I have had to implement an additional action to explicitly empty certain objects in my state.
I'm pretty new to Flux in general so I may be telling you what you already know.
from flummox.
Related Issues (20)
- how to get a child component input value HOT 1
- Missing getActionsAsObject from Actions HOT 5
- Incorrect params passed to async begin handler HOT 1
- More topic guides needed in doc HOT 1
- Context differs problem
- Do not pass flux prop to components wrapped with `connect` HOT 6
- Use Redux HOT 6
- Explanation in README as to why a switch to Redux should be made HOT 5
- Import flummox/component fails with 4.0.0-rc1 HOT 1
- unable to make flummox work with react-router 1.0.0-beta3 HOT 2
- Actions.js grabs all console logs HOT 4
- Wrong link in why-flux-component-is-better-than-flux-mixin.md
- Considering the numbers HOT 1
- Support for React 0.14 HOT 17
- How to only use custom stateGetter for subset of subscribed stores HOT 1
- Maintain module? HOT 4
- FluxComponent does not work on IE10 HOT 24
- Flummox 3.6 is incompatible with IE8 HOT 3
- TestUtils removed from NPM HOT 2
- Deprecation warning with React 15.5 HOT 1
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 flummox.