{"action":"created","issue":{"url":"https://api.github.com/repos/umijs/umi/issues/816","repository_url":"https://api.github.com/repos/umijs/umi","labels_url":"https://api.github.com/repos/umijs/umi/issues/816/labels{/name}","comments_url":"https://api.github.com/repos/umijs/umi/issues/816/comments","events_url":"https://api.github.com/repos/umijs/umi/issues/816/events","html_url":"https://github.com/umijs/umi/issues/816","id":349822871,"node_id":"MDU6SXNzdWUzNDk4MjI4NzE=","number":816,"title":"dva model state 无法更新","user":{"login":"jinyang1994","id":15340367,"node_id":"MDQ6VXNlcjE1MzQwMzY3","avatar_url":"https://avatars2.githubusercontent.com/u/15340367?v=4","gravatar_id":"","url":"https://api.github.com/users/jinyang1994","html_url":"https://github.com/jinyang1994","followers_url":"https://api.github.com/users/jinyang1994/followers","following_url":"https://api.github.com/users/jinyang1994/following{/other_user}","gists_url":"https://api.github.com/users/jinyang1994/gists{/gist_id}","starred_url":"https://api.github.com/users/jinyang1994/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jinyang1994/subscriptions","organizations_url":"https://api.github.com/users/jinyang1994/orgs","repos_url":"https://api.github.com/users/jinyang1994/repos","events_url":"https://api.github.com/users/jinyang1994/events{/privacy}","received_events_url":"https://api.github.com/users/jinyang1994/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-08-12T15:53:53Z","updated_at":"2018-08-13T05:29:23Z","closed_at":"2018-08-13T05:29:23Z","author_association":"NONE","body":"问题是这样的，我在effect执行了一个异步请求，请求回来了之后，通过reducers更新state。\r\n但是执行完reducers后，我的state并没有更新，而是最开始的默认值。\r\n在reducers的方法中return的前一刻，我打日志还是可以看到我想要的数据。\r\n\r\n```javascript\r\nexport default {\r\n  namespace: 'support',\r\n  state: {\r\n    list: [],\r\n    offset: 0,\r\n    status: 'opened',\r\n    limit: 10,\r\n    count: 0,\r\n  },\r\n  effects: {\r\n    * list({ payload }, { call, put, select }) {\r\n      const { offset, limit, status } = payload;\r\n      const { jsonData: result } = yield call(list, offset, limit, { status });\r\n\r\n      yield put({\r\n        type: 'load',\r\n        payload: {\r\n          limit,\r\n          offset,\r\n          status,\r\n          ...result,\r\n        },\r\n      });\r\n      const test = yield select();\r\n     // 2. 这时已经再查看就发现store中的state并没有改变。\r\n      console.log(test)\r\n      router.push({\r\n        search: `?limit=${limit}&offset=${offset}&status=${status}`,\r\n      });\r\n    },\r\n  },\r\n  reducers: {\r\n    load(state, { payload }) {\r\n      const { list, count, status, limit, offset } = payload;\r\n\r\n      // 1. 此时打log还是可以看到上面payload是我想要的数据。\r\n      console.log(payload);\r\n      // 打印state是proxy对象\r\n      console.log(state); //proxy\r\n      return {\r\n        ...state,\r\n        list,\r\n        count,\r\n        status,\r\n        limit,\r\n        offset,\r\n      };\r\n    },\r\n  },\r\n};\r\n```"},"comment":{"url":"https://api.github.com/repos/umijs/umi/issues/comments/412412034","html_url":"https://github.com/umijs/umi/issues/816#issuecomment-412412034","issue_url":"https://api.github.com/repos/umijs/umi/issues/816","id":412412034,"node_id":"MDEyOklzc3VlQ29tbWVudDQxMjQxMjAzNA==","user":{"login":"jinyang1994","id":15340367,"node_id":"MDQ6VXNlcjE1MzQwMzY3","avatar_url":"https://avatars2.githubusercontent.com/u/15340367?v=4","gravatar_id":"","url":"https://api.github.com/users/jinyang1994","html_url":"https://github.com/jinyang1994","followers_url":"https://api.github.com/users/jinyang1994/followers","following_url":"https://api.github.com/users/jinyang1994/following{/other_user}","gists_url":"https://api.github.com/users/jinyang1994/gists{/gist_id}","starred_url":"https://api.github.com/users/jinyang1994/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jinyang1994/subscriptions","organizations_url":"https://api.github.com/users/jinyang1994/orgs","repos_url":"https://api.github.com/users/jinyang1994/repos","events_url":"https://api.github.com/users/jinyang1994/events{/privacy}","received_events_url":"https://api.github.com/users/jinyang1994/received_events","type":"User","site_admin":false},"created_at":"2018-08-13T05:29:22Z","updated_at":"2018-08-13T05:29:22Z","author_association":"NONE","body":"问题解决了，仔细阅读了一下文档和搜索了一下相关的issue。\r\n发现了一句关键性的话：\r\n\r\n推荐开启 dva-immer 以简化 reducer 编写\r\n```javascript\r\nexport default {\r\n  plugins: [\r\n    ['umi-plugin-dva', { immer: true }],\r\n  ],\r\n};\r\n```\r\n\r\n出现此问题有两种解决办法。\r\n1. 删除`.umirc.js`中的`immer: true`\r\n2. 根据 #592 中相关的回复，将插件更新到`umi-plugin-dva@0.9.0`"}}
{"actor":{"display_login":"jinyang1994"}}