|
|
|
@ -8,6 +8,7 @@
|
|
|
|
|
|
|
|
|
|
import { isFunction, isArray, each, extend, isPlainObject, isNull, uniqueId, isWidget, isWidthOrHeight, isKey, remove, any, isNotNull } from "./2.base"; |
|
|
|
|
import OB from "./3.ob"; |
|
|
|
|
import { Providers, _lazyCreateWidget } from "./5.inject"; |
|
|
|
|
|
|
|
|
|
const cancelAnimationFrame = |
|
|
|
|
_global.cancelAnimationFrame || |
|
|
|
@ -360,7 +361,7 @@ export default class Widget extends OB {
|
|
|
|
|
_initElement() { |
|
|
|
|
this.__isMounting = true; |
|
|
|
|
// 当开启worker模式时,可以通过$render来实现另一种效果
|
|
|
|
|
const workerMode = BI.Providers.getProvider("bi.provider.system").getWorkerMode(); |
|
|
|
|
const workerMode = Providers.getProvider("bi.provider.system").getWorkerMode(); |
|
|
|
|
const render = isFunction(this.options.render) ? this.options.render : (workerMode ? (this.$render || this.render) : this.render); |
|
|
|
|
let els = render && render.call(this); |
|
|
|
|
els = this.options.configRender ? this.options.configRender.call(this, els) : els; |
|
|
|
@ -372,7 +373,7 @@ export default class Widget extends OB {
|
|
|
|
|
if (isArray(els)) { |
|
|
|
|
each(els, (i, el) => { |
|
|
|
|
if (el) { |
|
|
|
|
BI._lazyCreateWidget(el, { |
|
|
|
|
_lazyCreateWidget(el, { |
|
|
|
|
element: this |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
@ -840,9 +841,6 @@ export default class Widget extends OB {
|
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
extend(BI, { Widget }); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let context = null, current = null; |
|
|
|
|
const contextStack = [], currentStack = []; |
|
|
|
|
|
|
|
|
@ -875,7 +873,7 @@ function popTarget() {
|
|
|
|
|
Widget.current = current = currentStack.pop(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
BI.useStore = function (_store) { |
|
|
|
|
export function useStore(_store) { |
|
|
|
|
if (current && current.store) { |
|
|
|
|
return current.store; |
|
|
|
|
} |
|
|
|
@ -908,9 +906,9 @@ BI.useStore = function (_store) {
|
|
|
|
|
}; |
|
|
|
|
return current.$storeDelegate = delegate; |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
BI.useContext = function (inject) { |
|
|
|
|
export function useContext(inject) { |
|
|
|
|
// 通过组件找最近的store
|
|
|
|
|
const vm = Widget.findStore(Widget.current || Widget.context); |
|
|
|
|
if (vm) { |
|
|
|
@ -934,9 +932,9 @@ BI.useContext = function (inject) {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return vm; |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
BI.watch = function (vm, watch, handler) { |
|
|
|
|
export function watch(vm, watch, handler) { |
|
|
|
|
// 必须要保证组件当前环境存在
|
|
|
|
|
if (Widget.current) { |
|
|
|
|
if (vm instanceof BI.Model) { |
|
|
|
@ -970,9 +968,9 @@ BI.watch = function (vm, watch, handler) {
|
|
|
|
|
Widget.current.$watchDelayCallbacks || (Widget.current.$watchDelayCallbacks = []); |
|
|
|
|
Widget.current.$watchDelayCallbacks.push([watch, handler]); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
BI.onBeforeMount = function (beforeMount) { |
|
|
|
|
export function onBeforeMount(beforeMount) { |
|
|
|
|
if (current) { |
|
|
|
|
if (current.__isMounting) { |
|
|
|
|
beforeMount(); |
|
|
|
@ -985,8 +983,9 @@ BI.onBeforeMount = function (beforeMount) {
|
|
|
|
|
} |
|
|
|
|
current.beforeMount.push(beforeMount); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
BI.onMounted = function (mounted) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function onMounted(mounted) { |
|
|
|
|
if (current) { |
|
|
|
|
if (current._isMounted && !this.__async) { |
|
|
|
|
mounted(); |
|
|
|
@ -1000,7 +999,8 @@ BI.onMounted = function (mounted) {
|
|
|
|
|
current.mounted.push(mounted); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
BI.onBeforeUnmount = function (beforeDestroy) { |
|
|
|
|
|
|
|
|
|
export function onBeforeUnmount(beforeDestroy) { |
|
|
|
|
if (current) { |
|
|
|
|
if (!current.beforeDestroy) { |
|
|
|
|
current.beforeDestroy = []; |
|
|
|
@ -1009,8 +1009,9 @@ BI.onBeforeUnmount = function (beforeDestroy) {
|
|
|
|
|
} |
|
|
|
|
current.beforeDestroy.push(beforeDestroy); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
BI.onUnmounted = function (destroyed) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function onUnmounted(destroyed) { |
|
|
|
|
if (current) { |
|
|
|
|
if (!current.destroyed) { |
|
|
|
|
current.destroyed = []; |
|
|
|
@ -1019,7 +1020,7 @@ BI.onUnmounted = function (destroyed) {
|
|
|
|
|
} |
|
|
|
|
current.destroyed.push(destroyed); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Widget.registerRenderEngine = function (engine) { |
|
|
|
|
Widget._renderEngine = engine; |
|
|
|
@ -1043,7 +1044,7 @@ Widget.registerRenderEngine({
|
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
BI.mount = function (widget, container, predicate, hydrate) { |
|
|
|
|
export function mount(widget, container, predicate, hydrate) { |
|
|
|
|
if (hydrate === true) { |
|
|
|
|
// 将widget的element元素都挂载好,并建立相互关系
|
|
|
|
|
widget.element.data("__widgets", [widget]); |
|
|
|
@ -1077,4 +1078,16 @@ BI.mount = function (widget, container, predicate, hydrate) {
|
|
|
|
|
Widget._renderEngine.createElement(container).append(widget.element); |
|
|
|
|
} |
|
|
|
|
return widget._mount(true, false, false, predicate); |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
extend(BI, { |
|
|
|
|
Widget, |
|
|
|
|
useStore, |
|
|
|
|
useContext, |
|
|
|
|
watch, |
|
|
|
|
onBeforeMount, |
|
|
|
|
onMounted, |
|
|
|
|
onBeforeUnmount, |
|
|
|
|
onUnmounted, |
|
|
|
|
mount, |
|
|
|
|
}); |
|
|
|
|