|
|
@ -30,7 +30,7 @@ function callLifeHook(self, life) { |
|
|
|
if (hook) { |
|
|
|
if (hook) { |
|
|
|
hooks = hooks.concat(isArray(hook) ? hook : [hook]); |
|
|
|
hooks = hooks.concat(isArray(hook) ? hook : [hook]); |
|
|
|
} |
|
|
|
} |
|
|
|
each(hooks, function (i, hook) { |
|
|
|
each(hooks, (i, hook) => { |
|
|
|
hook.call(self); |
|
|
|
hook.call(self); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
@ -53,7 +53,7 @@ export class Widget extends OB { |
|
|
|
baseCls: "", |
|
|
|
baseCls: "", |
|
|
|
extraCls: "", |
|
|
|
extraCls: "", |
|
|
|
cls: "", |
|
|
|
cls: "", |
|
|
|
css: null |
|
|
|
css: null, |
|
|
|
|
|
|
|
|
|
|
|
// vdom: false
|
|
|
|
// vdom: false
|
|
|
|
}); |
|
|
|
}); |
|
|
@ -132,6 +132,7 @@ export class Widget extends OB { |
|
|
|
// 加个保险
|
|
|
|
// 加个保险
|
|
|
|
if (initCallbackCalled === true) { |
|
|
|
if (initCallbackCalled === true) { |
|
|
|
_global.console && console.error("组件: 请检查beforeInit内部的写法,callback只能执行一次"); |
|
|
|
_global.console && console.error("组件: 请检查beforeInit内部的写法,callback只能执行一次"); |
|
|
|
|
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
initCallbackCalled = true; |
|
|
|
initCallbackCalled = true; |
|
|
@ -140,18 +141,19 @@ export class Widget extends OB { |
|
|
|
// 加个保险
|
|
|
|
// 加个保险
|
|
|
|
if (renderCallbackCalled === true) { |
|
|
|
if (renderCallbackCalled === true) { |
|
|
|
_global.console && console.error("组件: 请检查beforeRender内部的写法,callback只能执行一次"); |
|
|
|
_global.console && console.error("组件: 请检查beforeRender内部的写法,callback只能执行一次"); |
|
|
|
|
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
renderCallbackCalled = true; |
|
|
|
renderCallbackCalled = true; |
|
|
|
this._render(); |
|
|
|
this._render(); |
|
|
|
this.__afterRender(); |
|
|
|
this.__afterRender(); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
if (this.options.beforeRender || this.beforeRender) { |
|
|
|
if (this.options.beforeRender || this.beforeRender) { |
|
|
|
this.__async = true; |
|
|
|
this.__async = true; |
|
|
|
const beforeRenderResult = (this.options.beforeRender || this.beforeRender).call(this, render); |
|
|
|
const beforeRenderResult = (this.options.beforeRender || this.beforeRender).call(this, render); |
|
|
|
if (beforeRenderResult instanceof Promise) { |
|
|
|
if (beforeRenderResult instanceof Promise) { |
|
|
|
beforeRenderResult.then(render).catch(function (e) { |
|
|
|
beforeRenderResult.then(render).catch(e => { |
|
|
|
_global.console && console.error(e); |
|
|
|
_global.console && console.error(e); |
|
|
|
render(); |
|
|
|
render(); |
|
|
|
}); |
|
|
|
}); |
|
|
@ -160,13 +162,13 @@ export class Widget extends OB { |
|
|
|
this._render(); |
|
|
|
this._render(); |
|
|
|
this.__afterRender(); |
|
|
|
this.__afterRender(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
if (this.options.beforeInit || this.beforeInit) { |
|
|
|
if (this.options.beforeInit || this.beforeInit) { |
|
|
|
this.__asking = true; |
|
|
|
this.__asking = true; |
|
|
|
const beforeInitResult = (this.options.beforeInit || this.beforeInit).call(this, init); |
|
|
|
const beforeInitResult = (this.options.beforeInit || this.beforeInit).call(this, init); |
|
|
|
if (beforeInitResult instanceof Promise) { |
|
|
|
if (beforeInitResult instanceof Promise) { |
|
|
|
beforeInitResult.then(init).catch(function (e) { |
|
|
|
beforeInitResult.then(init).catch(e => { |
|
|
|
_global.console && console.error(e); |
|
|
|
_global.console && console.error(e); |
|
|
|
init(); |
|
|
|
init(); |
|
|
|
}); |
|
|
|
}); |
|
|
@ -206,11 +208,11 @@ export class Widget extends OB { |
|
|
|
this._initElementWidth(); |
|
|
|
this._initElementWidth(); |
|
|
|
this._initElementHeight(); |
|
|
|
this._initElementHeight(); |
|
|
|
if (o._baseCls || o.baseCls || o.extraCls) { |
|
|
|
if (o._baseCls || o.baseCls || o.extraCls) { |
|
|
|
this.element.addClass((o._baseCls || "") + " " + (o.baseCls || "") + " " + (o.extraCls || "")); |
|
|
|
this.element.addClass(`${o._baseCls || ""} ${o.baseCls || ""} ${o.extraCls || ""}`); |
|
|
|
} |
|
|
|
} |
|
|
|
if (o.cls) { |
|
|
|
if (o.cls) { |
|
|
|
if (isFunction(o.cls)) { |
|
|
|
if (isFunction(o.cls)) { |
|
|
|
const cls = this.__watch(o.cls, (context, newValue) => { |
|
|
|
let cls = this.__watch(o.cls, (context, newValue) => { |
|
|
|
this.element.removeClass(cls).addClass(cls = newValue); |
|
|
|
this.element.removeClass(cls).addClass(cls = newValue); |
|
|
|
}); |
|
|
|
}); |
|
|
|
this.element.addClass(cls); |
|
|
|
this.element.addClass(cls); |
|
|
@ -229,7 +231,7 @@ export class Widget extends OB { |
|
|
|
} |
|
|
|
} |
|
|
|
if (o.css) { |
|
|
|
if (o.css) { |
|
|
|
if (isFunction(o.css)) { |
|
|
|
if (isFunction(o.css)) { |
|
|
|
const css = this.__watch(o.css, (context, newValue) => { |
|
|
|
let css = this.__watch(o.css, (context, newValue) => { |
|
|
|
for (const k in css) { |
|
|
|
for (const k in css) { |
|
|
|
if (isNull(newValue[k])) { |
|
|
|
if (isNull(newValue[k])) { |
|
|
|
newValue[k] = ""; |
|
|
|
newValue[k] = ""; |
|
|
@ -247,14 +249,13 @@ export class Widget extends OB { |
|
|
|
__watch(getter, handler, options) { |
|
|
|
__watch(getter, handler, options) { |
|
|
|
if (_global.Fix) { |
|
|
|
if (_global.Fix) { |
|
|
|
this._watchers = this._watchers || []; |
|
|
|
this._watchers = this._watchers || []; |
|
|
|
const watcher = new Fix.Watcher(null, () => { |
|
|
|
const watcher = new Fix.Watcher(null, () => getter.call(this, this), (handler && (v => { |
|
|
|
return getter.call(this, this); |
|
|
|
|
|
|
|
}, (handler && ((v) => { |
|
|
|
|
|
|
|
handler.call(this, this, v); |
|
|
|
handler.call(this, this, v); |
|
|
|
})) || BI.emptyFn, extend({ deep: true }, options)); |
|
|
|
})) || BI.emptyFn, extend({ deep: true }, options)); |
|
|
|
this._watchers.push(() => { |
|
|
|
this._watchers.push(() => { |
|
|
|
watcher.teardown(); |
|
|
|
watcher.teardown(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
return watcher.value; |
|
|
|
return watcher.value; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return getter(); |
|
|
|
return getter(); |
|
|
@ -374,7 +375,7 @@ export class Widget extends OB { |
|
|
|
each(els, (i, el) => { |
|
|
|
each(els, (i, el) => { |
|
|
|
if (el) { |
|
|
|
if (el) { |
|
|
|
_lazyCreateWidget(el, { |
|
|
|
_lazyCreateWidget(el, { |
|
|
|
element: this |
|
|
|
element: this, |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
@ -422,6 +423,7 @@ export class Widget extends OB { |
|
|
|
this.__afterMount(lifeHook, predicate); |
|
|
|
this.__afterMount(lifeHook, predicate); |
|
|
|
// }, 0);
|
|
|
|
// }, 0);
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -444,10 +446,12 @@ export class Widget extends OB { |
|
|
|
|
|
|
|
|
|
|
|
_update(nextProps, shouldUpdate) { |
|
|
|
_update(nextProps, shouldUpdate) { |
|
|
|
callLifeHook(this, "beforeUpdate"); |
|
|
|
callLifeHook(this, "beforeUpdate"); |
|
|
|
|
|
|
|
let res; |
|
|
|
if (shouldUpdate) { |
|
|
|
if (shouldUpdate) { |
|
|
|
const res = this.update && this.update(nextProps, shouldUpdate); |
|
|
|
res = this.update && this.update(nextProps, shouldUpdate); |
|
|
|
} |
|
|
|
} |
|
|
|
callLifeHook(this, "updated"); |
|
|
|
callLifeHook(this, "updated"); |
|
|
|
|
|
|
|
|
|
|
|
return res; |
|
|
|
return res; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -476,7 +480,7 @@ export class Widget extends OB { |
|
|
|
this.options._disabled = true; |
|
|
|
this.options._disabled = true; |
|
|
|
} |
|
|
|
} |
|
|
|
// 递归将所有子组件使能
|
|
|
|
// 递归将所有子组件使能
|
|
|
|
each(this._children, function (i, child) { |
|
|
|
each(this._children, (i, child) => { |
|
|
|
!child._manualSetEnable && child._setEnable && child._setEnable(enable); |
|
|
|
!child._manualSetEnable && child._setEnable && child._setEnable(enable); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
@ -488,7 +492,7 @@ export class Widget extends OB { |
|
|
|
this.options._invalid = true; |
|
|
|
this.options._invalid = true; |
|
|
|
} |
|
|
|
} |
|
|
|
// 递归将所有子组件使有效
|
|
|
|
// 递归将所有子组件使有效
|
|
|
|
each(this._children, function (i, child) { |
|
|
|
each(this._children, (i, child) => { |
|
|
|
!child._manualSetValid && child._setValid && child._setValid(valid); |
|
|
|
!child._manualSetValid && child._setValid && child._setValid(valid); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
@ -525,36 +529,36 @@ export class Widget extends OB { |
|
|
|
this.__setElementVisible(true); |
|
|
|
this.__setElementVisible(true); |
|
|
|
this._mount(); |
|
|
|
this._mount(); |
|
|
|
if (o.animation && !lastVisible) { |
|
|
|
if (o.animation && !lastVisible) { |
|
|
|
this.element.removeClass(o.animation + "-leave").removeClass(o.animation + "-leave-active").addClass(o.animation + "-enter"); |
|
|
|
this.element.removeClass(`${o.animation}-leave`).removeClass(`${o.animation}-leave-active`).addClass(`${o.animation}-enter`); |
|
|
|
if (this._requestAnimationFrame) { |
|
|
|
if (this._requestAnimationFrame) { |
|
|
|
cancelAnimationFrame(this._requestAnimationFrame); |
|
|
|
cancelAnimationFrame(this._requestAnimationFrame); |
|
|
|
} |
|
|
|
} |
|
|
|
this._requestAnimationFrame = () => { |
|
|
|
this._requestAnimationFrame = () => { |
|
|
|
this.element.addClass(o.animation + "-enter-active"); |
|
|
|
this.element.addClass(`${o.animation}-enter-active`); |
|
|
|
}; |
|
|
|
}; |
|
|
|
requestAnimationFrame(this._requestAnimationFrame); |
|
|
|
requestAnimationFrame(this._requestAnimationFrame); |
|
|
|
if (this._animationDuring) { |
|
|
|
if (this._animationDuring) { |
|
|
|
clearTimeout(this._animationDuring); |
|
|
|
clearTimeout(this._animationDuring); |
|
|
|
} |
|
|
|
} |
|
|
|
this._animationDuring = setTimeout(() => { |
|
|
|
this._animationDuring = setTimeout(() => { |
|
|
|
this.element.removeClass(o.animation + "-enter").removeClass(o.animation + "-enter-active"); |
|
|
|
this.element.removeClass(`${o.animation}-enter`).removeClass(`${o.animation}-enter-active`); |
|
|
|
}, o.animationDuring); |
|
|
|
}, o.animationDuring); |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (visible === false) { |
|
|
|
} else if (visible === false) { |
|
|
|
if (o.animation && lastVisible) { |
|
|
|
if (o.animation && lastVisible) { |
|
|
|
this.element.removeClass(o.animation + "-enter").removeClass(o.animation + "-enter-active").addClass(o.animation + "-leave"); |
|
|
|
this.element.removeClass(`${o.animation}-enter`).removeClass(`${o.animation}-enter-active`).addClass(`${o.animation}-leave`); |
|
|
|
if (this._requestAnimationFrame) { |
|
|
|
if (this._requestAnimationFrame) { |
|
|
|
cancelAnimationFrame(this._requestAnimationFrame); |
|
|
|
cancelAnimationFrame(this._requestAnimationFrame); |
|
|
|
} |
|
|
|
} |
|
|
|
this._requestAnimationFrame = () => { |
|
|
|
this._requestAnimationFrame = () => { |
|
|
|
this.element.addClass(o.animation + "-leave-active"); |
|
|
|
this.element.addClass(`${o.animation}-leave-active`); |
|
|
|
}; |
|
|
|
}; |
|
|
|
requestAnimationFrame(this._requestAnimationFrame); |
|
|
|
requestAnimationFrame(this._requestAnimationFrame); |
|
|
|
if (this._animationDuring) { |
|
|
|
if (this._animationDuring) { |
|
|
|
clearTimeout(this._animationDuring); |
|
|
|
clearTimeout(this._animationDuring); |
|
|
|
} |
|
|
|
} |
|
|
|
this._animationDuring = setTimeout(() => { |
|
|
|
this._animationDuring = setTimeout(() => { |
|
|
|
this.element.removeClass(o.animation + "-leave").removeClass(o.animation + "-leave-active"); |
|
|
|
this.element.removeClass(`${o.animation}-leave`).removeClass(`${o.animation}-leave-active`); |
|
|
|
this.__setElementVisible(false); |
|
|
|
this.__setElementVisible(false); |
|
|
|
}, o.animationDuring); |
|
|
|
}, o.animationDuring); |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -582,8 +586,8 @@ export class Widget extends OB { |
|
|
|
doBehavior() { |
|
|
|
doBehavior() { |
|
|
|
const args = arguments; |
|
|
|
const args = arguments; |
|
|
|
// 递归将所有子组件使有效
|
|
|
|
// 递归将所有子组件使有效
|
|
|
|
each(this._children, function (i, child) { |
|
|
|
each(this._children, (i, child) => { |
|
|
|
child.doBehavior && child.doBehavior.apply(child, args); |
|
|
|
child.doBehavior && child.doBehavior(...args); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -602,7 +606,7 @@ export class Widget extends OB { |
|
|
|
name = widget.getName(); |
|
|
|
name = widget.getName(); |
|
|
|
} |
|
|
|
} |
|
|
|
if (isKey(name)) { |
|
|
|
if (isKey(name)) { |
|
|
|
name = name + ""; |
|
|
|
name = `${name}`; |
|
|
|
} |
|
|
|
} |
|
|
|
name = name || widget.getName() || uniqueId("widget"); |
|
|
|
name = name || widget.getName() || uniqueId("widget"); |
|
|
|
if (this._children[name]) { |
|
|
|
if (this._children[name]) { |
|
|
@ -613,6 +617,7 @@ export class Widget extends OB { |
|
|
|
// TODO: self待删
|
|
|
|
// TODO: self待删
|
|
|
|
remove(self._children, this); |
|
|
|
remove(self._children, this); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
return (this._children[name] = widget); |
|
|
|
return (this._children[name] = widget); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -620,20 +625,21 @@ export class Widget extends OB { |
|
|
|
if (!isKey(name) || name === this.getName()) { |
|
|
|
if (!isKey(name) || name === this.getName()) { |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
name = name + ""; |
|
|
|
name = `${name}`; |
|
|
|
let widget = void 0, other = {}; |
|
|
|
let widget = void 0; |
|
|
|
any(this._children, function (i, wi) { |
|
|
|
const other = {}; |
|
|
|
|
|
|
|
any(this._children, (i, wi) => { |
|
|
|
if (i === name) { |
|
|
|
if (i === name) { |
|
|
|
widget = wi; |
|
|
|
widget = wi; |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
other[i] = wi; |
|
|
|
other[i] = wi; |
|
|
|
}); |
|
|
|
}); |
|
|
|
if (!widget) { |
|
|
|
if (!widget) { |
|
|
|
any(other, function (i, wi) { |
|
|
|
any(other, (i, wi) => (widget = wi.getWidgetByName(i))); |
|
|
|
return (widget = wi.getWidgetByName(i)); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return widget; |
|
|
|
return widget; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -646,7 +652,7 @@ export class Widget extends OB { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
hasWidget(name) { |
|
|
|
hasWidget(name) { |
|
|
|
return this._children[name] != null; |
|
|
|
return isNotNull(this._children[name]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
getName() { |
|
|
|
getName() { |
|
|
@ -664,11 +670,13 @@ export class Widget extends OB { |
|
|
|
attr(key, value) { |
|
|
|
attr(key, value) { |
|
|
|
if (isPlainObject(key)) { |
|
|
|
if (isPlainObject(key)) { |
|
|
|
each(key, (k, v) => this.attr(k, v)); |
|
|
|
each(key, (k, v) => this.attr(k, v)); |
|
|
|
|
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
if (isNotNull(value)) { |
|
|
|
if (isNotNull(value)) { |
|
|
|
return this.options[key] = value; |
|
|
|
this.options[key] = value; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return this.options[key]; |
|
|
|
return this.options[key]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -729,7 +737,7 @@ export class Widget extends OB { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
__d() { |
|
|
|
__d() { |
|
|
|
each(this._children, function (i, widget) { |
|
|
|
each(this._children, (i, widget) => { |
|
|
|
widget && widget._unMount && widget._unMount(); |
|
|
|
widget && widget._unMount && widget._unMount(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
this._children = {}; |
|
|
|
this._children = {}; |
|
|
@ -747,7 +755,6 @@ export class Widget extends OB { |
|
|
|
this.destroyed = null; |
|
|
|
this.destroyed = null; |
|
|
|
this._isDestroyed = true; |
|
|
|
this._isDestroyed = true; |
|
|
|
// this._purgeRef(); // 清除ref的时机还是要仔细考虑一下
|
|
|
|
// this._purgeRef(); // 清除ref的时机还是要仔细考虑一下
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_unMount() { |
|
|
|
_unMount() { |
|
|
@ -767,7 +774,7 @@ export class Widget extends OB { |
|
|
|
|
|
|
|
|
|
|
|
_empty () { |
|
|
|
_empty () { |
|
|
|
this._assetMounted(); |
|
|
|
this._assetMounted(); |
|
|
|
each(this._children, function (i, widget) { |
|
|
|
each(this._children, (i, widget) => { |
|
|
|
widget && widget._unMount && widget._unMount(); |
|
|
|
widget && widget._unMount && widget._unMount(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
this._children = {}; |
|
|
|
this._children = {}; |
|
|
@ -801,9 +808,9 @@ export class Widget extends OB { |
|
|
|
// this.purgeListeners();
|
|
|
|
// this.purgeListeners();
|
|
|
|
|
|
|
|
|
|
|
|
// 去掉组件绑定的watcher
|
|
|
|
// 去掉组件绑定的watcher
|
|
|
|
each(this._watchers, function (i, unwatches) { |
|
|
|
each(this._watchers, (i, unwatches) => { |
|
|
|
unwatches = isArray(unwatches) ? unwatches : [unwatches]; |
|
|
|
unwatches = isArray(unwatches) ? unwatches : [unwatches]; |
|
|
|
each(unwatches, function (j, unwatch) { |
|
|
|
each(unwatches, (j, unwatch) => { |
|
|
|
unwatch(); |
|
|
|
unwatch(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
@ -839,7 +846,7 @@ export class Widget extends OB { |
|
|
|
this._purgeRef(); |
|
|
|
this._purgeRef(); |
|
|
|
this.purgeListeners(); |
|
|
|
this.purgeListeners(); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let context = null, current = null; |
|
|
|
let context = null, current = null; |
|
|
|
const contextStack = [], currentStack = []; |
|
|
|
const contextStack = [], currentStack = []; |
|
|
@ -882,35 +889,42 @@ export function useStore(_store) { |
|
|
|
} |
|
|
|
} |
|
|
|
if (current) { |
|
|
|
if (current) { |
|
|
|
const currentStore = current._store; |
|
|
|
const currentStore = current._store; |
|
|
|
let delegate = {}, origin; |
|
|
|
const delegate = {}; |
|
|
|
|
|
|
|
let origin; |
|
|
|
if (_global.Proxy) { |
|
|
|
if (_global.Proxy) { |
|
|
|
const proxy = new Proxy(delegate, { |
|
|
|
const proxy = new Proxy(delegate, { |
|
|
|
get: function (target, key) { |
|
|
|
get (target, key) { |
|
|
|
return Reflect.get(origin, key); |
|
|
|
return Reflect.get(origin, key); |
|
|
|
}, |
|
|
|
}, |
|
|
|
set: function (target, key, value) { |
|
|
|
set (target, key, value) { |
|
|
|
return Reflect.set(origin, key, value); |
|
|
|
return Reflect.set(origin, key, value); |
|
|
|
} |
|
|
|
}, |
|
|
|
}); |
|
|
|
}); |
|
|
|
current._store = function () { |
|
|
|
current._store = function () { |
|
|
|
origin = (_store || currentStore).apply(this, arguments); |
|
|
|
origin = (_store || currentStore).apply(this, arguments); |
|
|
|
delegate.$delegate = origin; |
|
|
|
delegate.$delegate = origin; |
|
|
|
|
|
|
|
|
|
|
|
return origin; |
|
|
|
return origin; |
|
|
|
}; |
|
|
|
}; |
|
|
|
return current.$storeDelegate = proxy; |
|
|
|
current.$storeDelegate = proxy; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return current.$storeDelegate; |
|
|
|
} |
|
|
|
} |
|
|
|
current._store = function () { |
|
|
|
current._store = function () { |
|
|
|
const st = (_store || currentStore).apply(this, arguments); |
|
|
|
const st = (_store || currentStore).apply(this, arguments); |
|
|
|
extend(delegate, st); |
|
|
|
extend(delegate, st); |
|
|
|
|
|
|
|
|
|
|
|
return st; |
|
|
|
return st; |
|
|
|
}; |
|
|
|
}; |
|
|
|
return current.$storeDelegate = delegate; |
|
|
|
current.$storeDelegate = delegate; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return current.$storeDelegate; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function useContext(inject) { |
|
|
|
export function useContext(inject) { |
|
|
|
// 通过组件找最近的store
|
|
|
|
// 通过组件找最近的store
|
|
|
|
const vm = Widget.findStore(Widget.current || Widget.context); |
|
|
|
let vm = Widget.findStore(Widget.current || Widget.context); |
|
|
|
if (vm) { |
|
|
|
if (vm) { |
|
|
|
if (inject) { |
|
|
|
if (inject) { |
|
|
|
if (vm.$$computed && inject in vm.$$computed) { |
|
|
|
if (vm.$$computed && inject in vm.$$computed) { |
|
|
@ -928,9 +942,11 @@ export function useContext(inject) { |
|
|
|
} |
|
|
|
} |
|
|
|
vm = vm._parent; |
|
|
|
vm = vm._parent; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return vm; |
|
|
|
return vm; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -949,18 +965,19 @@ export function watch(vm, watch, handler) { |
|
|
|
if (isArray(handler)) { |
|
|
|
if (isArray(handler)) { |
|
|
|
for (let i = 0; i < handler.length; i++) { |
|
|
|
for (let i = 0; i < handler.length; i++) { |
|
|
|
watchers.push(Fix.watch(vm.model, key, innerHandler, { |
|
|
|
watchers.push(Fix.watch(vm.model, key, innerHandler, { |
|
|
|
store: vm |
|
|
|
store: vm, |
|
|
|
})); |
|
|
|
})); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
watchers.push(Fix.watch(vm.model, key, innerHandler, { |
|
|
|
watchers.push(Fix.watch(vm.model, key, innerHandler, { |
|
|
|
store: vm |
|
|
|
store: vm, |
|
|
|
})); |
|
|
|
})); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
// vm中一定有_widget
|
|
|
|
// vm中一定有_widget
|
|
|
|
Widget.current._watchers || (Widget.current._watchers = []); |
|
|
|
Widget.current._watchers || (Widget.current._watchers = []); |
|
|
|
Widget.current._watchers = Widget.current._watchers.concat(watchers); |
|
|
|
Widget.current._watchers = Widget.current._watchers.concat(watchers); |
|
|
|
|
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
handler = watch; |
|
|
|
handler = watch; |
|
|
@ -974,6 +991,7 @@ export function onBeforeMount(beforeMount) { |
|
|
|
if (current) { |
|
|
|
if (current) { |
|
|
|
if (current.__isMounting) { |
|
|
|
if (current.__isMounting) { |
|
|
|
beforeMount(); |
|
|
|
beforeMount(); |
|
|
|
|
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
if (!current.beforeMount) { |
|
|
|
if (!current.beforeMount) { |
|
|
@ -989,6 +1007,7 @@ export function onMounted(mounted) { |
|
|
|
if (current) { |
|
|
|
if (current) { |
|
|
|
if (current._isMounted && !this.__async) { |
|
|
|
if (current._isMounted && !this.__async) { |
|
|
|
mounted(); |
|
|
|
mounted(); |
|
|
|
|
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
if (!current.mounted) { |
|
|
|
if (!current.mounted) { |
|
|
@ -998,7 +1017,7 @@ export function onMounted(mounted) { |
|
|
|
} |
|
|
|
} |
|
|
|
current.mounted.push(mounted); |
|
|
|
current.mounted.push(mounted); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function onBeforeUnmount(beforeDestroy) { |
|
|
|
export function onBeforeUnmount(beforeDestroy) { |
|
|
|
if (current) { |
|
|
|
if (current) { |
|
|
@ -1026,7 +1045,7 @@ Widget.registerRenderEngine = function (engine) { |
|
|
|
Widget._renderEngine = engine; |
|
|
|
Widget._renderEngine = engine; |
|
|
|
}; |
|
|
|
}; |
|
|
|
Widget.registerRenderEngine({ |
|
|
|
Widget.registerRenderEngine({ |
|
|
|
createElement: function (widget) { |
|
|
|
createElement (widget) { |
|
|
|
if (isWidget(widget)) { |
|
|
|
if (isWidget(widget)) { |
|
|
|
const o = widget.options; |
|
|
|
const o = widget.options; |
|
|
|
if (o.element) { |
|
|
|
if (o.element) { |
|
|
@ -1035,13 +1054,15 @@ Widget.registerRenderEngine({ |
|
|
|
if (o.tagName) { |
|
|
|
if (o.tagName) { |
|
|
|
return BI.$(document.createElement(o.tagName)); |
|
|
|
return BI.$(document.createElement(o.tagName)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return BI.$(document.createDocumentFragment()); |
|
|
|
return BI.$(document.createDocumentFragment()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return BI.$(widget); |
|
|
|
return BI.$(widget); |
|
|
|
}, |
|
|
|
}, |
|
|
|
createFragment: function () { |
|
|
|
createFragment () { |
|
|
|
return document.createDocumentFragment(); |
|
|
|
return document.createDocumentFragment(); |
|
|
|
} |
|
|
|
}, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
export function mount(widget, container, predicate, hydrate) { |
|
|
|
export function mount(widget, container, predicate, hydrate) { |
|
|
@ -1049,8 +1070,8 @@ export function mount(widget, container, predicate, hydrate) { |
|
|
|
// 将widget的element元素都挂载好,并建立相互关系
|
|
|
|
// 将widget的element元素都挂载好,并建立相互关系
|
|
|
|
widget.element.data("__widgets", [widget]); |
|
|
|
widget.element.data("__widgets", [widget]); |
|
|
|
const res = widget._mount(true, false, false, function (w) { |
|
|
|
const res = widget._mount(true, false, false, function (w) { |
|
|
|
each(w._children, function (i, child) { |
|
|
|
each(w._children, (i, child) => { |
|
|
|
const ws = child.element.data("__widgets"); |
|
|
|
let ws = child.element.data("__widgets"); |
|
|
|
if (!ws) { |
|
|
|
if (!ws) { |
|
|
|
ws = []; |
|
|
|
ws = []; |
|
|
|
} |
|
|
|
} |
|
|
@ -1063,19 +1084,21 @@ export function mount(widget, container, predicate, hydrate) { |
|
|
|
const c = Widget._renderEngine.createElement; |
|
|
|
const c = Widget._renderEngine.createElement; |
|
|
|
BI.DOM.patchProps(widget.element, c(c(container).children()[0])); |
|
|
|
BI.DOM.patchProps(widget.element, c(c(container).children()[0])); |
|
|
|
|
|
|
|
|
|
|
|
const triggerLifeHook = function (w) { |
|
|
|
const triggerLifeHook = w => { |
|
|
|
w.beforeMount && w.beforeMount(); |
|
|
|
w.beforeMount && w.beforeMount(); |
|
|
|
w.mounted && w.mounted(); |
|
|
|
w.mounted && w.mounted(); |
|
|
|
each(w._children, function (i, child) { |
|
|
|
each(w._children, (i, child) => { |
|
|
|
triggerLifeHook(child); |
|
|
|
triggerLifeHook(child); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}; |
|
|
|
}; |
|
|
|
// 最后触发组件树生命周期函数
|
|
|
|
// 最后触发组件树生命周期函数
|
|
|
|
triggerLifeHook(widget); |
|
|
|
triggerLifeHook(widget); |
|
|
|
|
|
|
|
|
|
|
|
return res; |
|
|
|
return res; |
|
|
|
} |
|
|
|
} |
|
|
|
if (container) { |
|
|
|
if (container) { |
|
|
|
Widget._renderEngine.createElement(container).append(widget.element); |
|
|
|
Widget._renderEngine.createElement(container).append(widget.element); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return widget._mount(true, false, false, predicate); |
|
|
|
return widget._mount(true, false, false, predicate); |
|
|
|
} |
|
|
|
} |
|
|
|