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

change model inherits

上级 5c830d44
...@@ -41,8 +41,22 @@ define(function(require) { ...@@ -41,8 +41,22 @@ define(function(require) {
*/ */
defaultOption: null, 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) { mergeDefaultAndTheme: function (option, ecModel) {
...@@ -52,10 +66,27 @@ define(function(require) { ...@@ -52,10 +66,27 @@ define(function(require) {
}); });
ComponentModel.extend = function (opts) { ComponentModel.extend = function (proto) {
var SubComponentModel = Model.extend.call(this, opts); var SubComponentModel = function (option, parentModel, ecModel, dependentModels) {
var componentType = opts.type; 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) { if (componentType) {
componentType = ComponentModel.parseComponentType(componentType); componentType = ComponentModel.parseComponentType(componentType);
...@@ -71,7 +102,7 @@ define(function(require) { ...@@ -71,7 +102,7 @@ define(function(require) {
} }
} }
return SubComponentModel; return SubComponentModel;
}; }
ComponentModel.getComponentModelClass = function (componentType, option) { ComponentModel.getComponentModelClass = function (componentType, option) {
var fullComponentType = componentType; var fullComponentType = componentType;
......
...@@ -136,17 +136,6 @@ define(function (require) { ...@@ -136,17 +136,6 @@ define(function (require) {
componentsMap[componentType][i] = componentModel; componentsMap[componentType][i] = componentModel;
components.push(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); }, this);
......
...@@ -10,7 +10,7 @@ define(function (require) { ...@@ -10,7 +10,7 @@ define(function (require) {
* @alias module:echarts/model/Model * @alias module:echarts/model/Model
* @constructor * @constructor
*/ */
function Model(option, parentModel, ecModel, dependentModels) { function Model(option, parentModel) {
/** /**
* @type {module:echarts/model/Model} * @type {module:echarts/model/Model}
...@@ -24,20 +24,6 @@ define(function (require) { ...@@ -24,20 +24,6 @@ define(function (require) {
*/ */
this.option = option; 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} * @type {string}
* @public * @public
...@@ -77,7 +63,7 @@ define(function (require) { ...@@ -77,7 +63,7 @@ define(function (require) {
* @return {*} * @return {*}
*/ */
get: function (path, parentModel) { get: function (path, parentModel) {
if (typeof path == 'string') { if (typeof path === 'string') {
// path = this._prefix + path; // path = this._prefix + path;
path = path.split('.'); path = path.split('.');
} }
...@@ -133,7 +119,9 @@ define(function (require) { ...@@ -133,7 +119,9 @@ define(function (require) {
setVisual: function (key, val) { setVisual: function (key, val) {
if (typeof (key) === 'object') { if (typeof (key) === 'object') {
for (var name in key) { for (var name in key) {
this.setVisual(name, key[name]); if (key.hasOwnProperty(name)) {
this.setVisual(name, key[name]);
}
} }
return; return;
} }
...@@ -151,22 +139,22 @@ define(function (require) { ...@@ -151,22 +139,22 @@ define(function (require) {
}; };
Model.extend = function (proto) { Model.extend = function (proto) {
var Super = this;
var ExtendedModel = function () { var ExtendedModel = function () {
Super.apply(this, arguments); Model.apply(this, arguments);
}; };
for (var name in proto) { 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; ExtendedModel.extend = Super.extend;
zrUtil.inherits(ExtendedModel, Super); zrUtil.inherits(ExtendedModel, Super);
return ExtendedModel; return ExtendedModel;
} };
return Model; 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.
先完成此消息的编辑!
想要评论请 注册