mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[IMP] app: small scale perf improvement
This commit is contained in:
committed by
Sam Degueldre
parent
0e6059467f
commit
d046913a01
+9
-15
@@ -130,29 +130,23 @@ export class App<
|
||||
return hasDynamicPropList && Object.keys(props1).length !== Object.keys(props2).length;
|
||||
}
|
||||
const arePropsDifferent = hasSlotsProp ? () => true : _arePropsDifferent;
|
||||
const updateAndRender = ComponentNode.prototype.updateAndRender;
|
||||
const initiateRender = ComponentNode.prototype.initiateRender;
|
||||
|
||||
return (props: P, key: string, ctx: ComponentNode, parent: any, C: any) => {
|
||||
let children = ctx.children;
|
||||
let node: any = children[key];
|
||||
|
||||
if (node && node.status === STATUS.DESTROYED) {
|
||||
if (
|
||||
node &&
|
||||
(node.status === STATUS.DESTROYED || (isDynamic && node.component.constructor !== C))
|
||||
) {
|
||||
node = undefined;
|
||||
}
|
||||
if (isDynamic && node && node.component.constructor !== C) {
|
||||
node = undefined;
|
||||
}
|
||||
|
||||
const parentFiber = ctx.fiber!;
|
||||
if (node) {
|
||||
let shouldRender = node.forceNextRender;
|
||||
if (shouldRender) {
|
||||
if (arePropsDifferent(node.props, props) || parentFiber.deep || node.forceNextRender) {
|
||||
node.forceNextRender = false;
|
||||
} else {
|
||||
const currentProps = node.props;
|
||||
shouldRender = parentFiber.deep || arePropsDifferent(currentProps, props);
|
||||
}
|
||||
if (shouldRender) {
|
||||
node.updateAndRender(props, parentFiber);
|
||||
updateAndRender.call(node, props, parentFiber);
|
||||
}
|
||||
} else {
|
||||
// new component
|
||||
@@ -168,7 +162,7 @@ export class App<
|
||||
}
|
||||
node = new ComponentNode(C, props, this, ctx, key);
|
||||
children[key] = node;
|
||||
node.initiateRender(new Fiber(node, parentFiber));
|
||||
initiateRender.call(node, new Fiber(node, parentFiber));
|
||||
}
|
||||
parentFiber.childrenMap[key] = node;
|
||||
return node;
|
||||
|
||||
@@ -321,10 +321,15 @@ export class ComponentNode<P extends Props = any, E = any> implements VNode<Comp
|
||||
}
|
||||
}
|
||||
_patch() {
|
||||
const hasChildren = Object.keys(this.children).length > 0;
|
||||
this.children = this.fiber!.childrenMap;
|
||||
this.bdom!.patch(this!.fiber!.bdom!, hasChildren);
|
||||
this.fiber!.appliedToDom = true;
|
||||
let hasChildren = false;
|
||||
for (let _k in this.children) {
|
||||
hasChildren = true;
|
||||
break;
|
||||
}
|
||||
const fiber = this.fiber!;
|
||||
this.children = fiber.childrenMap;
|
||||
this.bdom!.patch(fiber.bdom!, hasChildren);
|
||||
fiber.appliedToDom = true;
|
||||
this.fiber = null;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import { isOptional, validateSchema } from "./validation";
|
||||
import type { ComponentConstructor } from "./component";
|
||||
import { markRaw } from "./reactivity";
|
||||
|
||||
const ObjectCreate = Object.create;
|
||||
/**
|
||||
* This file contains utility functions that will be injected in each template,
|
||||
* to perform various useful tasks in the compiled code.
|
||||
@@ -26,7 +27,7 @@ function callSlot(
|
||||
key = key + "__slot_" + name;
|
||||
const slots = ctx.props.slots || {};
|
||||
const { __render, __ctx, __scope } = slots[name] || {};
|
||||
const slotScope = Object.create(__ctx || {});
|
||||
const slotScope = ObjectCreate(__ctx || {});
|
||||
if (__scope) {
|
||||
slotScope[__scope] = extra;
|
||||
}
|
||||
@@ -46,7 +47,7 @@ function callSlot(
|
||||
|
||||
function capture(ctx: any): any {
|
||||
const component = ctx.__owl__.component;
|
||||
const result = Object.create(component);
|
||||
const result = ObjectCreate(component);
|
||||
for (let k in ctx) {
|
||||
result[k] = ctx[k];
|
||||
}
|
||||
@@ -161,18 +162,20 @@ export function safeOutput(value: any): ReturnType<typeof toggler> {
|
||||
}
|
||||
|
||||
let boundFunctions = new WeakMap();
|
||||
const WeakMapGet = WeakMap.prototype.get;
|
||||
const WeakMapSet = WeakMap.prototype.set;
|
||||
|
||||
function bind(ctx: any, fn: Function): Function {
|
||||
let component = ctx.__owl__.component;
|
||||
let boundFnMap = boundFunctions.get(component);
|
||||
let boundFnMap = WeakMapGet.call(boundFunctions, component);
|
||||
if (!boundFnMap) {
|
||||
boundFnMap = new WeakMap();
|
||||
boundFunctions.set(component, boundFnMap);
|
||||
WeakMapSet.call(boundFunctions, component, boundFnMap);
|
||||
}
|
||||
let boundFn = boundFnMap.get(fn);
|
||||
let boundFn = WeakMapGet.call(boundFnMap, fn);
|
||||
if (!boundFn) {
|
||||
boundFn = fn.bind(component);
|
||||
boundFnMap.set(fn, boundFn);
|
||||
WeakMapSet.call(boundFnMap, fn, boundFn);
|
||||
}
|
||||
return boundFn;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user