mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[REM] remove the Memo component
With the new fine grained reactivity system, it was no longer useful.
This commit is contained in:
committed by
Samuel Degueldre
parent
8a472231cf
commit
2a1b99be2d
@@ -42,7 +42,6 @@ export { App, mount } from "./app/app";
|
||||
export { Component } from "./component/component";
|
||||
export { useComponent, useState } from "./component/component_node";
|
||||
export { status } from "./component/status";
|
||||
export { Memo } from "./memo";
|
||||
export { xml } from "./app/template_set";
|
||||
export { reactive, markRaw, toRaw } from "./reactivity";
|
||||
export { useEffect, useEnv, useExternalListener, useRef, useChildSubEnv, useSubEnv } from "./hooks";
|
||||
|
||||
-47
@@ -1,47 +0,0 @@
|
||||
import { Component } from "./component/component";
|
||||
import type { ComponentNode } from "./component/component_node";
|
||||
import { xml } from "./app/template_set";
|
||||
import { Fiber } from "./component/fibers";
|
||||
|
||||
export class Memo extends Component {
|
||||
static template = xml`<t t-slot="default"/>`;
|
||||
|
||||
constructor(props: any, env: any, node: ComponentNode) {
|
||||
super(props, env, node);
|
||||
|
||||
// prevent patching process conditionally
|
||||
let applyPatch = false;
|
||||
const patchFn = node.patch;
|
||||
node.patch = () => {
|
||||
if (applyPatch) {
|
||||
patchFn.call(node);
|
||||
applyPatch = false;
|
||||
}
|
||||
};
|
||||
|
||||
// check props change, and render/apply patch if it changed
|
||||
let prevProps = props;
|
||||
const updateAndRender = node.updateAndRender;
|
||||
node.updateAndRender = function (props: any, parentFiber: Fiber) {
|
||||
const shouldUpdate = !shallowEqual(prevProps, props);
|
||||
if (shouldUpdate) {
|
||||
prevProps = props;
|
||||
updateAndRender.call(node, props, parentFiber);
|
||||
applyPatch = true;
|
||||
}
|
||||
return Promise.resolve();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* we assume that each object have the same set of keys
|
||||
*/
|
||||
function shallowEqual(p1: any, p2: any): boolean {
|
||||
for (let k in p1) {
|
||||
if (k !== "slots" && p1[k] !== p2[k]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user