简体   繁体   English

可变上下文方法挂起

[英]Fluxible Context methods hang

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 ). 我认为我的麻烦源于我正在用ES5编写的事实,并且我不得不对Fluxible主页上的ES6示例如何翻译( 链接链接 )做出最好的猜测。

Anyway, here's some relevant code (simplified greatly to try and emphasize the parts that I think might be important): 无论如何,这是一些相关的代码(经过简化,以强调我认为可能很重要的部分):

Store.js 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 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', {}); 我发现在调试打印语句时,执行被卡在context.dispatch('ACTION_DONE', {}); in Actions.action1 and at var store = context.getStore(Store.constructor); Actions.action1var store = context.getStore(Store.constructor); in Actions.action2 . Actions.action2 This makes me wonder at my ES5 translation of the examples - particularly my implementation of Store.js. 这使我对示例的ES5转换(尤其是Store.js的实现)感到疑惑。

Any help would be appreciated. 任何帮助,将不胜感激。 And do let me know if there is more information that I can provide. 并且让我知道是否还有更多我可以提供的信息。

Turns out that the method createStore in fluxible/addons could solve my problem - change the assign({}, BaseStore.prototype, { ... }) to createStore({ ... }) 事实证明, fluxible/addons createStore方法可以解决我的问题-将assign({}, BaseStore.prototype, { ... })更改为createStore({ ... })

I don't fully understand what the difference between what I'm doing now vs. what I was doing is; 我不完全了解我现在正在做的事情与我正在做的事情之间的区别。 so feel free to respond with explanations. 因此请随时做出解释。 For now, my problem is solved. 目前,我的问题已解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM