Giter VIP home page Giter VIP logo

Comments (1)

jesseskinner avatar jesseskinner commented on May 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.