[英]When to use dispatch with alt.js flux
我是使用flux的新手,已經開始使用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/中所示的dispatch()函數即可運行
我想知道我什么時候想要這樣做,什么調度以及與從ImageaActions.js中的updateImages函數返回值不同的是什么不同?
您的異步調用解決后,您可以使用dispatch
。 在這種情況下,它之所以有效,是因為當您的同步調用結束時,您正在調用另一個觸發調度的動作( updateImages
),因為getImages
不會觸發調度。 請記住,異步調用的返回是一個承諾。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.