Comments (1)
While looking at a way to simplify the TodoMVC example application, I came up with a slight addition to Hoverboard.compose that'll make this much more powerful.
What if you could pass any number of "translate" functions to Hoverboard.compose after the first argument, and have them translate or map the state automatically?
For example, in TodoMVC, I have a TodoStore for all the todos, and then I created an ActiveStore and CompletedStore which contain only the active/completed todos. Here's how I currently have to achieve this:
// create a simple store definition that allows setting a single list property
var ListStore = {
list: function (state, list) {
return { list: list };
}
};
// create stores to contain the active and completed todos
var ActiveStore = Hoverboard(ListStore);
var CompletedStore = Hoverboard(ListStore);
TodoStore.getState(function (state) {
var all = state.list;
// when the TodoStore changes, set the lists in these two stores with filtered lists
ActiveStore.list(_.filter(all, { completed: false }));
CompletedStore.list(_.filter(all, { completed: true }));
});
Unfortunately, the new Hoverboard.compose does nothing to make this easier. So what if we could just do this instead?
// create stores to contain the active and completed todos
var ActiveStore = Hoverboard.compose(TodoStore, function (state) {
return {
list: _.filter(state.list, { completed: false })
};
});
var CompletedStore = Hoverboard.compose(TodoStore, function (state) {
return {
list: _.filter(state.list, { completed: true })
};
});
This would be incredibly powerful, especially combined with the rest of Hoverboard.compose's functionality. It'd create a reactive approach to Flux, so you could have data flow from any number of sources, and be mapped and translated into the shape you need.
Another great thing, it'll only need a couple extra lines of code added to Hoverboard.compose.
from hover.
Related Issues (20)
- Debugging tool HOT 1
- Support module pattern
- mixins for React HOT 12
- React Native HOT 8
- react context HOT 8
- Unsubscribing inside listener messes up other listeners
- Hoverboard v2 Roadmap HOT 14
- Remove global state
- setState is not a function? HOT 2
- State as another class with finder & copy method on it? HOT 2
- Hoverboard.compose: Resolve functions to undefined by default
- Hoverboard 3 Roadmap HOT 5
- Composing actions
- Typings? HOT 4
- Stores that depend on other stores? HOT 4
- Complex Async Scenarios.. HOT 5
- Only constructor functions should be capitalized HOT 3
- Forgetting to return shouldn't wipe state
- firebase firestore:delete -r --all-collections && babel-node ./internals/import-default-data HOT 2
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 hover.