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

fix dynamic #1176

Merged
merged 1 commit into from
Sep 4, 2017
Merged

fix dynamic #1176

merged 1 commit into from
Sep 4, 2017

Conversation

jdz321
Copy link
Contributor

@jdz321 jdz321 commented Sep 4, 2017

https://github.com/dvajs/dva/blob/master/packages/dva-example-user-dashboard/src/router.js#L11

  const Users = dynamic({
    app,
    models: [
      import('./models/users'),
    ],
    component: import('./routes/Users'),
  });

这种 dynamic 写法,在加载router.js的时候,models和component都会被加载,事实上貌似没有做到dynamic?此处应该传入function,在asyncComponent()里去resolve需要动态加载的模块

例如

  const Users = dynamic({
    app,
    models: () => [
      import('./models/users'),
    ],
    component: () => import('./routes/Users'),
  });

另外 实际使用时,可能需要在 app.model(model) 前对model做些处理,所以dynamic可以传入自定义的app.model方法,使用更灵活一些,例如

  const mounter = app.model
  // or
  // const mounter = model => app.model(doSomething(model))

  const Users = dynamic({
    mounter,
    models: () => [
      import('./models/users'),
    ],
    component: () => import('./routes/Users'),
  });

@sorrycc
Copy link
Member

sorrycc commented Sep 4, 2017

const Users = dynamic({
  app,
  models: () => [
    import('./models/users'),
  ],
  component: () => import('./routes/Users'),
});

还是这样吧。

实际使用时,可能需要在 app.model(model) 前对model做些处理

可以在 import() 返回的 Promise 里处理,比如:

import('./models/users').then(resolveModel)

@jdz321
Copy link
Contributor Author

jdz321 commented Sep 4, 2017

@sorrycc 不错,我改了下,麻烦review~

@sorrycc sorrycc added the bug label Sep 4, 2017
@sorrycc
Copy link
Member

sorrycc commented Sep 4, 2017

1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants