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 app.model: namespace should be unique #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

adam1985
Copy link

No description provided.

@sorrycc
Copy link
Member

sorrycc commented Mar 21, 2017

为啥这么改?

@MinJieLiu
Copy link

应该改为这样:

const registerModel = (app, model) => {
  // eslint-disable-next-line no-underscore-dangle
  if (!app._models.filter(m => m.namespace === model.namespace).length) {
    app.model(model);
  }
};

因为原有的:

const cached = {};
function registerModel(app, model) {
  if (!cached[model.namespace]) {
    app.model(model);
    cached[model.namespace] = 1;
  }
}

cached 变量在热更新之后会被清空掉。从而导致重复注入 model

@sorrycc
Copy link
Member

sorrycc commented Aug 11, 2017

👍

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.

3 participants