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

Break changes: namespace, reducers, effects and subscriptions #42

Merged
merged 17 commits into from
Aug 22, 2016

Conversation

sorrycc
Copy link
Member

@sorrycc sorrycc commented Aug 20, 2016

TODO

  • reducers 和 effects 自动加 namespace 前缀
  • 删除 dva/effects 接口,通过 effect 函数的第二个参数传入 (put 被封装)
  • 封装 effect 的 put 和 subscription 的 dispatch,触发当前 model 的 action 时无需加 namespace 前缀
  • subscriptions 改成 key/value 格式,1 是和 reducers 和 effects 保持一致,2 是有命名方便跟踪
  • assert 换成 invariantwarning,然后脚手架内置 babel-plugin-dev-expression 让生产环境上不会出现 error 和 warning 信息
  • 简化 app.startapp.start 的配置信息移到 dva()
  • 梳理测试用例
  • onAction 支持数组格式
  • 提供升级文档
  • 修改 examples 和 dva-hackernews
  • 更新 dva-cli,兼容新的改动
  • 修改入门文档
  • 修改 README

Example

const app = dva();

app.model({
  namespace: 'loading',
  state: false,
  reducers: {
    show(state) { return true; },
    hide(state) { return false; },
  },
});

app.model({
  namespace: 'count',
  state: 0,
  subscriptions: {
    keyboard({ dispatch }) {
      return key('ctrl+up', () => { dispatch({ type: 'addWithDelay' }); });
    },
  },
  effects: {
    *addWithDelay(action, { put, call }) {
      yield put({ type: 'loading/show' });
      yield call(delay, 1000);
      yield put({ type: 'add' });
      yield put({ type: 'loading/hide' });
    },
  },
  reducers: {
    add(state) {
      return state + 1;
    },
  },
});

@sorrycc
Copy link
Member Author

sorrycc commented Aug 22, 2016

升级文档

app.start()

把之前给 app.start() 的参数传给 app = dva()

- const app = dva();
+ const app = dva({
+   history,
+   initialState,
+ });
...
- app.start({
-   history,
-   initialState,
- });
+ app.start();

app.model()

  1. 删除 reducers 和 effects 的 namespace 前缀
  2. 删除 effects 里 put(action) 以及 subscriptions 里 dispatch(action) 的 namespace 前缀 (注:调用其他 model 的 action 时还是需要加 namespace 的)
  3. 删除 /dva/effects 的引用,put, call 等 effects 从第二个参数里获取
  4. subscriptions 的格式从数组改成 Object
- import { put, call } from 'dva/effects';

app.model({
  namespace: 'count',
  reducers: {
-     'count/add'() {},
+     add() {},
  },
  effects: {
-     *'count/addDelay'(action) {
+     *addDelay(action, { call, put }) {
      yield call(delay, 1000);
-       yield put({ type: 'count/add');
+       yield put({ type: 'add');
    },
  },
  subscriptions: [
-     function({ dispatch }) {
+     setup({ dispatch }) {
-       dispatch({ type: 'count/addDelay' });
+       dispatch({ type: 'addDelay' });
    },
  ],
});

@sorrycc sorrycc force-pushed the break-changes branch 9 times, most recently from 4a9fa60 to c304325 Compare August 22, 2016 10:49
@sorrycc sorrycc merged commit 01ff888 into master Aug 22, 2016
@sorrycc sorrycc deleted the break-changes branch August 22, 2016 10:51
@sorrycc sorrycc restored the break-changes branch August 22, 2016 23:58
@xunv
Copy link

xunv commented Jan 18, 2017

根据dva-cli创建了项目,dva -v时结果为0.7.8,问下怎么升级到1.2。

@sorrycc
Copy link
Member Author

sorrycc commented Jan 19, 2017

0.7.8 是 dva-cli 的版本,dva 的版本要看 package.json 中的 dva 依赖。

@Hsinky
Copy link

Hsinky commented Jan 20, 2017

用什么命令来统一更新本地已创建好的框架?

@afc163
Copy link
Contributor

afc163 commented Jan 20, 2017

用 diff 格式来写 before 和 after 的代码变化。


...才发现这是 8 月份的改动。

@sorrycc
Copy link
Member Author

sorrycc commented Jan 20, 2017

@afc163 DONE

@951565664
Copy link

请问如何改端口号呢???

@sorrycc
Copy link
Member Author

sorrycc commented Jan 30, 2017

@951565664 roadhog? 参考 https://github.com/sorrycc/roadhog#环境变量

@miaozilong
Copy link

我想问下以下命令的详细清单或教程在哪能找到 以下都是百度的 应该不全
路由 dva route 路由名
组件 dva component 组件名
模型 dva model 模型名

@nihgwu
Copy link
Member

nihgwu commented Mar 14, 2017

@TBoyLi
Copy link

TBoyLi commented Mar 23, 2017

执行dva new 命令到node install 这里就卡住了。 半天没动静。dva 0.7.8

@sorrycc
Copy link
Member Author

sorrycc commented Mar 23, 2017

@TBoyLi 全局安装个 cnpm 试试。

@lixuecn lixuecn mentioned this pull request Jul 23, 2017
@AlwaysOnTheWay
Copy link

dva的其他版本号哪里可以看到?

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

Successfully merging this pull request may close these issues.

None yet

9 participants