fix: 🐛 support register html render object

This commit is contained in:
vector
2021-01-25 14:50:34 +08:00
parent 59df3dad0c
commit c1813adc5e
3 changed files with 18 additions and 6 deletions

View File

@ -722,9 +722,13 @@ export class Hook extends Base implements Hook.IHook {
@Decorator.hook()
shouldUpdateHTMLComponent(node: HTML): boolean {
const html = node.getHTML()
let html = node.getHTML()
if (html && typeof html === 'object') {
if (typeof html === 'string') {
html = HTML.componentRegistry.get(html) || html
}
if (ObjectExt.isPlainObject(html)) {
const shouldUpdate = (html as HTML.UpdatableComponent)
.shouldComponentUpdate

View File

@ -150,7 +150,9 @@ export namespace HTML {
shouldComponentUpdate: boolean | ((this: Graph, node: HTML) => boolean)
}
export const componentRegistry = Registry.create<Component>({
export const componentRegistry = Registry.create<
Component | UpdatableComponent
>({
type: 'html componnet',
})
}

View File

@ -34,12 +34,18 @@ const isNativeClass =
* Extends class with specified class name.
*/
export function createClass<T>(className: string, base: Function): T {
// tslint:disable-next-line
let cls
if (isNativeClass) {
cls = new Function('base',`return class ${className} extends base { }`)(base)
// tslint:disable-next-line
cls = new Function('base', `return class ${className} extends base { }`)(
base,
)
} else {
cls = new Function('base',`return function ${className}() { return base.apply(this, arguments) }`)(base)
// tslint:disable-next-line
cls = new Function(
'base',
`return function ${className}() { return base.apply(this, arguments) }`,
)(base)
inherit(cls, base)
}