0

I'm facing a situation where the methods in Fluxible Action context seem to hang. I think my trouble stems from the fact that I'm writing in ES5 and I've had to take my best guess at how the ES6 examples on Fluxible's homepage translate (link and link).

Anyway, here's some relevant code (simplified greatly to try and emphasize the parts that I think might be important):

Store.js

var BaseStore = require('fluxible/addons/BaseStore');
var assign = require('object-assign');

var Store = assign({}, BaseStore.prototype, {
    handleAction: function(data) {
       console.log('Action Done');
       this.emitChange();
    }
    ... (other methods) ...
}

Store.storeName = 'Store';
Store.handlers = { 'ACTION_DONE': 'handleAction' };

module.exports = Store;

Actions.js

var Promise = require('promise');
var Store = require('./Store');

var Actions = {
   action1: function(context, payload) {
       return new Promise(function(resolve, reject) {
           console.log('Action 1');
           context.dispatch('ACTION_DONE', {});
           resolve(true);
       });
   },

   action2: function(context, payload) {
       return new Promise(function(resolve, reject) {
           // Try to fetch a value from the store and display it
           var store = context.getStore(Store.constructor);
           console.log(store.getValue());
           context.dispatch('ACTION_DONE', {});
           resolve(true);
       });
   }
}

module.exports = Actions;

And I'm using this whole setup with the following lines

var Promise = require('promise');
var Fluxible = require('fluxible');
var Store = require('./Store');
var Actions = require('./Actions');

var app = new Fluxible();
app.registerStore(Store.constructor);

var context = app.createContext();
var action1 = context.executeAction(Actions.action1, {});
var action2 = context.executeAction(Actions.action2, {});

Promise.all([action1, action2]).then(function(val) { console.log('done'); });

I have found while debugging with print statements that execution gets stuck at context.dispatch('ACTION_DONE', {}); in Actions.action1 and at var store = context.getStore(Store.constructor); in Actions.action2. This makes me wonder at my ES5 translation of the examples - particularly my implementation of Store.js.

Any help would be appreciated. And do let me know if there is more information that I can provide.

4

1 回答 1

0

事实证明,方法createStore可以fluxible/addons解决我的问题 -assign({}, BaseStore.prototype, { ... })createStore({ ... })

我不完全理解我现在所做的与我正在做的有什么区别;因此,请随时做出解释。目前,我的问题已经解决了。

于 2015-11-28T22:52:11.587 回答