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

Improve dva models resolve #171

Closed
sorrycc opened this issue Mar 6, 2018 · 5 comments
Closed

Improve dva models resolve #171

sorrycc opened this issue Mar 6, 2018 · 5 comments

Comments

@sorrycc
Copy link
Member

sorrycc commented Mar 6, 2018

方案

  • src/models/**/*.js 为 global model
  • src/pages/**/models/**/*.js 为 page model
  • global model 全量载入,page model 在 production 时按需载入,在 development 时全量载入
  • page model 为 page js 所在路径下 models/**/*.js 的文件
  • page model 要向上查找,比如 page js 为 pages/a/b.js,他的 page model 为 pages/a/b/models/**/*.js + pages/a/models/**/*.js,依次类推
  • 约定 model.js 为单文件 model,解决只有一个 model 时不需要建 models 目录的问题,有 model.js 则不去找 models/**/*.js
  • maybe: 支持合并 model 和 component 的请求,避免文件过于细碎

例子

src
  models
    g.js
  pages
    a
      models
        a.js
        b.js
        ss
          s.js
      page.js
    c
      model.js
      d
        models
          d.js
        page.js
      page.js

如上目录:

  • global model 为 src/models/g.js
  • /a 的 page model 为 src/pages/a/models/{a,b,ss/s}.js
  • /c 的 page model 为 src/pages/c/model.js
  • /c/d 的 page model 为 src/pages/c/model.js, src/pages/c/d/models/d.js

相关 issue

@elivoa, @maxiaochuan

@superlbr
Copy link
Contributor

加到文档里吧,翻issue好麻烦

@fattypanda
Copy link

那么,两个页面共用一个model的情况该怎么弄呢

@fattypanda
Copy link

假设 a/b/c 三个页面同为 d 页面下的嵌套页面,但 a/b 都用到了模型 e, c 页面没有用到,我想要 a/b 其中一个页面加载时就加载模型 e,但 c 页面不会去加载。
目前这样会出现 a/b 各加载一次模型 e , 导致 [app.model] namespace should be unique 的问题

@aweffr
Copy link

aweffr commented May 25, 2018

+1,这个加到umijs的文档里吧,我找models的注册规则找了好一会...

@huynhquocthao
Copy link

I have a problem same as @fattypanda. Do we have any solution?

xierenyuan pushed a commit to xierenyuan/umi that referenced this issue Jun 23, 2022
* fix: alias dirname error

* chore: code style

* feat: getRealFile

* chore: code style
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants