goatslacker / alt

Isomorphic flux implementation
http://alt.js.org/
3.45k stars 323 forks source link

Extend the createStore function to accept a dataSource property #612

Closed dwalker11 closed 8 years ago

dwalker11 commented 8 years ago

When creating a store using an object literal:

var FoodStore = alt.createStore({
  displayName: 'FoodStore',

  bindListeners: {
    addItem: foodActions.addItem
  },

  state: {
    foods: []
  },

  publicMethods: {
    hasFood: function () {
      return !!this.getState().foods.length;
    }
  },

  addItem: function (item) {
    var foods = this.state.foods;
    foods.push(item);
    this.setState({
      foods: foods
    });
  }
});

there is no way to register asynchronous functions as you would when using the class syntax.

class SearchStore {
  constructor() {
    this.state = { value: '' };

    this.registerAsync(SearchSource);
  }
}

alt.createStore(SearchStore, 'SearchStore');

Other than using ES6 class syntax or ES5 constructor/prototype syntax, can we specify a property to handle the registration of an Asynchronous dataSource object?