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