2016-01-21 43 views
1

我试图在我的React应用程序中实现Alt。 目前我正在检查它,并试着按照教程做一些事情。现在我遇到了商店无法识别操作的问题。Alt + React - 以下alt教程无效的操作参考

这是操作类:

import alt from '../libs/alt'; 
import WishSource from '../sources/WishSource'; 

class WishActions { 
    fetchWishes() { 
     this.dispatch(); 
     WishSource.fetch() 
     .then((wishes) => { 
      this.actions.fetchWishesSuccess(wishes); 
     }) 
     .catch((err) => { 
      this.actions.fetchWishesFailed(err); 
     }); 
    } 
    fetchWishesSuccess(wishes) { 
    this.dispatch(wishes); 
    } 
    fetchWishesFailed(err) { 
    this.dispatch(err); 
    } 
} 
export default alt.generateActions(WishActions); 

我尝试如下绑定在我的商店这些操作:

import alt from '../libs/alt'; 
import WishActions from '../actions/WishActions'; 

class WishStore { 
    constructor() { 
    this.wishes = []; 
    this.errorMessage = null; 

    this.bindListeners({ 
     handleFetchWishes: WishActions.FETCH_WISHES, 
     handleFetchWishesSuccess: WishActions.FETCH_WISHES_SUCCESS, 
     handleFetchWishesFailed: WishActions.FETCH_WISHES_FAILED 
    }); 
    } 
    handleFetchWishesSuccess(wishes) { 
    this.wishes = wishes; 
    this.errorMessage = null; 
    } 
    handleFetchWishes() { 
    this.wishes = []; 
    } 
    handleFetchWishesFailed(err) { 
    this.errorMessage = err; 
    } 
} 

export default alt.createStore(WishStore, 'WishStore'); 

我一直给我的错误

“无效'

问题出在bindListeners函数的某个地方。

如果我尝试bindActions它说:

'_WishActions2.default.fetchWishes不是一个函数'

,这是在视图中。这里我打电话WishActions.fetchWishes()componentDidMount()

我无法理解这里发生了什么问题。 如果我看教程和其他例子,这应该工作。

有人可以帮助我在这里,也许解释什么是错的?

回答

3

我发现了什么地方出了问题,并会在这里留下帖子,以防其他人遇到同样的事情。

问题是我使用了generateActions而不是createActions。 您可以使用createActions作为类,使用generateActions作为简单函数。 ('create')将生成一个函数create =(x)=> {return x;}; }并发送它。 你仍然可以在你的课堂上使用this.generateActions构造函数