提交 221e4ca5 编写于 作者: L lang

Optimize Model construction, getItemModel always return new

上级 91aead28
......@@ -15,9 +15,9 @@ define(function (require) {
/**
* @overrite
*/
init: function (option, parentModel, ecModel, extraOpt, createdBySelf) {
init: function (option, parentModel, ecModel, extraOpt) {
this.mergeDefaultAndTheme(option, ecModel);
this.mergeOption(option, ecModel, createdBySelf, true);
this.mergeOption(option, ecModel, extraOpt.createdBySelf, true);
},
mergeOption: function (newOpt, ecModel, createdBySelf, isInit) {
......@@ -40,10 +40,11 @@ define(function (require) {
var opt = {
// Use the same series index and name
seriesIndex: seriesModel.seriesIndex,
name: seriesModel.name
name: seriesModel.name,
createdBySelf: true
};
mlModel = new MarkLineModel(
markLineOpt, this, ecModel, opt, true
markLineOpt, this, ecModel, opt
);
}
else {
......
......@@ -13,9 +13,9 @@ define(function (require) {
/**
* @overrite
*/
init: function (option, parentModel, ecModel, extraOpt, createdBySelf) {
init: function (option, parentModel, ecModel, extraOpt) {
this.mergeDefaultAndTheme(option, ecModel);
this.mergeOption(option, ecModel, createdBySelf, true);
this.mergeOption(option, ecModel, extraOpt.createdBySelf, true);
},
mergeOption: function (newOpt, ecModel, createdBySelf, isInit) {
......@@ -38,10 +38,11 @@ define(function (require) {
var opt = {
// Use the same series index and name
seriesIndex: seriesModel.seriesIndex,
name: seriesModel.name
name: seriesModel.name,
createdBySelf: true
};
mpModel = new MarkPointModel(
markPointOpt, this, ecModel, opt, true
markPointOpt, this, ecModel, opt
);
}
else {
......
......@@ -723,7 +723,6 @@ define(function (require) {
return list;
};
var temporaryModel = new Model(null);
// Since temporate model is shared by all data items. So we must make sure it can't be write.
// PENDING may cause any performance problem?
// if (Object.freeze) {
......@@ -731,29 +730,14 @@ define(function (require) {
// }
/**
* Get model of one data item.
* It will create a temporary model if value on idx is not an option.
*
* @param {number} idx
* @param {boolean} [createNew=false]
*/
// FIXME Model proxy ?
listProto.getItemModel = function (idx, createNew) {
var model;
listProto.getItemModel = function (idx) {
var hostModel = this.hostModel;
idx = this.indices[idx];
// Use a temporary model proxy
// FIXME Create a new one may cause memory leak
if (createNew) {
model = new Model(null, hostModel);
}
else {
model = temporaryModel;
}
// FIXME If return null when idx not exists
model.option = this._rawData[idx];
model.parentModel = hostModel;
model.ecModel = hostModel.ecModel;
return model;
return new Model(this._rawData[idx], hostModel, hostModel.ecModel);
};
/**
......@@ -807,7 +791,7 @@ define(function (require) {
/**
* Set layout property.
* @param {string} key
* @param {string} key
* @param {*} val
*/
listProto.setLayout = function (key, val) {
......@@ -819,7 +803,7 @@ define(function (require) {
* @param {string} key.
* @return {*}
*/
listProto.getLayout = function (key) {
listProto.getLayout = function (key) {
return this._layout[key];
};
......
......@@ -12,19 +12,20 @@ define(function (require) {
* @param {Object} option
* @param {module:echarts/model/Model} parentModel
* @param {module:echarts/model/Global} ecModel
* @param {Object} extraOpt
*/
function Model(option, parentModel, ecModel) {
function Model(option, parentModel, ecModel, extraOpt) {
/**
* @type {module:echarts/model/Model}
* @readOnly
*/
this.parentModel = parentModel || null;
this.parentModel = parentModel;
/**
* @type {module:echarts/model/Global}
* @readOnly
*/
this.ecModel = ecModel || null;
this.ecModel = ecModel;
/**
* @type {Object}
......@@ -32,7 +33,15 @@ define(function (require) {
*/
this.option = option;
this.init.apply(this, arguments);
// Simple optimization
if (this.init) {
if (arguments.length <= 4) {
this.init(option, parentModel, ecModel, extraOpt);
}
else {
this.init.apply(this, arguments);
}
}
}
Model.prototype = {
......@@ -43,7 +52,7 @@ define(function (require) {
* Model 的初始化函数
* @param {Object} option
*/
init: function (option) {},
init: null,
/**
* 从新的 Option merge
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册