Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

在model里面,我怎么定义非状态的变量? #130

Closed
bjwulin opened this issue Oct 8, 2016 · 6 comments
Closed

在model里面,我怎么定义非状态的变量? #130

bjwulin opened this issue Oct 8, 2016 · 6 comments

Comments

@bjwulin
Copy link

bjwulin commented Oct 8, 2016

1、rn的ListView,ds.cloneWithRows(items),那么我必须保存一份items数据,ds是状态变量,items是不需要放到状态里面的,因此,我只是希望在model中做一个非状态的变量,我现在是这样做:

let _items=[];
let _loadedAll=false;
export default {
  namespace: 'doingTaskStore',
...

`
不知道是否合理?

2、dva for web,怎么拆分index.js,现在快1M了?

3、比如有个变量,rn的ListView的refreshing,类似loading,我将fetch的error都放到dva的onError里面了,因此,如果有错,都由onError处理了,那么我怎么在error时关闭refreshing?

@sorrycc
Copy link
Member

sorrycc commented Oct 8, 2016

  1. 别在 reducer 里调这些变量就都是合理的
  2. dva 本身是 439K (压缩后 296k),剩下的都是项目的依赖库引入的大小,拆分可以用 dymanic router,例子:https://github.com/dvajs/dva/tree/master/examples/dynamic-load
  3. error 需要支持 dispatch,下个版本支持,Support dispatch in onError hook #126

@bjwulin
Copy link
Author

bjwulin commented Oct 8, 2016

@sorrycc ,我reducer这样,有问题没:

 reducers: {
    gettedDoingTasks(state, {payload}) {
      const ret=ListUtils.getListDatasource(state.ds,_items,payload);
      _items=ret.items;
      _loadedAll=ret.loadedAll;
      return {...state, ds:ret.ds,};
    },

2、我想吧dva,reactjs,一些第三方库和业务拆分出来,因为变化的只会是业务。

@sorrycc
Copy link
Member

sorrycc commented Oct 8, 2016

有问题,这样 reducer 就不是 pure function 了,出问题时会不好排查。

@bjwulin
Copy link
Author

bjwulin commented Oct 8, 2016

但是我怎么写会比较好一点,我确实不希望有些变量放到state里面,没有意义。

@sorrycc
Copy link
Member

sorrycc commented Oct 8, 2016

可以在 effect 里获取 _items 和 _loadedAll,通过 payload 传给 reducer 。

@bjwulin
Copy link
Author

bjwulin commented Oct 8, 2016

好的,明白,就是把这个变量赋值逻辑放在effect里面,reducer纯粹改变state就行。谢谢。

@bjwulin bjwulin closed this as completed Oct 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants