[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:
Géry Debongnie
2019-11-14 14:09:42 +01:00
parent e5940b4b6b
commit 56087b95cd
8 changed files with 33 additions and 34 deletions
+16 -1
View File
@@ -328,8 +328,23 @@ export class Component<T extends Env, Props extends {}> {
if (__owl__.currentFiber && !__owl__.currentFiber.isRendered) {
return scheduler.addFiber(__owl__.currentFiber.root);
}
// if we aren't mounted at this point, it implies that there is a
// currentFiber that is already rendered (isRendered is true), so we are
// about to be mounted
const isMounted = __owl__.isMounted;
const fiber = new Fiber(null, this, undefined, undefined, force, null);
this.__render(fiber);
Promise.resolve().then(() => {
if (__owl__.isMounted || !isMounted) {
// we are mounted (__owl__.isMounted), or if we are currently being
// mounted (!isMounted), so we call __render
this.__render(fiber);
} else {
// we were mounted when render was called, but we aren't anymore, so we
// were actually about to be unmounted ; we can thus forget about this
// fiber
__owl__.currentFiber = null;
}
});
return scheduler.addFiber(fiber);
}