mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[REF] component: make observer and state optional
This commit is contained in:
+9
-5
@@ -35,7 +35,7 @@ export interface Meta<T extends Env, Props> {
|
|||||||
renderProps: Props | null;
|
renderProps: Props | null;
|
||||||
renderPromise: Promise<VNode> | null;
|
renderPromise: Promise<VNode> | null;
|
||||||
boundHandlers: { [key: number]: any };
|
boundHandlers: { [key: number]: any };
|
||||||
observer: Observer;
|
observer?: Observer;
|
||||||
}
|
}
|
||||||
|
|
||||||
const patch = init([sdListeners, sdAttrs, sdProps]);
|
const patch = init([sdListeners, sdAttrs, sdProps]);
|
||||||
@@ -62,7 +62,7 @@ export class Component<
|
|||||||
}
|
}
|
||||||
|
|
||||||
env: T;
|
env: T;
|
||||||
state: State = <State>{};
|
state?: State;
|
||||||
props: Props;
|
props: Props;
|
||||||
refs: {
|
refs: {
|
||||||
[key: string]: Component<T, any, any> | HTMLElement | undefined;
|
[key: string]: Component<T, any, any> | HTMLElement | undefined;
|
||||||
@@ -120,8 +120,7 @@ export class Component<
|
|||||||
renderId: 1,
|
renderId: 1,
|
||||||
renderPromise: null,
|
renderPromise: null,
|
||||||
renderProps: props || null,
|
renderProps: props || null,
|
||||||
boundHandlers: {},
|
boundHandlers: {}
|
||||||
observer: new Observer()
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -366,13 +365,17 @@ export class Component<
|
|||||||
this.__owl__.renderId++;
|
this.__owl__.renderId++;
|
||||||
const promises: Promise<void>[] = [];
|
const promises: Promise<void>[] = [];
|
||||||
const template = this.inlineTemplate || this.template;
|
const template = this.inlineTemplate || this.template;
|
||||||
|
if (this.__owl__.observer) {
|
||||||
this.__owl__.observer.allowMutations = false;
|
this.__owl__.observer.allowMutations = false;
|
||||||
|
}
|
||||||
let vnode = this.env.qweb.render(template, this, {
|
let vnode = this.env.qweb.render(template, this, {
|
||||||
promises,
|
promises,
|
||||||
handlers: this.__owl__.boundHandlers,
|
handlers: this.__owl__.boundHandlers,
|
||||||
forceUpdate: force
|
forceUpdate: force
|
||||||
});
|
});
|
||||||
|
if (this.__owl__.observer) {
|
||||||
this.__owl__.observer.allowMutations = true;
|
this.__owl__.observer.allowMutations = true;
|
||||||
|
}
|
||||||
|
|
||||||
// this part is critical for the patching process to be done correctly. The
|
// this part is critical for the patching process to be done correctly. The
|
||||||
// tricky part is that a child widget can be rerendered on its own, which
|
// tricky part is that a child widget can be rerendered on its own, which
|
||||||
@@ -422,7 +425,8 @@ export class Component<
|
|||||||
}
|
}
|
||||||
|
|
||||||
_observeState() {
|
_observeState() {
|
||||||
if (Object.keys(this.state).length) {
|
if (this.state) {
|
||||||
|
this.__owl__.observer = new Observer();
|
||||||
this.__owl__.observer.observe(this.state);
|
this.__owl__.observer.observe(this.state);
|
||||||
this.__owl__.observer.notifyCB = this.render.bind(this);
|
this.__owl__.observer.notifyCB = this.render.bind(this);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ describe("basic widget properties", () => {
|
|||||||
test("props and state are properly defined", async () => {
|
test("props and state are properly defined", async () => {
|
||||||
const widget = new Widget(env);
|
const widget = new Widget(env);
|
||||||
expect(widget.props).toEqual({});
|
expect(widget.props).toEqual({});
|
||||||
expect(widget.state).toEqual({});
|
expect(widget.state).toEqual(undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("has no el after creation", async () => {
|
test("has no el after creation", async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user