2016-01-21 26 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構造函數