dvajs / dva-example-user-dashboard

👲 👬 👨‍👩‍👧 👨‍👩‍👦‍👦
446 stars 205 forks source link

fix app.model: namespace should be unique #9

Open adam1985 opened 7 years ago

sorrycc commented 7 years ago

为啥这么改?

MinJieLiu commented 7 years ago

应该改为这样:

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 commented 7 years ago

👍