提交 85fbe498 编写于 作者: P pah100

change model inherits

上级 5c830d44
......@@ -41,8 +41,22 @@ define(function(require) {
*/
defaultOption: null,
init: function (option, parentModel, ecModel) {
this.mergeDefaultAndTheme(option, ecModel);
/**
* @type {Object}
* @readOnly
*/
ecModel: null,
/**
* key: componentType
* value: Component model list, can not be null.
* @type {Object.<string, Array.<module:echarts/model/Model>>}
* @readOnly
*/
dependentModel: null,
init: function () {
this.mergeDefaultAndTheme(this.option, this.ecModel);
},
mergeDefaultAndTheme: function (option, ecModel) {
......@@ -52,10 +66,27 @@ define(function(require) {
});
ComponentModel.extend = function (opts) {
var SubComponentModel = Model.extend.call(this, opts);
var componentType = opts.type;
ComponentModel.extend = function (proto) {
var SubComponentModel = function (option, parentModel, ecModel, dependentModels) {
this.ecModel = ecModel;
this.dependentModels = dependentModels;
ComponentModel.apply(this, arguments);
};
for (var name in proto) {
if (proto.hasOwnProperty(name)) {
SubComponentModel.prototype[name] = proto[name];
}
}
var Super = this;
SubComponentModel.extend = Super.extend;
zrUtil.inherits(SubComponentModel, Super);
return registerComponentClass(SubComponentModel, proto.type);
};
function registerComponentClass(SubComponentModel, componentType) {
if (componentType) {
componentType = ComponentModel.parseComponentType(componentType);
......@@ -71,7 +102,7 @@ define(function(require) {
}
}
return SubComponentModel;
};
}
ComponentModel.getComponentModelClass = function (componentType, option) {
var fullComponentType = componentType;
......
......@@ -136,17 +136,6 @@ define(function (require) {
componentsMap[componentType][i] = componentModel;
components.push(componentModel);
}
if (componentModel) {
// 同步 Option
if (zrUtil.isArray(componentOption)) {
option[componentType] = option[componentType] || [];
option[componentType][i] = componentModel.option;
}
else {
option[componentType] = componentModel.option;
}
}
}
}, this);
......
......@@ -10,7 +10,7 @@ define(function (require) {
* @alias module:echarts/model/Model
* @constructor
*/
function Model(option, parentModel, ecModel, dependentModels) {
function Model(option, parentModel) {
/**
* @type {module:echarts/model/Model}
......@@ -24,20 +24,6 @@ define(function (require) {
*/
this.option = option;
/**
* @type {Object}
* @protected
*/
this.ecModel = ecModel;
/**
* key: componentType
* value: Array.<Object> Component model list, can not be null.
* @type {Object}
* @readOnly
*/
this.dependentModels = dependentModels;
/**
* @type {string}
* @public
......@@ -77,7 +63,7 @@ define(function (require) {
* @return {*}
*/
get: function (path, parentModel) {
if (typeof path == 'string') {
if (typeof path === 'string') {
// path = this._prefix + path;
path = path.split('.');
}
......@@ -133,7 +119,9 @@ define(function (require) {
setVisual: function (key, val) {
if (typeof (key) === 'object') {
for (var name in key) {
this.setVisual(name, key[name]);
if (key.hasOwnProperty(name)) {
this.setVisual(name, key[name]);
}
}
return;
}
......@@ -151,22 +139,22 @@ define(function (require) {
};
Model.extend = function (proto) {
var Super = this;
var ExtendedModel = function () {
Super.apply(this, arguments);
Model.apply(this, arguments);
};
for (var name in proto) {
ExtendedModel.prototype[name] = proto[name];
if (proto.hasOwnProperty(name)) {
ExtendedModel.prototype[name] = proto[name];
}
}
var Super = this;
ExtendedModel.extend = Super.extend;
zrUtil.inherits(ExtendedModel, Super);
return ExtendedModel;
}
};
return Model;
});
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册