mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[REF] observer: notify subscribers directly
This rev. moves the logic of batching the notifications of changes occurring in the same microtask tick, from the observer, to the listeners (the context, and the render function of components). By doing so in render, we ensure that similar renderings are batched in a single one, wherever they come from (state change, store change, direct call...).
This commit is contained in:
+1
-11
@@ -24,19 +24,9 @@ import { Observer } from "./core/observer";
|
||||
export function useState<T>(state: T): T {
|
||||
const component: Component<any, any> = Component.current!;
|
||||
const __owl__ = component.__owl__;
|
||||
const renderFn = __owl__.renderFn;
|
||||
let lastRenderRevNumber;
|
||||
__owl__.renderFn = function(comp, params) {
|
||||
lastRenderRevNumber = __owl__.observer!.rev;
|
||||
return renderFn(comp, params);
|
||||
};
|
||||
if (!__owl__.observer) {
|
||||
__owl__.observer = new Observer();
|
||||
__owl__.observer.notifyCB = () => {
|
||||
if (lastRenderRevNumber < __owl__.observer!.rev) {
|
||||
component.render();
|
||||
}
|
||||
};
|
||||
__owl__.observer.notifyCB = component.render.bind(component);
|
||||
}
|
||||
return __owl__.observer.observe(state);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user