小编Moh*_* RN的帖子

Aurelia在一次行动中两次改变状态

我正在开发aurelia并使用aurelia-store进行应用程序状态管理.在从服务器加载数据时,我想更改isLoading字段true/false以在相关组件上显示掩码.所以我在我的州中定义了一个属性isLoading(例如).在加载操作中,我想首先将加载状态更改为true,并将数据检索为false.所以根据这个字段的值(isLoading)我想在组件上显示掩码.

我想要这样的东西:

export async function getRoles(state) {
  try {
    return Object.assign({}, state, { isRolesListLoading: {busy: true} });
    const getRoles = await accountManagement.getRoles();
    return Object.assign({}, state, { getRoles, isRolesListLoading: {busy: false} });

  } catch (error) {
    console.log('error getRoles "error": ', error);
  }
}
Run Code Online (Sandbox Code Playgroud)

但正如我从aurelia文件中得知的那样,在一个动作中不允许进行两次状态更改.

我该怎么办?

我有一个想法,首先在这个动作中发出另一个动作,使isLoading成为真,然后完成工作.像这样的东西:

export async function getRoles(state) {
  try {
    desiredDispatch('goToLoadingState'); // fake code
    const getRoles = await accountManagement.getRoles();
    return Object.assign({}, state, { getRoles, isRolesListLoading: {busy: false} });

  } catch (error) {
    console.log('error getRoles "error": ', …
Run Code Online (Sandbox Code Playgroud)

action dispatch aurelia aurelia-store

4
推荐指数
1
解决办法
141
查看次数

标签 统计

action ×1

aurelia ×1

aurelia-store ×1

dispatch ×1