何时使用 dispatch with alt.js flux

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;
  }
}

目前这在不使用 dispatch() 函数的情况下工作,如他们的教程中所示 http://alt.js.org/guide/async/

我想知道我什么时候想做这个以及 dispatch 做了什么以及它与 ImageaActions.js

中的 updateImages 函数返回值有什么不同

当您的异步调用解决时,您使用 dispatch。在这种情况下,它会起作用,因为当您的同步调用完成时,您正在调用另一个触发调度的操作 (updateImages),因为 getImages 没有触发调度。请记住,异步调用的 return 是一个 Promise。