2016-09-19 22 views
0

我剛剛使用流量並開始使用alt.js implmentation。我想知道我什麼時候會在我的動作中使用dispatch。例如,拿這個代碼。什麼時候使用alt.js流量

//ImageActions.js 

class ImageActions { 
    getImages(id) { 
    return Api.get(`topics/${id}`).then(response => { 
     let images = response.data.filter(image => { 
     return !image.is_album; 
     }); 
     this.updateImages(images); 
    }); 
    } 
    updateImages(images) { 
    return images; 
    } 
} 
--------------------------------------------------- 

//ImageStore.js 
class ImageStore { 
    constructor() { 
    this.images = []; 
    this.image = {}; 
    this.bindListeners({ 
     handleUpdateImages: ImageActions.UPDATE_IMAGES 
    }); 
    } 
    handleUpdateImages(images) { 
    this.images = images; 
    } 
} 

目前這個工作沒有使用調度()函數,在這裏他們的教程http://alt.js.org/guide/async/

我不知道什麼時候我會想這樣做,做什麼調度和它做什麼比看到不同只是返回ImageaActions.js中updateImages函數的值

回答

1

當異步調用解析時,您使用dispatch。在這種情況下,它的作用是因爲當你的同步呼叫結束時,你正在呼叫另一個觸發分派的動作(updateImages),因爲getImages沒有觸發分派。記住異步調用的返回是一個承諾。

相關問題