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:
+10
-1
@@ -45,7 +45,16 @@ export class Context extends EventBus {
|
||||
constructor(state: Object = {}) {
|
||||
super();
|
||||
this.observer = new Observer();
|
||||
this.observer.notifyCB = this.__notifyComponents.bind(this);
|
||||
this.observer.notifyCB = () => {
|
||||
// notify components in the next microtask tick to ensure that subscribers
|
||||
// are notified only once for all changes that occur in the same micro tick
|
||||
let rev = this.rev;
|
||||
return Promise.resolve().then(() => {
|
||||
if (rev === this.rev) {
|
||||
this.__notifyComponents();
|
||||
}
|
||||
});
|
||||
};
|
||||
this.state = this.observer.observe(state);
|
||||
this.subscriptions.update = [];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user