_disposable: function (o, name) { lib.assert(o != null); // 常见的错误 var area = inner(this).cptDisposableArea; // o为 null 或 undefined 时什么也不做,这是为了支持编码的简洁 if (o == null) { return o; } // 全部dispose else if (o === false) { for (var n in area) { if (area.hasOwnProperty(n)) { disposeDisposable.call(this, area[n]); area[n] = null; } } } // 指定名称进行dispose else if ($.type(o) === 'string') { disposeDisposable.call(this, area[o]); area[o] = null; } // 注册可以被dispose的对象 else { lib.assert($.isFunction(o.dispose) || lib.isJQuery(o), 'No dispose method nor not jQuery!'); name = name || '\x0E\x0E-component-anonymouse-disposable' + lib.localUID(); area[name] = o; } return o; },
_constructSubCpt: function (subEl) { var $subEl = $(subEl); var originInnerHTML = subEl.innerHTML; var thisViewModel = this._viewModel(); var def = this._parseCptDef( (new Function( 'viewModel', 'lib', 'lang', 'constant', 'return {' + $subEl.data('cpt') + '};' )).call(this, thisViewModel, lib, this.getLang(), this.getConstant()) ); var Clz = this.getCptClass(def.type); var subViewModel = def.viewModelGet ? getByPath(def.viewModelGet, thisViewModel) : def.viewModel; var subCpt = new Clz(subEl, subViewModel, def); subCpt[ORIGINAL_HTML_KEY] = originInnerHTML; return this._sub( // 如果没定义name,则表示匿名 def.name || ('\x0E\x0F-sub-cpt-name-' + lib.localUID()), subCpt ); },
_construct: function ($el, viewModel, def) { arguments.length > 0 && lib.assert($el != null); // 这种错误太常见了 // 可以初始化无主元素的component if (!$el || $.isPlainObject($el)) { def = viewModel; viewModel = $el; $el = null; } else { $el = $($el); } def = $.extend({}, def); lib.isComponent(this, true); // 标记为Component。 var innerThis = inner(this); innerThis.cptDef = def; // 事件的名空间 innerThis.eventNamespace = '.namespace' + lib.localUID(); // 存放子组件,格式为:{name: someSubComponent} innerThis.subComponents = {}; innerThis.sub$Els = {}; innerThis.disposed = false; innerThis.cptDisposableArea = {}; innerThis.cptInstanceUID = 'cpt-instance-' + lib.localUID(); initViewModelControlMap.call(this); viewModel = this._parseViewModel(viewModel || {}, def) || {}; setViewModel.call(this, viewModel); initCssDefine.call(this); initInnerViewModel.call(this); initMainEl.call(this, $el); this._prepare(); applyBaseTpl.call(this); this._init(); },