mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| bf7730a34a | |||
| a968bb7ab5 | |||
| 4cd1df46b3 | |||
| 989b0d6709 | |||
| 9b93521da4 | |||
| de240b1ebc | |||
| 55dbc01a1b | |||
| e3b1566943 | |||
| 828be28653 | |||
| d80fad760c | |||
| 7611ea6033 | |||
| c7d515a6b3 | |||
| d277039b14 |
@@ -240,7 +240,7 @@ class Task extends Component {
|
|||||||
static template = xml /* xml */`
|
static template = xml /* xml */`
|
||||||
<div class="task" t-att-class="props.task.isCompleted ? 'done' : ''">
|
<div class="task" t-att-class="props.task.isCompleted ? 'done' : ''">
|
||||||
<input type="checkbox" t-att-checked="props.task.isCompleted"/>
|
<input type="checkbox" t-att-checked="props.task.isCompleted"/>
|
||||||
<span><t t-esc="props.task.title"/></span>
|
<span><t t-esc="props.task.text"/></span>
|
||||||
</div>`;
|
</div>`;
|
||||||
static props = ["task"];
|
static props = ["task"];
|
||||||
}
|
}
|
||||||
@@ -743,7 +743,7 @@ the user experience.
|
|||||||
```xml
|
```xml
|
||||||
<input type="checkbox" t-att-checked="props.task.isCompleted"
|
<input type="checkbox" t-att-checked="props.task.isCompleted"
|
||||||
t-att-id="props.task.id"
|
t-att-id="props.task.id"
|
||||||
t-on-click="dispatch('toggleTask', props.task.id)"/>
|
t-on-click="() => store.toggleTask(props.task)"/>
|
||||||
<label t-att-for="props.task.id"><t t-esc="props.task.text"/></label>
|
<label t-att-for="props.task.id"><t t-esc="props.task.text"/></label>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@odoo/owl",
|
"name": "@odoo/owl",
|
||||||
"version": "2.0.0-beta.3",
|
"version": "2.0.0-beta-4",
|
||||||
"description": "Odoo Web Library (OWL)",
|
"description": "Odoo Web Library (OWL)",
|
||||||
"main": "dist/owl.cjs.js",
|
"main": "dist/owl.cjs.js",
|
||||||
"browser": "dist/owl.iife.js",
|
"browser": "dist/owl.iife.js",
|
||||||
|
|||||||
@@ -101,6 +101,7 @@ export class App<
|
|||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
if (this.root) {
|
if (this.root) {
|
||||||
|
this.scheduler.flush();
|
||||||
this.root.destroy();
|
this.root.destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -139,7 +139,8 @@ export function updateClass(this: HTMLElement, val: any, oldVal: any) {
|
|||||||
|
|
||||||
export function makePropSetter(name: string): Setter<HTMLElement> {
|
export function makePropSetter(name: string): Setter<HTMLElement> {
|
||||||
return function setProp(this: HTMLElement, value: any) {
|
return function setProp(this: HTMLElement, value: any) {
|
||||||
(this as any)[name] = value || "";
|
// support 0, fallback to empty string for other falsy values
|
||||||
|
(this as any)[name] = value === 0 ? 0 : value || "";
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1115,8 +1115,11 @@ export class CodeGenerator {
|
|||||||
let slotStr: string[] = [];
|
let slotStr: string[] = [];
|
||||||
for (let slotName in ast.slots) {
|
for (let slotName in ast.slots) {
|
||||||
const slotAst = ast.slots[slotName];
|
const slotAst = ast.slots[slotName];
|
||||||
|
const params = [];
|
||||||
|
if (slotAst.content) {
|
||||||
const name = this.compileInNewTarget("slot", slotAst.content, ctx, slotAst.on);
|
const name = this.compileInNewTarget("slot", slotAst.content, ctx, slotAst.on);
|
||||||
const params = [`__render: ${name}, __ctx: ${ctxStr}`];
|
params.push(`__render: ${name}, __ctx: ${ctxStr}`);
|
||||||
|
}
|
||||||
const scope = ast.slots[slotName].scope;
|
const scope = ast.slots[slotName].scope;
|
||||||
if (scope) {
|
if (scope) {
|
||||||
params.push(`__scope: "${scope}"`);
|
params.push(`__scope: "${scope}"`);
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ export interface ASTTCall {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface SlotDefinition {
|
interface SlotDefinition {
|
||||||
content: AST;
|
content: AST | null;
|
||||||
scope: string | null;
|
scope: string | null;
|
||||||
on: EventHandlers | null;
|
on: EventHandlers | null;
|
||||||
attrs: Attrs | null;
|
attrs: Attrs | null;
|
||||||
@@ -749,7 +749,6 @@ function parseComponent(node: Element, ctx: ParsingContext): AST | null {
|
|||||||
slotNode.removeAttribute("t-set-slot");
|
slotNode.removeAttribute("t-set-slot");
|
||||||
slotNode.remove();
|
slotNode.remove();
|
||||||
const slotAst = parseNode(slotNode, ctx);
|
const slotAst = parseNode(slotNode, ctx);
|
||||||
if (slotAst) {
|
|
||||||
let on: SlotDefinition["on"] = null;
|
let on: SlotDefinition["on"] = null;
|
||||||
let attrs: Attrs | null = null;
|
let attrs: Attrs | null = null;
|
||||||
let scope: string | null = null;
|
let scope: string | null = null;
|
||||||
@@ -769,7 +768,6 @@ function parseComponent(node: Element, ctx: ParsingContext): AST | null {
|
|||||||
slots = slots || {};
|
slots = slots || {};
|
||||||
slots[name] = { content: slotAst, on, attrs, scope };
|
slots[name] = { content: slotAst, on, attrs, scope };
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// default slot
|
// default slot
|
||||||
const defaultContent = parseChildNodes(clone, ctx);
|
const defaultContent = parseChildNodes(clone, ctx);
|
||||||
|
|||||||
@@ -2,23 +2,16 @@ import type { App, Env } from "../app/app";
|
|||||||
import { BDom, VNode } from "../blockdom";
|
import { BDom, VNode } from "../blockdom";
|
||||||
import {
|
import {
|
||||||
clearReactivesForCallback,
|
clearReactivesForCallback,
|
||||||
|
getSubscriptions,
|
||||||
|
NonReactive,
|
||||||
Reactive,
|
Reactive,
|
||||||
reactive,
|
reactive,
|
||||||
TARGET,
|
TARGET,
|
||||||
NonReactive,
|
|
||||||
getSubscriptions,
|
|
||||||
} from "../reactivity";
|
} from "../reactivity";
|
||||||
import { batched, Callback } from "../utils";
|
import { batched, Callback } from "../utils";
|
||||||
import { Component, ComponentConstructor } from "./component";
|
import { Component, ComponentConstructor } from "./component";
|
||||||
import { fibersInError, handleError } from "./error_handling";
|
import { fibersInError, handleError } from "./error_handling";
|
||||||
import {
|
import { Fiber, makeChildFiber, makeRootFiber, MountFiber, MountOptions } from "./fibers";
|
||||||
Fiber,
|
|
||||||
makeChildFiber,
|
|
||||||
makeRootFiber,
|
|
||||||
MountFiber,
|
|
||||||
MountOptions,
|
|
||||||
RootFiber,
|
|
||||||
} from "./fibers";
|
|
||||||
import { applyDefaultProps } from "./props_validation";
|
import { applyDefaultProps } from "./props_validation";
|
||||||
import { STATUS } from "./status";
|
import { STATUS } from "./status";
|
||||||
|
|
||||||
@@ -124,8 +117,9 @@ export function component<P extends object>(
|
|||||||
node = new ComponentNode(C, props, ctx.app, ctx);
|
node = new ComponentNode(C, props, ctx.app, ctx);
|
||||||
ctx.children[key] = node;
|
ctx.children[key] = node;
|
||||||
|
|
||||||
node.initiateRender(new Fiber(node, parentFiber));
|
node.initiateRender(makeChildFiber(node, parentFiber));
|
||||||
}
|
}
|
||||||
|
parentFiber.root!.reachedChildren.add(node);
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,7 +187,7 @@ export class ComponentNode<P extends object = any, E = any> implements VNode<Com
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.status === STATUS.NEW && this.fiber === fiber) {
|
if (this.status === STATUS.NEW && this.fiber === fiber) {
|
||||||
this._render(fiber);
|
fiber.render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,16 +232,7 @@ export class ComponentNode<P extends object = any, E = any> implements VNode<Com
|
|||||||
// embedded in a rendering coming from above, so the fiber will be rendered
|
// embedded in a rendering coming from above, so the fiber will be rendered
|
||||||
// in the next microtick anyway, so we should not render it again.
|
// in the next microtick anyway, so we should not render it again.
|
||||||
if (this.fiber === fiber && (current || !fiber.parent)) {
|
if (this.fiber === fiber && (current || !fiber.parent)) {
|
||||||
this._render(fiber);
|
fiber.render();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_render(fiber: Fiber | RootFiber) {
|
|
||||||
try {
|
|
||||||
fiber.bdom = this.renderFn();
|
|
||||||
fiber.root!.counter--;
|
|
||||||
} catch (e) {
|
|
||||||
handleError({ node: this, error: e });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -291,7 +276,7 @@ export class ComponentNode<P extends object = any, E = any> implements VNode<Com
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
component.props = props;
|
component.props = props;
|
||||||
this._render(fiber);
|
fiber.render();
|
||||||
const parentRoot = parentFiber.root!;
|
const parentRoot = parentFiber.root!;
|
||||||
if (this.willPatch.length) {
|
if (this.willPatch.length) {
|
||||||
parentRoot.willPatch.push(fiber);
|
parentRoot.willPatch.push(fiber);
|
||||||
@@ -349,6 +334,7 @@ export class ComponentNode<P extends object = any, E = any> implements VNode<Com
|
|||||||
}
|
}
|
||||||
|
|
||||||
patch() {
|
patch() {
|
||||||
|
debugger
|
||||||
if (this.fiber && this.fiber.parent) {
|
if (this.fiber && this.fiber.parent) {
|
||||||
// we only patch here renderings coming from above. renderings initiated
|
// we only patch here renderings coming from above. renderings initiated
|
||||||
// by the component will be patched independently in the appropriate
|
// by the component will be patched independently in the appropriate
|
||||||
|
|||||||
@@ -30,7 +30,8 @@ function _handleError(node: ComponentNode | null, error: any, isFirstRound = fal
|
|||||||
|
|
||||||
if (stopped) {
|
if (stopped) {
|
||||||
if (isFirstRound && fiber && fiber.node.fiber) {
|
if (isFirstRound && fiber && fiber.node.fiber) {
|
||||||
fiber.root!.counter--;
|
const root = fiber.root!;
|
||||||
|
root.setCounter(root.counter - 1);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
+117
-24
@@ -1,6 +1,6 @@
|
|||||||
import { BDom, mount } from "../blockdom";
|
import { BDom, mount } from "../blockdom";
|
||||||
import type { ComponentNode } from "./component_node";
|
import type { ComponentNode } from "./component_node";
|
||||||
import { fibersInError, handleError } from "./error_handling";
|
import { handleError } from "./error_handling";
|
||||||
import { STATUS } from "./status";
|
import { STATUS } from "./status";
|
||||||
|
|
||||||
export function makeChildFiber(node: ComponentNode, parent: Fiber): Fiber {
|
export function makeChildFiber(node: ComponentNode, parent: Fiber): Fiber {
|
||||||
@@ -9,24 +9,72 @@ export function makeChildFiber(node: ComponentNode, parent: Fiber): Fiber {
|
|||||||
cancelFibers(current.children);
|
cancelFibers(current.children);
|
||||||
current.root = null;
|
current.root = null;
|
||||||
}
|
}
|
||||||
return new Fiber(node, parent);
|
let fiber = new Fiber(node);
|
||||||
|
fiber.deep = parent.deep;
|
||||||
|
const root = parent.root!;
|
||||||
|
fiber.root = root;
|
||||||
|
parent.children.push(fiber);
|
||||||
|
fiber.parent = parent;
|
||||||
|
root.setCounter(root.counter + 1);
|
||||||
|
return fiber;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function makeRootFiber(node: ComponentNode): Fiber {
|
export function makeRootFiber(node: ComponentNode): Fiber {
|
||||||
let current = node.fiber;
|
let current = node.fiber;
|
||||||
if (current) {
|
if (current) {
|
||||||
let root = current.root!;
|
debugger;
|
||||||
root.counter = root.counter + 1 - cancelFibers(current.children);
|
let parent = current.parent;
|
||||||
current.children = [];
|
let n = cancelFibers(current.children);
|
||||||
current.bdom = null;
|
current.root = null;
|
||||||
if (fibersInError.has(current)) {
|
// current.bdom = null;
|
||||||
fibersInError.delete(current);
|
if (parent) {
|
||||||
fibersInError.delete(root);
|
let fiber = new Fiber(node);
|
||||||
current.appliedToDom = false;
|
fiber.deep = parent.deep;
|
||||||
|
const root = parent.root!;
|
||||||
|
fiber.root = root;
|
||||||
|
let index = parent.children.indexOf(current);
|
||||||
|
parent.children[index] = fiber;
|
||||||
|
// parent.children.push(fiber);
|
||||||
|
fiber.parent = parent;
|
||||||
|
// node.fiber =
|
||||||
|
root.setCounter(root.counter + 1 - n);
|
||||||
|
if (node.willPatch.length) {
|
||||||
|
let index = root.willPatch.indexOf(current);
|
||||||
|
if (index >= 0) {
|
||||||
|
root.willPatch[index] = fiber;
|
||||||
}
|
}
|
||||||
return current;
|
|
||||||
}
|
}
|
||||||
const fiber = new RootFiber(node, null);
|
if (node.patched.length) {
|
||||||
|
let index = root.patched.indexOf(current);
|
||||||
|
if (index >= 0) {
|
||||||
|
root.patched[index] = fiber;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return fiber;
|
||||||
|
}
|
||||||
|
// let parent = current.parent;
|
||||||
|
// let fiber = new Fiber(node);
|
||||||
|
// return fiber;
|
||||||
|
|
||||||
|
// cancelFibers(current.children);
|
||||||
|
// current.root = null;
|
||||||
|
// let root = current.root!;
|
||||||
|
// root.setCounter(root.counter + 1 - cancelFibers(current.children));
|
||||||
|
// current.children = [];
|
||||||
|
// current.bdom = null;
|
||||||
|
// if (current === root) {
|
||||||
|
// root.reachedChildren = new WeakSet();
|
||||||
|
// }
|
||||||
|
// if (fibersInError.has(current)) {
|
||||||
|
// fibersInError.delete(current);
|
||||||
|
// fibersInError.delete(root);
|
||||||
|
// current.appliedToDom = false;
|
||||||
|
// }
|
||||||
|
// return current;
|
||||||
|
}
|
||||||
|
const fiber = new RootFiber(node);
|
||||||
|
fiber.root = fiber;
|
||||||
if (node.willPatch.length) {
|
if (node.willPatch.length) {
|
||||||
fiber.willPatch.push(fiber);
|
fiber.willPatch.push(fiber);
|
||||||
}
|
}
|
||||||
@@ -59,26 +107,60 @@ function cancelFibers(fibers: Fiber[]): number {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
(window as any).fibers = [];
|
||||||
|
|
||||||
export class Fiber {
|
export class Fiber {
|
||||||
node: ComponentNode;
|
node: ComponentNode;
|
||||||
bdom: BDom | null = null;
|
bdom: BDom | null = null;
|
||||||
root: RootFiber | null; // A Fiber that has been replaced by another has no root
|
root: RootFiber | null = null; // A Fiber that has been replaced by another has no root
|
||||||
parent: Fiber | null;
|
parent: Fiber | null = null;
|
||||||
children: Fiber[] = [];
|
children: Fiber[] = [];
|
||||||
appliedToDom = false;
|
appliedToDom = false;
|
||||||
deep: boolean = false;
|
deep: boolean = false;
|
||||||
|
|
||||||
constructor(node: ComponentNode, parent: Fiber | null) {
|
constructor(node: ComponentNode) {
|
||||||
this.node = node;
|
this.node = node;
|
||||||
this.parent = parent;
|
(window as any).fibers.push(this);
|
||||||
if (parent) {
|
}
|
||||||
this.deep = parent.deep;
|
|
||||||
const root = parent.root!;
|
render() {
|
||||||
root.counter++;
|
// if some parent has a fiber => register in followup
|
||||||
this.root = root;
|
let prev = this.root!.node;
|
||||||
parent.children.push(this);
|
let scheduler = prev.app.scheduler;
|
||||||
|
let current = prev.parent;
|
||||||
|
while (current) {
|
||||||
|
if (current.fiber) {
|
||||||
|
let root = current.fiber.root!;
|
||||||
|
if (root.counter) {
|
||||||
|
scheduler.delayedRenders.push(this);
|
||||||
|
return;
|
||||||
} else {
|
} else {
|
||||||
this.root = this as any;
|
if (!root.reachedChildren.has(prev)) {
|
||||||
|
// is dead. but we keep the render around just in case
|
||||||
|
scheduler.delayedRenders.push(this);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
current = root.node;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
prev = current;
|
||||||
|
current = current.parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
// there are no current rendering from above => we can render
|
||||||
|
this._render();
|
||||||
|
}
|
||||||
|
|
||||||
|
_render() {
|
||||||
|
const node = this.node;
|
||||||
|
const root = this.root;
|
||||||
|
if (root) {
|
||||||
|
try {
|
||||||
|
this.bdom = node.renderFn();
|
||||||
|
root.setCounter(root.counter - 1);
|
||||||
|
} catch (e) {
|
||||||
|
handleError({ node, error: e });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -94,6 +176,8 @@ export class RootFiber extends Fiber {
|
|||||||
// i.e.: render triggered in onWillUnmount or in willPatch will be delayed
|
// i.e.: render triggered in onWillUnmount or in willPatch will be delayed
|
||||||
locked: boolean = false;
|
locked: boolean = false;
|
||||||
|
|
||||||
|
reachedChildren: WeakSet<ComponentNode> = new WeakSet();
|
||||||
|
|
||||||
complete() {
|
complete() {
|
||||||
const node = this.node;
|
const node = this.node;
|
||||||
this.locked = true;
|
this.locked = true;
|
||||||
@@ -144,6 +228,14 @@ export class RootFiber extends Fiber {
|
|||||||
handleError({ fiber: current || this, error: e });
|
handleError({ fiber: current || this, error: e });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setCounter(newValue: number) {
|
||||||
|
debugger;
|
||||||
|
this.counter = newValue;
|
||||||
|
if (newValue === 0) {
|
||||||
|
this.node.app.scheduler.flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type Position = "first-child" | "last-child";
|
type Position = "first-child" | "last-child";
|
||||||
@@ -157,8 +249,9 @@ export class MountFiber extends RootFiber {
|
|||||||
position: Position;
|
position: Position;
|
||||||
|
|
||||||
constructor(node: ComponentNode, target: HTMLElement, options: MountOptions = {}) {
|
constructor(node: ComponentNode, target: HTMLElement, options: MountOptions = {}) {
|
||||||
super(node, null);
|
super(node);
|
||||||
this.target = target;
|
this.target = target;
|
||||||
|
this.root = this;
|
||||||
this.position = options.position || "last-child";
|
this.position = options.position || "last-child";
|
||||||
}
|
}
|
||||||
complete() {
|
complete() {
|
||||||
|
|||||||
+26
-27
@@ -11,27 +11,16 @@ export class Scheduler {
|
|||||||
// interactions with other code, such as test frameworks that override them
|
// interactions with other code, such as test frameworks that override them
|
||||||
static requestAnimationFrame = window.requestAnimationFrame.bind(window);
|
static requestAnimationFrame = window.requestAnimationFrame.bind(window);
|
||||||
tasks: Set<RootFiber> = new Set();
|
tasks: Set<RootFiber> = new Set();
|
||||||
isRunning: boolean = false;
|
|
||||||
requestAnimationFrame: Window["requestAnimationFrame"];
|
requestAnimationFrame: Window["requestAnimationFrame"];
|
||||||
|
frame: number = 0;
|
||||||
|
delayedRenders: Fiber[] = [];
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.requestAnimationFrame = Scheduler.requestAnimationFrame;
|
this.requestAnimationFrame = Scheduler.requestAnimationFrame;
|
||||||
}
|
}
|
||||||
|
|
||||||
start() {
|
|
||||||
this.isRunning = true;
|
|
||||||
this.scheduleTasks();
|
|
||||||
}
|
|
||||||
|
|
||||||
stop() {
|
|
||||||
this.isRunning = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
addFiber(fiber: Fiber) {
|
addFiber(fiber: Fiber) {
|
||||||
this.tasks.add(fiber.root!);
|
this.tasks.add(fiber.root!);
|
||||||
if (!this.isRunning) {
|
|
||||||
this.start();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -39,7 +28,30 @@ export class Scheduler {
|
|||||||
* Other tasks are left unchanged.
|
* Other tasks are left unchanged.
|
||||||
*/
|
*/
|
||||||
flush() {
|
flush() {
|
||||||
this.tasks.forEach((fiber) => {
|
if (this.delayedRenders.length) {
|
||||||
|
let renders = this.delayedRenders;
|
||||||
|
this.delayedRenders = [];
|
||||||
|
for (let f of renders) {
|
||||||
|
if (f.root) {
|
||||||
|
f.render();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.frame === 0) {
|
||||||
|
this.frame = this.requestAnimationFrame(() => {
|
||||||
|
this.frame = 0;
|
||||||
|
this.tasks.forEach((fiber) => this.processFiber(fiber));
|
||||||
|
for (let task of this.tasks) {
|
||||||
|
if (task.node.status === STATUS.DESTROYED) {
|
||||||
|
this.tasks.delete(task);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
processFiber(fiber: RootFiber) {
|
||||||
if (fiber.root !== fiber) {
|
if (fiber.root !== fiber) {
|
||||||
this.tasks.delete(fiber);
|
this.tasks.delete(fiber);
|
||||||
return;
|
return;
|
||||||
@@ -60,18 +72,5 @@ export class Scheduler {
|
|||||||
}
|
}
|
||||||
this.tasks.delete(fiber);
|
this.tasks.delete(fiber);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
if (this.tasks.size === 0) {
|
|
||||||
this.stop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
scheduleTasks() {
|
|
||||||
this.requestAnimationFrame(() => {
|
|
||||||
this.flush();
|
|
||||||
if (this.isRunning) {
|
|
||||||
this.scheduleTasks();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -232,6 +232,11 @@ function basicProxyHandler<T extends Target>(callback: Callback): ProxyHandler<T
|
|||||||
if (key === TARGET) {
|
if (key === TARGET) {
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
// non-writable non-configurable properties cannot be made reactive
|
||||||
|
const desc = Object.getOwnPropertyDescriptor(target, key);
|
||||||
|
if (desc && !desc.writable && !desc.configurable) {
|
||||||
|
return Reflect.get(target, key, proxy);
|
||||||
|
}
|
||||||
observeTargetKey(target, key, callback);
|
observeTargetKey(target, key, callback);
|
||||||
return possiblyReactive(Reflect.get(target, key, proxy), callback);
|
return possiblyReactive(Reflect.get(target, key, proxy), callback);
|
||||||
},
|
},
|
||||||
|
|||||||
+6
-4
@@ -15,11 +15,13 @@ export function batched(callback: Callback): Callback {
|
|||||||
await Promise.resolve();
|
await Promise.resolve();
|
||||||
if (!called) {
|
if (!called) {
|
||||||
called = true;
|
called = true;
|
||||||
callback();
|
|
||||||
// wait for all calls in this microtick to fall through before resetting "called"
|
// wait for all calls in this microtick to fall through before resetting "called"
|
||||||
// so that only the first call to the batched function calls the original callback
|
// so that only the first call to the batched function calls the original callback.
|
||||||
await Promise.resolve();
|
// Schedule this before calling the callback so that calls to the batched function
|
||||||
called = false;
|
// within the callback will proceed only after resetting called to false, and have
|
||||||
|
// a chance to execute the callback again
|
||||||
|
Promise.resolve().then(() => (called = false));
|
||||||
|
callback();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -169,13 +169,25 @@ describe("properties", () => {
|
|||||||
expect(input.value).toBe("potato");
|
expect(input.value).toBe("potato");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("input with value attribute, and undefined given", () => {
|
test("input with value attribute, and falsy value given", () => {
|
||||||
const block = createBlock(`<input block-attribute-0="value"/>`);
|
const block = createBlock(`<input block-attribute-0="value"/>`);
|
||||||
|
|
||||||
const tree = block([undefined]);
|
const tree = block([undefined]);
|
||||||
mount(tree, fixture);
|
mount(tree, fixture);
|
||||||
const input = fixture.querySelector("input")!;
|
const input = fixture.querySelector("input")!;
|
||||||
expect(input.value).toBe("");
|
expect(input.value).toBe("");
|
||||||
|
|
||||||
|
patch(tree, block([null]));
|
||||||
|
expect(input.value).toBe("");
|
||||||
|
|
||||||
|
patch(tree, block([0]));
|
||||||
|
expect(input.value).toBe("0");
|
||||||
|
|
||||||
|
patch(tree, block([""]));
|
||||||
|
expect(input.value).toBe("");
|
||||||
|
|
||||||
|
patch(tree, block([false]));
|
||||||
|
expect(input.value).toBe("");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("input type=checkbox with checked attribute", () => {
|
test("input type=checkbox with checked attribute", () => {
|
||||||
|
|||||||
@@ -1370,6 +1370,25 @@ describe("qweb parser", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("a component with an empty named slot", async () => {
|
||||||
|
expect(parse(`<MyComponent><t t-set-slot="mySlot"></t></MyComponent>`)).toEqual({
|
||||||
|
dynamicProps: null,
|
||||||
|
isDynamic: false,
|
||||||
|
name: "MyComponent",
|
||||||
|
on: null,
|
||||||
|
props: null,
|
||||||
|
slots: {
|
||||||
|
mySlot: {
|
||||||
|
attrs: null,
|
||||||
|
content: null,
|
||||||
|
on: null,
|
||||||
|
scope: null,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
type: 11,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test("a component with a named slot", async () => {
|
test("a component with a named slot", async () => {
|
||||||
expect(parse(`<MyComponent><t t-set-slot="name">foo</t></MyComponent>`)).toEqual({
|
expect(parse(`<MyComponent><t t-set-slot="name">foo</t></MyComponent>`)).toEqual({
|
||||||
type: ASTType.TComponent,
|
type: ASTType.TComponent,
|
||||||
|
|||||||
@@ -52,6 +52,50 @@ exports[`Cascading renders after microtaskTick 3`] = `
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`another scenario with delayed rendering 1`] = `
|
||||||
|
"function anonymous(bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
let b2,b3;
|
||||||
|
b2 = text(\`A\`);
|
||||||
|
if (ctx['state'].value<15) {
|
||||||
|
b3 = component(\`B\`, {value: ctx['state'].value}, key + \`__1\`, node, ctx);
|
||||||
|
}
|
||||||
|
return multi([b2, b3]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`another scenario with delayed rendering 2`] = `
|
||||||
|
"function anonymous(bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
const b2 = text(ctx['props'].value);
|
||||||
|
const b3 = component(\`C\`, {}, key + \`__1\`, node, ctx);
|
||||||
|
return multi([b2, b3]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`another scenario with delayed rendering 3`] = `
|
||||||
|
"function anonymous(bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<button block-handler-0=\\"click\\"><block-text-1/></button>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
let hdlr1 = [ctx['increment'], ctx];
|
||||||
|
let txt1 = ctx['state'].val;
|
||||||
|
return block1([hdlr1, txt1]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`async rendering destroying a widget before start is over 1`] = `
|
exports[`async rendering destroying a widget before start is over 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
@@ -1067,6 +1111,184 @@ exports[`delay willUpdateProps with rendering grandchild 4`] = `
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`delayed rendering, but then initial rendering is cancelled by yet another render 1`] = `
|
||||||
|
"function anonymous(bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
return component(\`B\`, {value: ctx['state'].value}, key + \`__1\`, node, ctx);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`delayed rendering, but then initial rendering is cancelled by yet another render 2`] = `
|
||||||
|
"function anonymous(bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
return component(\`C\`, {value: ctx['state'].someValue+ctx['props'].value}, key + \`__1\`, node, ctx);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`delayed rendering, but then initial rendering is cancelled by yet another render 3`] = `
|
||||||
|
"function anonymous(bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
||||||
|
|
||||||
|
let block3 = createBlock(\`<p><block-text-0/></p>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
const b2 = component(\`D\`, {}, key + \`__1\`, node, ctx);
|
||||||
|
let txt1 = ctx['props'].value;
|
||||||
|
const b3 = block3([txt1]);
|
||||||
|
return multi([b2, b3]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`delayed rendering, but then initial rendering is cancelled by yet another render 4`] = `
|
||||||
|
"function anonymous(bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<button block-handler-0=\\"click\\"><block-text-1/></button>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
let hdlr1 = [ctx['increment'], ctx];
|
||||||
|
let txt1 = ctx['state'].val;
|
||||||
|
return block1([hdlr1, txt1]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`delayed rendering, reusing fiber and stuff 1`] = `
|
||||||
|
"function anonymous(bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
return component(\`B\`, {value: ctx['state'].value}, key + \`__1\`, node, ctx);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`delayed rendering, reusing fiber and stuff 2`] = `
|
||||||
|
"function anonymous(bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
const b2 = text(ctx['props'].value);
|
||||||
|
const b3 = component(\`C\`, {}, key + \`__1\`, node, ctx);
|
||||||
|
return multi([b2, b3]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`delayed rendering, reusing fiber and stuff 3`] = `
|
||||||
|
"function anonymous(bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<button block-handler-0=\\"click\\"><block-text-1/></button>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
let hdlr1 = [ctx['increment'], ctx];
|
||||||
|
let txt1 = ctx['state'].val;
|
||||||
|
return block1([hdlr1, txt1]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`delayed rendering, reusing fiber then component is destroyed and stuff 1`] = `
|
||||||
|
"function anonymous(bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
let b2,b3;
|
||||||
|
b2 = text(\`A\`);
|
||||||
|
if (ctx['state'].value<15) {
|
||||||
|
b3 = component(\`B\`, {value: ctx['state'].value}, key + \`__1\`, node, ctx);
|
||||||
|
}
|
||||||
|
return multi([b2, b3]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`delayed rendering, reusing fiber then component is destroyed and stuff 2`] = `
|
||||||
|
"function anonymous(bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
const b2 = text(ctx['props'].value);
|
||||||
|
const b3 = component(\`C\`, {}, key + \`__1\`, node, ctx);
|
||||||
|
return multi([b2, b3]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`delayed rendering, reusing fiber then component is destroyed and stuff 3`] = `
|
||||||
|
"function anonymous(bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<button block-handler-0=\\"click\\"><block-text-1/></button>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
let hdlr1 = [ctx['increment'], ctx];
|
||||||
|
let txt1 = ctx['state'].val;
|
||||||
|
return block1([hdlr1, txt1]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`delayed rendering, then component is destroyed and stuff 1`] = `
|
||||||
|
"function anonymous(bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
return component(\`B\`, {value: ctx['state'].value}, key + \`__1\`, node, ctx);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`delayed rendering, then component is destroyed and stuff 2`] = `
|
||||||
|
"function anonymous(bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
let b2,b3;
|
||||||
|
b2 = text(ctx['props'].value);
|
||||||
|
if (ctx['props'].value<10) {
|
||||||
|
b3 = component(\`C\`, {}, key + \`__1\`, node, ctx);
|
||||||
|
}
|
||||||
|
return multi([b2, b3]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`delayed rendering, then component is destroyed and stuff 3`] = `
|
||||||
|
"function anonymous(bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<button block-handler-0=\\"click\\"><block-text-1/></button>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
let hdlr1 = [ctx['increment'], ctx];
|
||||||
|
let txt1 = ctx['state'].val;
|
||||||
|
return block1([hdlr1, txt1]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`destroying/recreating a subcomponent, other scenario 1`] = `
|
exports[`destroying/recreating a subcomponent, other scenario 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -1,5 +1,31 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`reactivity in lifecycle Child component doesn't render when state they depend on changes but their parent is about to unmount them 1`] = `
|
||||||
|
"function anonymous(bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
let b2;
|
||||||
|
if (ctx['state'].renderChild) {
|
||||||
|
b2 = component(\`Child\`, {state: ctx['state']}, key + \`__1\`, node, ctx);
|
||||||
|
}
|
||||||
|
return multi([b2]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`reactivity in lifecycle Child component doesn't render when state they depend on changes but their parent is about to unmount them 2`] = `
|
||||||
|
"function anonymous(bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
return text(ctx['props'].state.content.a);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`reactivity in lifecycle can use a state hook 1`] = `
|
exports[`reactivity in lifecycle can use a state hook 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -1444,6 +1444,71 @@ exports[`slots simple default slot, variation 2`] = `
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`slots simple named and empty slot -- 2 1`] = `
|
||||||
|
"function anonymous(bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
||||||
|
let { capture, markRaw } = helpers;
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
const ctx1 = capture(ctx);
|
||||||
|
return component(\`Child\`, {slots: markRaw({'myEmptySlot': {myProp: 'myProp text'}})}, key + \`__1\`, node, ctx);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`slots simple named and empty slot -- 2 2`] = `
|
||||||
|
"function anonymous(bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
||||||
|
let { callSlot } = helpers;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
||||||
|
|
||||||
|
function defaultContent1(ctx, node, key = \\"\\") {
|
||||||
|
return text(\`default empty\`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
const b3 = callSlot(ctx, node, key, 'myEmptySlot', false, null, defaultContent1);
|
||||||
|
return block1([], [b3]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`slots simple named and empty slot 1`] = `
|
||||||
|
"function anonymous(bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
||||||
|
let { capture, markRaw } = helpers;
|
||||||
|
|
||||||
|
function slot1(ctx, node, key = \\"\\") {
|
||||||
|
return text(\`some text\`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
const ctx1 = capture(ctx);
|
||||||
|
return component(\`Child\`, {slots: markRaw({'myEmptySlot': {}, 'default': {__render: slot1, __ctx: ctx1}})}, key + \`__1\`, node, ctx);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`slots simple named and empty slot 2`] = `
|
||||||
|
"function anonymous(bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
||||||
|
let { callSlot } = helpers;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<span><block-child-0/><block-child-1/></span>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
const b2 = callSlot(ctx, node, key, 'default', false, null);
|
||||||
|
const b3 = callSlot(ctx, node, key, 'myEmptySlot', false, null);
|
||||||
|
return block1([], [b2, b3]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`slots simple slot with slot scope 1`] = `
|
exports[`slots simple slot with slot scope 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import {
|
|||||||
Component,
|
Component,
|
||||||
mount,
|
mount,
|
||||||
onMounted,
|
onMounted,
|
||||||
|
onRendered,
|
||||||
onWillStart,
|
onWillStart,
|
||||||
onWillUnmount,
|
onWillUnmount,
|
||||||
onWillUpdateProps,
|
onWillUpdateProps,
|
||||||
@@ -869,6 +870,7 @@ test("concurrent renderings scenario 2", async () => {
|
|||||||
"ComponentB:rendered",
|
"ComponentB:rendered",
|
||||||
]).toBeLogged();
|
]).toBeLogged();
|
||||||
|
|
||||||
|
debugger;
|
||||||
stateB.fromB = "c";
|
stateB.fromB = "c";
|
||||||
await nextTick();
|
await nextTick();
|
||||||
expect(fixture.innerHTML).toBe("<div>1<p><span>1b</span></p></div>");
|
expect(fixture.innerHTML).toBe("<div>1<p><span>1b</span></p></div>");
|
||||||
@@ -880,7 +882,7 @@ test("concurrent renderings scenario 2", async () => {
|
|||||||
|
|
||||||
defs[1].resolve(); // resolve rendering initiated in B
|
defs[1].resolve(); // resolve rendering initiated in B
|
||||||
await nextTick();
|
await nextTick();
|
||||||
expect(fixture.innerHTML).toBe("<div>2<p><span>2c</span></p></div>");
|
debugger
|
||||||
expect([
|
expect([
|
||||||
"ComponentC:willRender",
|
"ComponentC:willRender",
|
||||||
"ComponentC:rendered",
|
"ComponentC:rendered",
|
||||||
@@ -891,6 +893,7 @@ test("concurrent renderings scenario 2", async () => {
|
|||||||
"ComponentB:patched",
|
"ComponentB:patched",
|
||||||
"ComponentA:patched",
|
"ComponentA:patched",
|
||||||
]).toBeLogged();
|
]).toBeLogged();
|
||||||
|
expect(fixture.innerHTML).toBe("<div>2<p><span>2c</span></p></div>");
|
||||||
|
|
||||||
defs[0].resolve(); // resolve rendering initiated in A
|
defs[0].resolve(); // resolve rendering initiated in A
|
||||||
await nextTick();
|
await nextTick();
|
||||||
@@ -1079,11 +1082,7 @@ test("concurrent renderings scenario 3", async () => {
|
|||||||
stateC.fromC = "d";
|
stateC.fromC = "d";
|
||||||
await nextTick();
|
await nextTick();
|
||||||
expect(fixture.innerHTML).toBe("<div><p><span><i>1c</i></span></p></div>");
|
expect(fixture.innerHTML).toBe("<div><p><span><i>1c</i></span></p></div>");
|
||||||
expect([
|
expect([]).toBeLogged();
|
||||||
"ComponentC:willRender",
|
|
||||||
"ComponentD:willUpdateProps",
|
|
||||||
"ComponentC:rendered",
|
|
||||||
]).toBeLogged();
|
|
||||||
|
|
||||||
defB.resolve(); // resolve rendering initiated in A (still blocked in D)
|
defB.resolve(); // resolve rendering initiated in A (still blocked in D)
|
||||||
await nextTick();
|
await nextTick();
|
||||||
@@ -1099,14 +1098,7 @@ test("concurrent renderings scenario 3", async () => {
|
|||||||
|
|
||||||
defsD[0].resolve(); // resolve rendering initiated in C (should be ignored)
|
defsD[0].resolve(); // resolve rendering initiated in C (should be ignored)
|
||||||
await nextTick();
|
await nextTick();
|
||||||
expect(ComponentD.prototype.someValue).toBeCalledTimes(1);
|
|
||||||
expect(fixture.innerHTML).toBe("<div><p><span><i>1c</i></span></p></div>");
|
|
||||||
expect([]).toBeLogged();
|
|
||||||
|
|
||||||
defsD[1].resolve(); // completely resolve rendering initiated in A
|
|
||||||
await nextTick();
|
|
||||||
expect(fixture.innerHTML).toBe("<div><p><span><i>2d</i></span></p></div>");
|
expect(fixture.innerHTML).toBe("<div><p><span><i>2d</i></span></p></div>");
|
||||||
expect(ComponentD.prototype.someValue).toBeCalledTimes(2);
|
|
||||||
expect([
|
expect([
|
||||||
"ComponentD:willRender",
|
"ComponentD:willRender",
|
||||||
"ComponentD:rendered",
|
"ComponentD:rendered",
|
||||||
@@ -1119,6 +1111,7 @@ test("concurrent renderings scenario 3", async () => {
|
|||||||
"ComponentB:patched",
|
"ComponentB:patched",
|
||||||
"ComponentA:patched",
|
"ComponentA:patched",
|
||||||
]).toBeLogged();
|
]).toBeLogged();
|
||||||
|
expect(ComponentD.prototype.someValue).toBeCalledTimes(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("concurrent renderings scenario 4", async () => {
|
test("concurrent renderings scenario 4", async () => {
|
||||||
@@ -1207,11 +1200,7 @@ test("concurrent renderings scenario 4", async () => {
|
|||||||
stateC.fromC = "d";
|
stateC.fromC = "d";
|
||||||
await nextTick();
|
await nextTick();
|
||||||
expect(fixture.innerHTML).toBe("<div><p><span><i>1c</i></span></p></div>");
|
expect(fixture.innerHTML).toBe("<div><p><span><i>1c</i></span></p></div>");
|
||||||
expect([
|
expect([]).toBeLogged();
|
||||||
"ComponentC:willRender",
|
|
||||||
"ComponentD:willUpdateProps",
|
|
||||||
"ComponentC:rendered",
|
|
||||||
]).toBeLogged();
|
|
||||||
|
|
||||||
defB.resolve(); // resolve rendering initiated in A (still blocked in D)
|
defB.resolve(); // resolve rendering initiated in A (still blocked in D)
|
||||||
await nextTick();
|
await nextTick();
|
||||||
@@ -1227,6 +1216,12 @@ test("concurrent renderings scenario 4", async () => {
|
|||||||
|
|
||||||
defsD[1].resolve(); // completely resolve rendering initiated in A
|
defsD[1].resolve(); // completely resolve rendering initiated in A
|
||||||
await nextTick();
|
await nextTick();
|
||||||
|
expect(fixture.innerHTML).toBe("<div><p><span><i>1c</i></span></p></div>");
|
||||||
|
expect(ComponentD.prototype.someValue).toBeCalledTimes(1);
|
||||||
|
expect([]).toBeLogged();
|
||||||
|
|
||||||
|
defsD[0].resolve(); // resolve rendering initiated in C (should be ignored)
|
||||||
|
await nextTick();
|
||||||
expect(fixture.innerHTML).toBe("<div><p><span><i>2d</i></span></p></div>");
|
expect(fixture.innerHTML).toBe("<div><p><span><i>2d</i></span></p></div>");
|
||||||
expect(ComponentD.prototype.someValue).toBeCalledTimes(2);
|
expect(ComponentD.prototype.someValue).toBeCalledTimes(2);
|
||||||
expect([
|
expect([
|
||||||
@@ -1241,12 +1236,6 @@ test("concurrent renderings scenario 4", async () => {
|
|||||||
"ComponentB:patched",
|
"ComponentB:patched",
|
||||||
"ComponentA:patched",
|
"ComponentA:patched",
|
||||||
]).toBeLogged();
|
]).toBeLogged();
|
||||||
|
|
||||||
defsD[0].resolve(); // resolve rendering initiated in C (should be ignored)
|
|
||||||
await nextTick();
|
|
||||||
expect(fixture.innerHTML).toBe("<div><p><span><i>2d</i></span></p></div>");
|
|
||||||
expect(ComponentD.prototype.someValue).toBeCalledTimes(2);
|
|
||||||
expect([]).toBeLogged();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("concurrent renderings scenario 5", async () => {
|
test("concurrent renderings scenario 5", async () => {
|
||||||
@@ -2714,13 +2703,7 @@ test("delay willUpdateProps", async () => {
|
|||||||
parent.render();
|
parent.render();
|
||||||
await nextTick();
|
await nextTick();
|
||||||
expect(fixture.innerHTML).toBe("0_0");
|
expect(fixture.innerHTML).toBe("0_0");
|
||||||
expect([
|
expect(["Parent:willRender", "Child:willUpdateProps", "Parent:rendered"]).toBeLogged();
|
||||||
"Child:willRender",
|
|
||||||
"Child:rendered",
|
|
||||||
"Parent:willRender",
|
|
||||||
"Child:willUpdateProps",
|
|
||||||
"Parent:rendered",
|
|
||||||
]).toBeLogged();
|
|
||||||
|
|
||||||
promise = makeDeferred();
|
promise = makeDeferred();
|
||||||
const prom2 = promise;
|
const prom2 = promise;
|
||||||
@@ -2837,13 +2820,9 @@ test("delay willUpdateProps with rendering grandchild", async () => {
|
|||||||
await nextTick();
|
await nextTick();
|
||||||
expect(fixture.innerHTML).toBe("0_0<div></div>");
|
expect(fixture.innerHTML).toBe("0_0<div></div>");
|
||||||
expect([
|
expect([
|
||||||
"DelayedChild:willRender",
|
|
||||||
"DelayedChild:rendered",
|
|
||||||
"GrandParent:willRender",
|
"GrandParent:willRender",
|
||||||
"Parent:willUpdateProps",
|
"Parent:willUpdateProps",
|
||||||
"GrandParent:rendered",
|
"GrandParent:rendered",
|
||||||
"ReactiveChild:willRender",
|
|
||||||
"ReactiveChild:rendered",
|
|
||||||
"Parent:willRender",
|
"Parent:willRender",
|
||||||
"DelayedChild:willUpdateProps",
|
"DelayedChild:willUpdateProps",
|
||||||
"ReactiveChild:willUpdateProps",
|
"ReactiveChild:willUpdateProps",
|
||||||
@@ -2864,8 +2843,6 @@ test("delay willUpdateProps with rendering grandchild", async () => {
|
|||||||
"GrandParent:willRender",
|
"GrandParent:willRender",
|
||||||
"Parent:willUpdateProps",
|
"Parent:willUpdateProps",
|
||||||
"GrandParent:rendered",
|
"GrandParent:rendered",
|
||||||
"ReactiveChild:willRender",
|
|
||||||
"ReactiveChild:rendered",
|
|
||||||
"Parent:willRender",
|
"Parent:willRender",
|
||||||
"DelayedChild:willUpdateProps",
|
"DelayedChild:willUpdateProps",
|
||||||
"ReactiveChild:willUpdateProps",
|
"ReactiveChild:willUpdateProps",
|
||||||
@@ -3254,6 +3231,467 @@ test("rendering parent twice, with different props on child and stuff", async ()
|
|||||||
]).toBeLogged();
|
]).toBeLogged();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("delayed rendering, but then initial rendering is cancelled by yet another render", async () => {
|
||||||
|
const promC = makeDeferred();
|
||||||
|
let stateB: any = null;
|
||||||
|
|
||||||
|
class D extends Component {
|
||||||
|
static template = xml`<button t-on-click="increment"><t t-esc="state.val"/></button>`;
|
||||||
|
state = useState({ val: 1 });
|
||||||
|
setup() {
|
||||||
|
useLogLifecycle();
|
||||||
|
}
|
||||||
|
increment() {
|
||||||
|
this.state.val++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class C extends Component {
|
||||||
|
static template = xml`<D/><p><t t-esc="props.value"/></p>`;
|
||||||
|
static components = { D };
|
||||||
|
setup() {
|
||||||
|
useLogLifecycle();
|
||||||
|
onWillUpdateProps(() => promC);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class B extends Component {
|
||||||
|
static template = xml`<C value="state.someValue + props.value"/>`;
|
||||||
|
static components = { C };
|
||||||
|
state = useState({ someValue: 3 });
|
||||||
|
setup() {
|
||||||
|
useLogLifecycle();
|
||||||
|
stateB = this.state;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class A extends Component {
|
||||||
|
static template = xml`<B value="state.value"/>`;
|
||||||
|
static components = { B };
|
||||||
|
state = useState({ value: 33 });
|
||||||
|
setup() {
|
||||||
|
useLogLifecycle();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const parent = await mount(A, fixture);
|
||||||
|
expect(fixture.innerHTML).toBe("<button>1</button><p>36</p>");
|
||||||
|
expect([
|
||||||
|
"A:setup",
|
||||||
|
"A:willStart",
|
||||||
|
"A:willRender",
|
||||||
|
"B:setup",
|
||||||
|
"B:willStart",
|
||||||
|
"A:rendered",
|
||||||
|
"B:willRender",
|
||||||
|
"C:setup",
|
||||||
|
"C:willStart",
|
||||||
|
"B:rendered",
|
||||||
|
"C:willRender",
|
||||||
|
"D:setup",
|
||||||
|
"D:willStart",
|
||||||
|
"C:rendered",
|
||||||
|
"D:willRender",
|
||||||
|
"D:rendered",
|
||||||
|
"D:mounted",
|
||||||
|
"C:mounted",
|
||||||
|
"B:mounted",
|
||||||
|
"A:mounted",
|
||||||
|
]).toBeLogged();
|
||||||
|
|
||||||
|
// update B and C, but render is blocked by C willupdateProps
|
||||||
|
stateB.someValue = 5;
|
||||||
|
await nextTick();
|
||||||
|
expect(["B:willRender", "C:willUpdateProps", "B:rendered"]).toBeLogged();
|
||||||
|
|
||||||
|
// update D => render should be delayed, because B is currently rendering
|
||||||
|
fixture.querySelector("button")!.click();
|
||||||
|
await nextTick();
|
||||||
|
expect([]).toBeLogged();
|
||||||
|
|
||||||
|
// update A => render should go to B and cancel it
|
||||||
|
parent.state.value = 34;
|
||||||
|
await nextTick();
|
||||||
|
expect([
|
||||||
|
"A:willRender",
|
||||||
|
"B:willUpdateProps",
|
||||||
|
"A:rendered",
|
||||||
|
"B:willRender",
|
||||||
|
"C:willUpdateProps",
|
||||||
|
"B:rendered",
|
||||||
|
]).toBeLogged();
|
||||||
|
|
||||||
|
promC.resolve();
|
||||||
|
await nextTick();
|
||||||
|
expect([
|
||||||
|
"C:willRender",
|
||||||
|
"C:rendered",
|
||||||
|
"D:willRender",
|
||||||
|
"D:rendered",
|
||||||
|
"D:willPatch",
|
||||||
|
"D:patched",
|
||||||
|
"A:willPatch",
|
||||||
|
"B:willPatch",
|
||||||
|
"C:willPatch",
|
||||||
|
"C:patched",
|
||||||
|
"B:patched",
|
||||||
|
"A:patched",
|
||||||
|
]).toBeLogged();
|
||||||
|
expect(fixture.innerHTML).toBe("<button>2</button><p>39</p>");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("delayed rendering, reusing fiber and stuff", async () => {
|
||||||
|
let prom1 = makeDeferred();
|
||||||
|
let prom2 = makeDeferred();
|
||||||
|
|
||||||
|
class C extends Component {
|
||||||
|
static template = xml`<button t-on-click="increment"><t t-esc="state.val"/></button>`;
|
||||||
|
state = useState({ val: 1 });
|
||||||
|
setup() {
|
||||||
|
useLogLifecycle();
|
||||||
|
}
|
||||||
|
increment() {
|
||||||
|
this.state.val++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class B extends Component {
|
||||||
|
static template = xml`<t t-esc="props.value"/><C />`;
|
||||||
|
static components = { C };
|
||||||
|
setup() {
|
||||||
|
useLogLifecycle();
|
||||||
|
let flag = false;
|
||||||
|
onWillUpdateProps(() => {
|
||||||
|
flag = true;
|
||||||
|
return prom1;
|
||||||
|
});
|
||||||
|
onRendered(async () => {
|
||||||
|
if (flag) {
|
||||||
|
await nextMicroTick();
|
||||||
|
prom2.resolve();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class A extends Component {
|
||||||
|
static template = xml`<B value="state.value"/>`;
|
||||||
|
static components = { B };
|
||||||
|
state = useState({ value: 33 });
|
||||||
|
setup() {
|
||||||
|
useLogLifecycle();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const parent = await mount(A, fixture);
|
||||||
|
expect(fixture.innerHTML).toBe("33<button>1</button>");
|
||||||
|
expect([
|
||||||
|
"A:setup",
|
||||||
|
"A:willStart",
|
||||||
|
"A:willRender",
|
||||||
|
"B:setup",
|
||||||
|
"B:willStart",
|
||||||
|
"A:rendered",
|
||||||
|
"B:willRender",
|
||||||
|
"C:setup",
|
||||||
|
"C:willStart",
|
||||||
|
"B:rendered",
|
||||||
|
"C:willRender",
|
||||||
|
"C:rendered",
|
||||||
|
"C:mounted",
|
||||||
|
"B:mounted",
|
||||||
|
"A:mounted",
|
||||||
|
]).toBeLogged();
|
||||||
|
|
||||||
|
// initiate a render in A, but is blocked in B
|
||||||
|
parent.state.value = 34;
|
||||||
|
await nextTick();
|
||||||
|
expect(["A:willRender", "B:willUpdateProps", "A:rendered"]).toBeLogged();
|
||||||
|
|
||||||
|
// initiate a render in C => delayed because of render in A
|
||||||
|
fixture.querySelector("button")!.click();
|
||||||
|
await nextTick();
|
||||||
|
expect([]).toBeLogged();
|
||||||
|
|
||||||
|
// wait for render in A to be completed
|
||||||
|
prom1.resolve();
|
||||||
|
await prom2;
|
||||||
|
expect(["B:willRender", "B:rendered", "C:willRender", "C:rendered"]).toBeLogged();
|
||||||
|
|
||||||
|
// initiate a new render in A => fiber will be reused
|
||||||
|
parent.state.value = 355;
|
||||||
|
await nextTick();
|
||||||
|
expect(fixture.innerHTML).toBe("355<button>2</button>");
|
||||||
|
expect([
|
||||||
|
"A:willRender",
|
||||||
|
"B:willUpdateProps",
|
||||||
|
"A:rendered",
|
||||||
|
"B:willRender",
|
||||||
|
"B:rendered",
|
||||||
|
"A:willPatch",
|
||||||
|
"B:willPatch",
|
||||||
|
"B:patched",
|
||||||
|
"A:patched",
|
||||||
|
"C:willPatch",
|
||||||
|
"C:patched",
|
||||||
|
]).toBeLogged();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("delayed rendering, then component is destroyed and stuff", async () => {
|
||||||
|
let prom1 = makeDeferred();
|
||||||
|
|
||||||
|
class C extends Component {
|
||||||
|
static template = xml`<button t-on-click="increment"><t t-esc="state.val"/></button>`;
|
||||||
|
state = useState({ val: 1 });
|
||||||
|
setup() {
|
||||||
|
useLogLifecycle();
|
||||||
|
}
|
||||||
|
increment() {
|
||||||
|
this.state.val++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class B extends Component {
|
||||||
|
static template = xml`<t t-esc="props.value"/><t t-if="props.value lt 10"><C /></t>`;
|
||||||
|
static components = { C };
|
||||||
|
setup() {
|
||||||
|
useLogLifecycle();
|
||||||
|
onWillUpdateProps(() => prom1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class A extends Component {
|
||||||
|
static template = xml`<B value="state.value"/>`;
|
||||||
|
static components = { B };
|
||||||
|
state = useState({ value: 3 });
|
||||||
|
setup() {
|
||||||
|
useLogLifecycle();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const parent = await mount(A, fixture);
|
||||||
|
expect(fixture.innerHTML).toBe("3<button>1</button>");
|
||||||
|
expect([
|
||||||
|
"A:setup",
|
||||||
|
"A:willStart",
|
||||||
|
"A:willRender",
|
||||||
|
"B:setup",
|
||||||
|
"B:willStart",
|
||||||
|
"A:rendered",
|
||||||
|
"B:willRender",
|
||||||
|
"C:setup",
|
||||||
|
"C:willStart",
|
||||||
|
"B:rendered",
|
||||||
|
"C:willRender",
|
||||||
|
"C:rendered",
|
||||||
|
"C:mounted",
|
||||||
|
"B:mounted",
|
||||||
|
"A:mounted",
|
||||||
|
]).toBeLogged();
|
||||||
|
|
||||||
|
// initiate a render in C (so will be first task)
|
||||||
|
fixture.querySelector("button")!.click();
|
||||||
|
// initiate a render in A, but is blocked in B. the render will destroy c. also,
|
||||||
|
// it blocks the render C
|
||||||
|
parent.state.value = 34;
|
||||||
|
await nextTick();
|
||||||
|
expect(["A:willRender", "B:willUpdateProps", "A:rendered"]).toBeLogged();
|
||||||
|
|
||||||
|
// wait for render in A to be completed
|
||||||
|
prom1.resolve();
|
||||||
|
await nextTick();
|
||||||
|
expect(fixture.innerHTML).toBe("34");
|
||||||
|
expect([
|
||||||
|
"B:willRender",
|
||||||
|
"B:rendered",
|
||||||
|
"A:willPatch",
|
||||||
|
"B:willPatch",
|
||||||
|
"C:willUnmount",
|
||||||
|
"C:willDestroy",
|
||||||
|
"B:patched",
|
||||||
|
"A:patched",
|
||||||
|
]).toBeLogged();
|
||||||
|
|
||||||
|
await nextTick();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("delayed rendering, reusing fiber then component is destroyed and stuff", async () => {
|
||||||
|
let prom1 = makeDeferred();
|
||||||
|
|
||||||
|
class C extends Component {
|
||||||
|
static template = xml`<button t-on-click="increment"><t t-esc="state.val"/></button>`;
|
||||||
|
state = useState({ val: 1 });
|
||||||
|
setup() {
|
||||||
|
useLogLifecycle();
|
||||||
|
}
|
||||||
|
increment() {
|
||||||
|
this.state.val++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class B extends Component {
|
||||||
|
static template = xml`<t t-esc="props.value"/><C />`;
|
||||||
|
static components = { C };
|
||||||
|
setup() {
|
||||||
|
useLogLifecycle();
|
||||||
|
onWillUpdateProps(() => prom1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class A extends Component {
|
||||||
|
static template = xml`A<t t-if="state.value lt 15"><B value="state.value"/></t>`;
|
||||||
|
static components = { B };
|
||||||
|
state = useState({ value: 3 });
|
||||||
|
setup() {
|
||||||
|
useLogLifecycle();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const parent = await mount(A, fixture);
|
||||||
|
expect(fixture.innerHTML).toBe("A3<button>1</button>");
|
||||||
|
expect([
|
||||||
|
"A:setup",
|
||||||
|
"A:willStart",
|
||||||
|
"A:willRender",
|
||||||
|
"B:setup",
|
||||||
|
"B:willStart",
|
||||||
|
"A:rendered",
|
||||||
|
"B:willRender",
|
||||||
|
"C:setup",
|
||||||
|
"C:willStart",
|
||||||
|
"B:rendered",
|
||||||
|
"C:willRender",
|
||||||
|
"C:rendered",
|
||||||
|
"C:mounted",
|
||||||
|
"B:mounted",
|
||||||
|
"A:mounted",
|
||||||
|
]).toBeLogged();
|
||||||
|
|
||||||
|
// initiate a render in A, but is blocked in B
|
||||||
|
parent.state.value = 5;
|
||||||
|
await nextTick();
|
||||||
|
expect(["A:willRender", "B:willUpdateProps", "A:rendered"]).toBeLogged();
|
||||||
|
|
||||||
|
// initiate a render in C (will be delayed because of render in A)
|
||||||
|
fixture.querySelector("button")!.click();
|
||||||
|
await nextTick();
|
||||||
|
expect([]).toBeLogged();
|
||||||
|
|
||||||
|
// initiate a render in A, that will destroy B
|
||||||
|
parent.state.value = 23;
|
||||||
|
await nextTick();
|
||||||
|
expect(fixture.innerHTML).toBe("A");
|
||||||
|
expect([
|
||||||
|
"A:willRender",
|
||||||
|
"A:rendered",
|
||||||
|
"A:willPatch",
|
||||||
|
"B:willUnmount",
|
||||||
|
"C:willUnmount",
|
||||||
|
"C:willDestroy",
|
||||||
|
"B:willDestroy",
|
||||||
|
"A:patched",
|
||||||
|
]).toBeLogged();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("another scenario with delayed rendering", async () => {
|
||||||
|
let prom1 = makeDeferred();
|
||||||
|
let onSecondRenderA = makeDeferred();
|
||||||
|
|
||||||
|
class C extends Component {
|
||||||
|
static template = xml`<button t-on-click="increment"><t t-esc="state.val"/></button>`;
|
||||||
|
state = useState({ val: 1 });
|
||||||
|
setup() {
|
||||||
|
useLogLifecycle();
|
||||||
|
}
|
||||||
|
increment() {
|
||||||
|
this.state.val++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class B extends Component {
|
||||||
|
static template = xml`<t t-esc="props.value"/><C />`;
|
||||||
|
static components = { C };
|
||||||
|
setup() {
|
||||||
|
useLogLifecycle();
|
||||||
|
onWillUpdateProps(() => prom1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class A extends Component {
|
||||||
|
static template = xml`A<t t-if="state.value lt 15"><B value="state.value"/></t>`;
|
||||||
|
static components = { B };
|
||||||
|
state = useState({ value: 3 });
|
||||||
|
setup() {
|
||||||
|
useLogLifecycle();
|
||||||
|
let n = 0;
|
||||||
|
onRendered(() => {
|
||||||
|
n++;
|
||||||
|
if (n === 2) {
|
||||||
|
onSecondRenderA.resolve();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const parent = await mount(A, fixture);
|
||||||
|
expect(fixture.innerHTML).toBe("A3<button>1</button>");
|
||||||
|
expect([
|
||||||
|
"A:setup",
|
||||||
|
"A:willStart",
|
||||||
|
"A:willRender",
|
||||||
|
"B:setup",
|
||||||
|
"B:willStart",
|
||||||
|
"A:rendered",
|
||||||
|
"B:willRender",
|
||||||
|
"C:setup",
|
||||||
|
"C:willStart",
|
||||||
|
"B:rendered",
|
||||||
|
"C:willRender",
|
||||||
|
"C:rendered",
|
||||||
|
"C:mounted",
|
||||||
|
"B:mounted",
|
||||||
|
"A:mounted",
|
||||||
|
]).toBeLogged();
|
||||||
|
|
||||||
|
// initiate a render in A, but is blocked in B
|
||||||
|
parent.state.value = 5;
|
||||||
|
await nextTick();
|
||||||
|
expect(["A:willRender", "B:willUpdateProps", "A:rendered"]).toBeLogged();
|
||||||
|
|
||||||
|
// initiate a render in C (will be delayed because of render in A)
|
||||||
|
fixture.querySelector("button")!.click();
|
||||||
|
await nextTick();
|
||||||
|
expect([]).toBeLogged();
|
||||||
|
|
||||||
|
// initiate a render in A, that will destroy B
|
||||||
|
parent.state.value = 23;
|
||||||
|
await onSecondRenderA;
|
||||||
|
await nextMicroTick();
|
||||||
|
expect(["A:willRender", "A:rendered"]).toBeLogged();
|
||||||
|
|
||||||
|
// rerender A, but without destroying B
|
||||||
|
parent.state.value = 7;
|
||||||
|
await nextTick();
|
||||||
|
expect(["A:willRender", "B:willUpdateProps", "A:rendered"]).toBeLogged();
|
||||||
|
|
||||||
|
prom1.resolve();
|
||||||
|
await nextTick();
|
||||||
|
expect(fixture.innerHTML).toBe("A7<button>2</button>");
|
||||||
|
|
||||||
|
expect([
|
||||||
|
"B:willRender",
|
||||||
|
"B:rendered",
|
||||||
|
"C:willRender",
|
||||||
|
"C:rendered",
|
||||||
|
"A:willPatch",
|
||||||
|
"B:willPatch",
|
||||||
|
"B:patched",
|
||||||
|
"A:patched",
|
||||||
|
"C:willPatch",
|
||||||
|
"C:patched",
|
||||||
|
]).toBeLogged();
|
||||||
|
});
|
||||||
|
|
||||||
// test.skip("components with shouldUpdate=false", async () => {
|
// test.skip("components with shouldUpdate=false", async () => {
|
||||||
// const state = { p: 1, cc: 10 };
|
// const state = { p: 1, cc: 10 };
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import {
|
|||||||
useState,
|
useState,
|
||||||
xml,
|
xml,
|
||||||
} from "../../src";
|
} from "../../src";
|
||||||
import { makeTestFixture, nextTick, snapshotEverything } from "../helpers";
|
import { makeTestFixture, nextTick, snapshotEverything, useLogLifecycle } from "../helpers";
|
||||||
|
|
||||||
let fixture: HTMLElement;
|
let fixture: HTMLElement;
|
||||||
|
|
||||||
@@ -155,4 +155,48 @@ describe("reactivity in lifecycle", () => {
|
|||||||
expect(steps).toEqual([2]);
|
expect(steps).toEqual([2]);
|
||||||
expect(fixture.innerHTML).toBe("<div>2</div>");
|
expect(fixture.innerHTML).toBe("<div>2</div>");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("Child component doesn't render when state they depend on changes but their parent is about to unmount them", async () => {
|
||||||
|
class Child extends Component {
|
||||||
|
static template = xml`<t t-esc="props.state.content.a"/>`;
|
||||||
|
setup() {
|
||||||
|
useLogLifecycle();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class Parent extends Component {
|
||||||
|
static template = xml`<Child t-if="state.renderChild" state="state"/>`;
|
||||||
|
static components = { Child };
|
||||||
|
state: any = useState({ renderChild: true, content: { a: 2 } });
|
||||||
|
setup() {
|
||||||
|
useLogLifecycle();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const parent = await mount(Parent, fixture);
|
||||||
|
expect(fixture.innerHTML).toBe("2");
|
||||||
|
expect([
|
||||||
|
"Parent:setup",
|
||||||
|
"Parent:willStart",
|
||||||
|
"Parent:willRender",
|
||||||
|
"Child:setup",
|
||||||
|
"Child:willStart",
|
||||||
|
"Parent:rendered",
|
||||||
|
"Child:willRender",
|
||||||
|
"Child:rendered",
|
||||||
|
"Child:mounted",
|
||||||
|
"Parent:mounted",
|
||||||
|
]).toBeLogged();
|
||||||
|
|
||||||
|
parent.state.content = null;
|
||||||
|
parent.state.renderChild = false;
|
||||||
|
await nextTick();
|
||||||
|
expect([
|
||||||
|
"Parent:willRender",
|
||||||
|
"Parent:rendered",
|
||||||
|
"Parent:willPatch",
|
||||||
|
"Child:willUnmount",
|
||||||
|
"Child:willDestroy",
|
||||||
|
"Parent:patched",
|
||||||
|
]).toBeLogged();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -74,6 +74,43 @@ describe("slots", () => {
|
|||||||
expect(fixture.innerHTML).toBe("<span>other text</span>");
|
expect(fixture.innerHTML).toBe("<span>other text</span>");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("simple named and empty slot", async () => {
|
||||||
|
class Child extends Component {
|
||||||
|
static template = xml`<span><t t-slot="default" /><t t-slot="myEmptySlot"/></span>`;
|
||||||
|
|
||||||
|
setup() {
|
||||||
|
expect(this.props.slots["myEmptySlot"]).toBeTruthy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Parent extends Component {
|
||||||
|
static template = xml`<Child>some text<t t-set-slot="myEmptySlot" /></Child>`;
|
||||||
|
static components = { Child };
|
||||||
|
}
|
||||||
|
await mount(Parent, fixture);
|
||||||
|
|
||||||
|
expect(fixture.innerHTML).toBe("<span>some text</span>");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("simple named and empty slot -- 2", async () => {
|
||||||
|
class Child extends Component {
|
||||||
|
static template = xml`<span><t t-slot="myEmptySlot">default empty</t></span>`;
|
||||||
|
|
||||||
|
setup() {
|
||||||
|
expect(this.props.slots["myEmptySlot"]).toBeTruthy();
|
||||||
|
expect(this.props.slots["myEmptySlot"].myProp).toBe("myProp text");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Parent extends Component {
|
||||||
|
static template = xml`<Child><t t-set-slot="myEmptySlot" myProp="'myProp text'" /></Child>`;
|
||||||
|
static components = { Child };
|
||||||
|
}
|
||||||
|
await mount(Parent, fixture);
|
||||||
|
|
||||||
|
expect(fixture.innerHTML).toBe("<span>default empty</span>");
|
||||||
|
});
|
||||||
|
|
||||||
test("default slot with slot scope: shorthand syntax", async () => {
|
test("default slot with slot scope: shorthand syntax", async () => {
|
||||||
let child: any;
|
let child: any;
|
||||||
class Child extends Component {
|
class Child extends Component {
|
||||||
|
|||||||
@@ -208,6 +208,46 @@ describe("Reactivity", () => {
|
|||||||
expect(n).toBe(1); // two operations but only one notification
|
expect(n).toBe(1); // two operations but only one notification
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("batched: modifying the reactive in the callback doesn't break reactivity", async () => {
|
||||||
|
let n = 0;
|
||||||
|
let obj = { a: 1 };
|
||||||
|
const state = createReactive(
|
||||||
|
obj,
|
||||||
|
batched(() => {
|
||||||
|
state.a; // subscribe to a
|
||||||
|
state.a = 2;
|
||||||
|
n++;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
expect(n).toBe(0);
|
||||||
|
state.a = 2;
|
||||||
|
expect(n).toBe(0);
|
||||||
|
await nextMicroTick();
|
||||||
|
expect(n).toBe(0); // key has not be read yet
|
||||||
|
state.a = state.a + 5; // key is read and then modified
|
||||||
|
expect(n).toBe(0);
|
||||||
|
await nextMicroTick();
|
||||||
|
expect(n).toBe(1);
|
||||||
|
// the write a = 2 inside the batched callback triggered another notification, wait for it
|
||||||
|
await nextMicroTick();
|
||||||
|
expect(n).toBe(2);
|
||||||
|
// Should now be stable as we're writing the same value again
|
||||||
|
await nextMicroTick();
|
||||||
|
expect(n).toBe(2);
|
||||||
|
|
||||||
|
// Do it again to check it's not broken
|
||||||
|
state.a = state.a + 5; // key is read and then modified
|
||||||
|
expect(n).toBe(2);
|
||||||
|
await nextMicroTick();
|
||||||
|
expect(n).toBe(3);
|
||||||
|
// the write a = 2 inside the batched callback triggered another notification, wait for it
|
||||||
|
await nextMicroTick();
|
||||||
|
expect(n).toBe(4);
|
||||||
|
// Should now be stable as we're writing the same value again
|
||||||
|
await nextMicroTick();
|
||||||
|
expect(n).toBe(4);
|
||||||
|
});
|
||||||
|
|
||||||
test("setting property to same value does not trigger callback", async () => {
|
test("setting property to same value does not trigger callback", async () => {
|
||||||
let n = 0;
|
let n = 0;
|
||||||
const state = createReactive({ a: 1 }, () => n++);
|
const state = createReactive({ a: 1 }, () => n++);
|
||||||
@@ -1095,6 +1135,13 @@ describe("Reactivity", () => {
|
|||||||
expect(n).toBe(1);
|
expect(n).toBe(1);
|
||||||
expect(state.k).toEqual({ n: 2 });
|
expect(state.k).toEqual({ n: 2 });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("can access properties on reactive of frozen objects", async () => {
|
||||||
|
const obj = Object.freeze({ a: {} });
|
||||||
|
const state = createReactive(obj);
|
||||||
|
expect(() => state.a).not.toThrow();
|
||||||
|
expect(state.a).toBe(obj.a);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Collections", () => {
|
describe("Collections", () => {
|
||||||
|
|||||||
@@ -50,4 +50,24 @@ describe("batched", () => {
|
|||||||
await nextMicroTick();
|
await nextMicroTick();
|
||||||
expect(n).toBe(1);
|
expect(n).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("calling batched function from within the callback is not treated as part of the original batch", async () => {
|
||||||
|
let n = 0;
|
||||||
|
let fn = batched(() => {
|
||||||
|
n++;
|
||||||
|
if (n === 1) {
|
||||||
|
fn();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(n).toBe(0);
|
||||||
|
fn();
|
||||||
|
expect(n).toBe(0);
|
||||||
|
await nextMicroTick(); // First batch
|
||||||
|
expect(n).toBe(1);
|
||||||
|
await nextMicroTick(); // Second batch initiated from within the callback
|
||||||
|
expect(n).toBe(2);
|
||||||
|
await nextMicroTick();
|
||||||
|
expect(n).toBe(2);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user