mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0d9d21a5c1 | |||
| 836e12b1c5 | |||
| 7538aeae0e | |||
| 3e9ba9ca8e | |||
| e4c296a7d2 | |||
| 44748270da | |||
| 8b1dc4c43d | |||
| c105c6da38 |
@@ -451,5 +451,6 @@ console.log(status(component));
|
|||||||
// logs either:
|
// logs either:
|
||||||
// - 'new', if the component is new and has not been mounted yet
|
// - 'new', if the component is new and has not been mounted yet
|
||||||
// - 'mounted', if the component is currently mounted
|
// - 'mounted', if the component is currently mounted
|
||||||
|
// - 'cancelled', if the component has not been mounted yet but will be destroyed soon
|
||||||
// - 'destroyed' if the component is currently destroyed
|
// - 'destroyed' if the component is currently destroyed
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -376,15 +376,16 @@ An important difference should be made with the usual `QWeb` behaviour: Owl
|
|||||||
requires the presence of a `t-key` directive, to be able to properly reconcile
|
requires the presence of a `t-key` directive, to be able to properly reconcile
|
||||||
renderings.
|
renderings.
|
||||||
|
|
||||||
`t-foreach` can iterate on an array (the current item will be the current value)
|
`t-foreach` can iterate on any iterable, and also has special support for objects
|
||||||
or an object (the current item will be the current key).
|
and maps, it will expose the key of the current iteration as the contents of the
|
||||||
|
`t-as`, and the corresponding value with the same name and the suffix `_value`.
|
||||||
|
|
||||||
In addition to the name passed via t-as, `t-foreach` provides a few other
|
In addition to the name passed via t-as, `t-foreach` provides a few other useful
|
||||||
variables for various data points (note: `$as` will be replaced with the name
|
variables (note: `$as` will be replaced with the name passed to `t-as`):
|
||||||
passed to `t-as`):
|
|
||||||
|
|
||||||
- `$as_value`: the current iteration value, identical to `$as` for lists and
|
- `$as_value`: the current iteration value, identical to `$as` for arrays and
|
||||||
integers, but for objects, it provides the value (where `$as` provides the key)
|
other iterables, but for objects and maps, it provides the value (where `$as`
|
||||||
|
provides the key)
|
||||||
- `$as_index`: the current iteration index (the first item of the iteration has index 0)
|
- `$as_index`: the current iteration index (the first item of the iteration has index 0)
|
||||||
- `$as_first`: whether the current item is the first of the iteration
|
- `$as_first`: whether the current item is the first of the iteration
|
||||||
(equivalent to `$as_index == 0`)
|
(equivalent to `$as_index == 0`)
|
||||||
|
|||||||
+82
-49
@@ -122,14 +122,16 @@ function handleError(params) {
|
|||||||
}
|
}
|
||||||
const node = "node" in params ? params.node : params.fiber.node;
|
const node = "node" in params ? params.node : params.fiber.node;
|
||||||
const fiber = "fiber" in params ? params.fiber : node.fiber;
|
const fiber = "fiber" in params ? params.fiber : node.fiber;
|
||||||
// resets the fibers on components if possible. This is important so that
|
if (fiber) {
|
||||||
// new renderings can be properly included in the initial one, if any.
|
// resets the fibers on components if possible. This is important so that
|
||||||
let current = fiber;
|
// new renderings can be properly included in the initial one, if any.
|
||||||
do {
|
let current = fiber;
|
||||||
current.node.fiber = current;
|
do {
|
||||||
current = current.parent;
|
current.node.fiber = current;
|
||||||
} while (current);
|
current = current.parent;
|
||||||
fibersInError.set(fiber.root, error);
|
} while (current);
|
||||||
|
fibersInError.set(fiber.root, error);
|
||||||
|
}
|
||||||
const handled = _handleError(node, error);
|
const handled = _handleError(node, error);
|
||||||
if (!handled) {
|
if (!handled) {
|
||||||
console.warn(`[Owl] Unhandled error. Destroying the root component`);
|
console.warn(`[Owl] Unhandled error. Destroying the root component`);
|
||||||
@@ -311,20 +313,13 @@ function updateClass(val, oldVal) {
|
|||||||
* @returns a batched version of the original callback
|
* @returns a batched version of the original callback
|
||||||
*/
|
*/
|
||||||
function batched(callback) {
|
function batched(callback) {
|
||||||
let called = false;
|
let scheduled = false;
|
||||||
return async () => {
|
return async (...args) => {
|
||||||
// This await blocks all calls to the callback here, then releases them sequentially
|
if (!scheduled) {
|
||||||
// in the next microtick. This line decides the granularity of the batch.
|
scheduled = true;
|
||||||
await Promise.resolve();
|
await Promise.resolve();
|
||||||
if (!called) {
|
scheduled = false;
|
||||||
called = true;
|
callback(...args);
|
||||||
// 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.
|
|
||||||
// Schedule this before calling the callback so that calls to the batched function
|
|
||||||
// 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();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -1657,8 +1652,7 @@ function cancelFibers(fibers) {
|
|||||||
let node = fiber.node;
|
let node = fiber.node;
|
||||||
fiber.render = throwOnRender;
|
fiber.render = throwOnRender;
|
||||||
if (node.status === 0 /* NEW */) {
|
if (node.status === 0 /* NEW */) {
|
||||||
node.destroy();
|
node.cancel();
|
||||||
delete node.parent.children[node.parentKey];
|
|
||||||
}
|
}
|
||||||
node.fiber = null;
|
node.fiber = null;
|
||||||
if (fiber.bdom) {
|
if (fiber.bdom) {
|
||||||
@@ -2385,6 +2379,9 @@ class ComponentNode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
async render(deep) {
|
async render(deep) {
|
||||||
|
if (this.status >= 2 /* CANCELLED */) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
let current = this.fiber;
|
let current = this.fiber;
|
||||||
if (current && (current.root.locked || current.bdom === true)) {
|
if (current && (current.root.locked || current.bdom === true)) {
|
||||||
await Promise.resolve();
|
await Promise.resolve();
|
||||||
@@ -2410,7 +2407,7 @@ class ComponentNode {
|
|||||||
this.fiber = fiber;
|
this.fiber = fiber;
|
||||||
this.app.scheduler.addFiber(fiber);
|
this.app.scheduler.addFiber(fiber);
|
||||||
await Promise.resolve();
|
await Promise.resolve();
|
||||||
if (this.status === 2 /* DESTROYED */) {
|
if (this.status >= 2 /* CANCELLED */) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// We only want to actually render the component if the following two
|
// We only want to actually render the component if the following two
|
||||||
@@ -2428,6 +2425,18 @@ class ComponentNode {
|
|||||||
fiber.render();
|
fiber.render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
cancel() {
|
||||||
|
this._cancel();
|
||||||
|
delete this.parent.children[this.parentKey];
|
||||||
|
this.app.scheduler.scheduleDestroy(this);
|
||||||
|
}
|
||||||
|
_cancel() {
|
||||||
|
this.status = 2 /* CANCELLED */;
|
||||||
|
const children = this.children;
|
||||||
|
for (let childKey in children) {
|
||||||
|
children[childKey]._cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
destroy() {
|
destroy() {
|
||||||
let shouldRemove = this.status === 1 /* MOUNTED */;
|
let shouldRemove = this.status === 1 /* MOUNTED */;
|
||||||
this._destroy();
|
this._destroy();
|
||||||
@@ -2455,7 +2464,7 @@ class ComponentNode {
|
|||||||
this.app.handleError({ error: e, node: this });
|
this.app.handleError({ error: e, node: this });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.status = 2 /* DESTROYED */;
|
this.status = 3 /* DESTROYED */;
|
||||||
}
|
}
|
||||||
async updateAndRender(props, parentFiber) {
|
async updateAndRender(props, parentFiber) {
|
||||||
this.nextProps = props;
|
this.nextProps = props;
|
||||||
@@ -2988,12 +2997,22 @@ function prepareList(collection) {
|
|||||||
keys = collection;
|
keys = collection;
|
||||||
values = collection;
|
values = collection;
|
||||||
}
|
}
|
||||||
else if (collection) {
|
else if (collection instanceof Map) {
|
||||||
values = Object.keys(collection);
|
keys = [...collection.keys()];
|
||||||
keys = Object.values(collection);
|
values = [...collection.values()];
|
||||||
|
}
|
||||||
|
else if (collection && typeof collection === "object") {
|
||||||
|
if (Symbol.iterator in collection) {
|
||||||
|
keys = [...collection];
|
||||||
|
values = keys;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
values = Object.keys(collection);
|
||||||
|
keys = Object.values(collection);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new OwlError("Invalid loop expression");
|
throw new OwlError(`Invalid loop expression: "${collection}" is not iterable`);
|
||||||
}
|
}
|
||||||
const n = values.length;
|
const n = values.length;
|
||||||
return [keys, values, n, new Array(n)];
|
return [keys, values, n, new Array(n)];
|
||||||
@@ -4936,10 +4955,8 @@ function parseDOMNode(node, ctx) {
|
|||||||
const typeAttr = node.getAttribute("type");
|
const typeAttr = node.getAttribute("type");
|
||||||
const isInput = tagName === "input";
|
const isInput = tagName === "input";
|
||||||
const isSelect = tagName === "select";
|
const isSelect = tagName === "select";
|
||||||
const isTextarea = tagName === "textarea";
|
|
||||||
const isCheckboxInput = isInput && typeAttr === "checkbox";
|
const isCheckboxInput = isInput && typeAttr === "checkbox";
|
||||||
const isRadioInput = isInput && typeAttr === "radio";
|
const isRadioInput = isInput && typeAttr === "radio";
|
||||||
const isOtherInput = isInput && !isCheckboxInput && !isRadioInput;
|
|
||||||
const hasLazyMod = attr.includes(".lazy");
|
const hasLazyMod = attr.includes(".lazy");
|
||||||
const hasNumberMod = attr.includes(".number");
|
const hasNumberMod = attr.includes(".number");
|
||||||
const hasTrimMod = attr.includes(".trim");
|
const hasTrimMod = attr.includes(".trim");
|
||||||
@@ -4951,8 +4968,8 @@ function parseDOMNode(node, ctx) {
|
|||||||
specialInitTargetAttr: isRadioInput ? "checked" : null,
|
specialInitTargetAttr: isRadioInput ? "checked" : null,
|
||||||
eventType,
|
eventType,
|
||||||
hasDynamicChildren: false,
|
hasDynamicChildren: false,
|
||||||
shouldTrim: hasTrimMod && (isOtherInput || isTextarea),
|
shouldTrim: hasTrimMod,
|
||||||
shouldNumberize: hasNumberMod && (isOtherInput || isTextarea),
|
shouldNumberize: hasNumberMod,
|
||||||
};
|
};
|
||||||
if (isSelect) {
|
if (isSelect) {
|
||||||
// don't pollute the original ctx
|
// don't pollute the original ctx
|
||||||
@@ -5535,7 +5552,7 @@ function compile(template, options = {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// do not modify manually. This file is generated by the release script.
|
// do not modify manually. This file is generated by the release script.
|
||||||
const version = "2.1.3";
|
const version = "2.1.4";
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Scheduler
|
// Scheduler
|
||||||
@@ -5545,11 +5562,18 @@ class Scheduler {
|
|||||||
this.tasks = new Set();
|
this.tasks = new Set();
|
||||||
this.frame = 0;
|
this.frame = 0;
|
||||||
this.delayedRenders = [];
|
this.delayedRenders = [];
|
||||||
|
this.cancelledNodes = new Set();
|
||||||
this.requestAnimationFrame = Scheduler.requestAnimationFrame;
|
this.requestAnimationFrame = Scheduler.requestAnimationFrame;
|
||||||
}
|
}
|
||||||
addFiber(fiber) {
|
addFiber(fiber) {
|
||||||
this.tasks.add(fiber.root);
|
this.tasks.add(fiber.root);
|
||||||
}
|
}
|
||||||
|
scheduleDestroy(node) {
|
||||||
|
this.cancelledNodes.add(node);
|
||||||
|
if (this.frame === 0) {
|
||||||
|
this.frame = this.requestAnimationFrame(() => this.processTasks());
|
||||||
|
}
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Process all current tasks. This only applies to the fibers that are ready.
|
* Process all current tasks. This only applies to the fibers that are ready.
|
||||||
* Other tasks are left unchanged.
|
* Other tasks are left unchanged.
|
||||||
@@ -5559,21 +5583,28 @@ class Scheduler {
|
|||||||
let renders = this.delayedRenders;
|
let renders = this.delayedRenders;
|
||||||
this.delayedRenders = [];
|
this.delayedRenders = [];
|
||||||
for (let f of renders) {
|
for (let f of renders) {
|
||||||
if (f.root && f.node.status !== 2 /* DESTROYED */ && f.node.fiber === f) {
|
if (f.root && f.node.status !== 3 /* DESTROYED */ && f.node.fiber === f) {
|
||||||
f.render();
|
f.render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.frame === 0) {
|
if (this.frame === 0) {
|
||||||
this.frame = this.requestAnimationFrame(() => {
|
this.frame = this.requestAnimationFrame(() => this.processTasks());
|
||||||
this.frame = 0;
|
}
|
||||||
this.tasks.forEach((fiber) => this.processFiber(fiber));
|
}
|
||||||
for (let task of this.tasks) {
|
processTasks() {
|
||||||
if (task.node.status === 2 /* DESTROYED */) {
|
this.frame = 0;
|
||||||
this.tasks.delete(task);
|
for (let node of this.cancelledNodes) {
|
||||||
}
|
node._destroy();
|
||||||
}
|
}
|
||||||
});
|
this.cancelledNodes.clear();
|
||||||
|
for (let task of this.tasks) {
|
||||||
|
this.processFiber(task);
|
||||||
|
}
|
||||||
|
for (let task of this.tasks) {
|
||||||
|
if (task.node.status === 3 /* DESTROYED */) {
|
||||||
|
this.tasks.delete(task);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
processFiber(fiber) {
|
processFiber(fiber) {
|
||||||
@@ -5586,7 +5617,7 @@ class Scheduler {
|
|||||||
this.tasks.delete(fiber);
|
this.tasks.delete(fiber);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (fiber.node.status === 2 /* DESTROYED */) {
|
if (fiber.node.status === 3 /* DESTROYED */) {
|
||||||
this.tasks.delete(fiber);
|
this.tasks.delete(fiber);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -5810,9 +5841,11 @@ function status(component) {
|
|||||||
switch (component.__owl__.status) {
|
switch (component.__owl__.status) {
|
||||||
case 0 /* NEW */:
|
case 0 /* NEW */:
|
||||||
return "new";
|
return "new";
|
||||||
|
case 2 /* CANCELLED */:
|
||||||
|
return "cancelled";
|
||||||
case 1 /* MOUNTED */:
|
case 1 /* MOUNTED */:
|
||||||
return "mounted";
|
return "mounted";
|
||||||
case 2 /* DESTROYED */:
|
case 3 /* DESTROYED */:
|
||||||
return "destroyed";
|
return "destroyed";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5952,6 +5985,6 @@ TemplateSet.prototype._compileTemplate = function _compileTemplate(name, templat
|
|||||||
export { App, Component, EventBus, OwlError, __info__, blockDom, loadFile, markRaw, markup, mount, onError, onMounted, onPatched, onRendered, onWillDestroy, onWillPatch, onWillRender, onWillStart, onWillUnmount, onWillUpdateProps, reactive, status, toRaw, useChildSubEnv, useComponent, useEffect, useEnv, useExternalListener, useRef, useState, useSubEnv, validate, validateType, whenReady, xml };
|
export { App, Component, EventBus, OwlError, __info__, blockDom, loadFile, markRaw, markup, mount, onError, onMounted, onPatched, onRendered, onWillDestroy, onWillPatch, onWillRender, onWillStart, onWillUnmount, onWillUpdateProps, reactive, status, toRaw, useChildSubEnv, useComponent, useEffect, useEnv, useExternalListener, useRef, useState, useSubEnv, validate, validateType, whenReady, xml };
|
||||||
|
|
||||||
|
|
||||||
__info__.date = '2023-06-28T09:17:13.630Z';
|
__info__.date = '2023-07-18T14:07:26.565Z';
|
||||||
__info__.hash = '432ff44';
|
__info__.hash = '836e12b';
|
||||||
__info__.url = 'https://github.com/odoo/owl';
|
__info__.url = 'https://github.com/odoo/owl';
|
||||||
|
|||||||
Generated
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@odoo/owl",
|
"name": "@odoo/owl",
|
||||||
"version": "2.1.4",
|
"version": "2.2",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@odoo/owl",
|
"name": "@odoo/owl",
|
||||||
"version": "2.1.4",
|
"version": "2.2",
|
||||||
"description": "Odoo Web Library (OWL)",
|
"description": "Odoo Web Library (OWL)",
|
||||||
"main": "dist/owl.cjs.js",
|
"main": "dist/owl.cjs.js",
|
||||||
"module": "dist/owl.es.js",
|
"module": "dist/owl.es.js",
|
||||||
|
|||||||
@@ -365,10 +365,8 @@ function parseDOMNode(node: Element, ctx: ParsingContext): AST | null {
|
|||||||
const typeAttr = node.getAttribute("type");
|
const typeAttr = node.getAttribute("type");
|
||||||
const isInput = tagName === "input";
|
const isInput = tagName === "input";
|
||||||
const isSelect = tagName === "select";
|
const isSelect = tagName === "select";
|
||||||
const isTextarea = tagName === "textarea";
|
|
||||||
const isCheckboxInput = isInput && typeAttr === "checkbox";
|
const isCheckboxInput = isInput && typeAttr === "checkbox";
|
||||||
const isRadioInput = isInput && typeAttr === "radio";
|
const isRadioInput = isInput && typeAttr === "radio";
|
||||||
const isOtherInput = isInput && !isCheckboxInput && !isRadioInput;
|
|
||||||
const hasLazyMod = attr.includes(".lazy");
|
const hasLazyMod = attr.includes(".lazy");
|
||||||
const hasNumberMod = attr.includes(".number");
|
const hasNumberMod = attr.includes(".number");
|
||||||
const hasTrimMod = attr.includes(".trim");
|
const hasTrimMod = attr.includes(".trim");
|
||||||
@@ -381,8 +379,8 @@ function parseDOMNode(node: Element, ctx: ParsingContext): AST | null {
|
|||||||
specialInitTargetAttr: isRadioInput ? "checked" : null,
|
specialInitTargetAttr: isRadioInput ? "checked" : null,
|
||||||
eventType,
|
eventType,
|
||||||
hasDynamicChildren: false,
|
hasDynamicChildren: false,
|
||||||
shouldTrim: hasTrimMod && (isOtherInput || isTextarea),
|
shouldTrim: hasTrimMod,
|
||||||
shouldNumberize: hasNumberMod && (isOtherInput || isTextarea),
|
shouldNumberize: hasNumberMod,
|
||||||
};
|
};
|
||||||
if (isSelect) {
|
if (isSelect) {
|
||||||
// don't pollute the original ctx
|
// don't pollute the original ctx
|
||||||
|
|||||||
@@ -145,6 +145,9 @@ export class ComponentNode<P extends Props = any, E = any> implements VNode<Comp
|
|||||||
}
|
}
|
||||||
|
|
||||||
async render(deep: boolean) {
|
async render(deep: boolean) {
|
||||||
|
if (this.status >= STATUS.CANCELLED) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
let current = this.fiber;
|
let current = this.fiber;
|
||||||
if (current && (current.root!.locked || (current as any).bdom === true)) {
|
if (current && (current.root!.locked || (current as any).bdom === true)) {
|
||||||
await Promise.resolve();
|
await Promise.resolve();
|
||||||
@@ -171,7 +174,7 @@ export class ComponentNode<P extends Props = any, E = any> implements VNode<Comp
|
|||||||
|
|
||||||
this.app.scheduler.addFiber(fiber);
|
this.app.scheduler.addFiber(fiber);
|
||||||
await Promise.resolve();
|
await Promise.resolve();
|
||||||
if (this.status === STATUS.DESTROYED) {
|
if (this.status >= STATUS.CANCELLED) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// We only want to actually render the component if the following two
|
// We only want to actually render the component if the following two
|
||||||
@@ -190,6 +193,20 @@ export class ComponentNode<P extends Props = any, E = any> implements VNode<Comp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cancel() {
|
||||||
|
this._cancel();
|
||||||
|
delete this.parent!.children[this.parentKey!];
|
||||||
|
this.app.scheduler.scheduleDestroy(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
_cancel() {
|
||||||
|
this.status = STATUS.CANCELLED;
|
||||||
|
const children = this.children;
|
||||||
|
for (let childKey in children) {
|
||||||
|
children[childKey]._cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
let shouldRemove = this.status === STATUS.MOUNTED;
|
let shouldRemove = this.status === STATUS.MOUNTED;
|
||||||
this._destroy();
|
this._destroy();
|
||||||
|
|||||||
@@ -51,17 +51,19 @@ export function handleError(params: ErrorParams) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
const node = "node" in params ? params.node : params.fiber.node;
|
const node = "node" in params ? params.node : params.fiber.node;
|
||||||
const fiber = "fiber" in params ? params.fiber : node.fiber!;
|
const fiber = "fiber" in params ? params.fiber : node.fiber;
|
||||||
|
|
||||||
// resets the fibers on components if possible. This is important so that
|
if (fiber) {
|
||||||
// new renderings can be properly included in the initial one, if any.
|
// resets the fibers on components if possible. This is important so that
|
||||||
let current: Fiber | null = fiber;
|
// new renderings can be properly included in the initial one, if any.
|
||||||
do {
|
let current: Fiber | null = fiber;
|
||||||
current.node.fiber = current;
|
do {
|
||||||
current = current.parent;
|
current.node.fiber = current;
|
||||||
} while (current);
|
current = current.parent;
|
||||||
|
} while (current);
|
||||||
|
|
||||||
fibersInError.set(fiber.root!, error);
|
fibersInError.set(fiber.root!, error);
|
||||||
|
}
|
||||||
|
|
||||||
const handled = _handleError(node, error);
|
const handled = _handleError(node, error);
|
||||||
if (!handled) {
|
if (!handled) {
|
||||||
|
|||||||
@@ -55,8 +55,7 @@ function cancelFibers(fibers: Fiber[]): number {
|
|||||||
let node = fiber.node;
|
let node = fiber.node;
|
||||||
fiber.render = throwOnRender;
|
fiber.render = throwOnRender;
|
||||||
if (node.status === STATUS.NEW) {
|
if (node.status === STATUS.NEW) {
|
||||||
node.destroy();
|
node.cancel();
|
||||||
delete node.parent!.children[node.parentKey!];
|
|
||||||
}
|
}
|
||||||
node.fiber = null;
|
node.fiber = null;
|
||||||
if (fiber.bdom) {
|
if (fiber.bdom) {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import type { ComponentNode } from "./component_node";
|
||||||
import { fibersInError } from "./error_handling";
|
import { fibersInError } from "./error_handling";
|
||||||
import { Fiber, RootFiber } from "./fibers";
|
import { Fiber, RootFiber } from "./fibers";
|
||||||
import { STATUS } from "./status";
|
import { STATUS } from "./status";
|
||||||
@@ -14,6 +15,7 @@ export class Scheduler {
|
|||||||
requestAnimationFrame: Window["requestAnimationFrame"];
|
requestAnimationFrame: Window["requestAnimationFrame"];
|
||||||
frame: number = 0;
|
frame: number = 0;
|
||||||
delayedRenders: Fiber[] = [];
|
delayedRenders: Fiber[] = [];
|
||||||
|
cancelledNodes: Set<ComponentNode> = new Set();
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.requestAnimationFrame = Scheduler.requestAnimationFrame;
|
this.requestAnimationFrame = Scheduler.requestAnimationFrame;
|
||||||
@@ -23,6 +25,13 @@ export class Scheduler {
|
|||||||
this.tasks.add(fiber.root!);
|
this.tasks.add(fiber.root!);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scheduleDestroy(node: ComponentNode) {
|
||||||
|
this.cancelledNodes.add(node);
|
||||||
|
if (this.frame === 0) {
|
||||||
|
this.frame = this.requestAnimationFrame(() => this.processTasks());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process all current tasks. This only applies to the fibers that are ready.
|
* Process all current tasks. This only applies to the fibers that are ready.
|
||||||
* Other tasks are left unchanged.
|
* Other tasks are left unchanged.
|
||||||
@@ -39,15 +48,23 @@ export class Scheduler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.frame === 0) {
|
if (this.frame === 0) {
|
||||||
this.frame = this.requestAnimationFrame(() => {
|
this.frame = this.requestAnimationFrame(() => this.processTasks());
|
||||||
this.frame = 0;
|
}
|
||||||
this.tasks.forEach((fiber) => this.processFiber(fiber));
|
}
|
||||||
for (let task of this.tasks) {
|
|
||||||
if (task.node.status === STATUS.DESTROYED) {
|
processTasks() {
|
||||||
this.tasks.delete(task);
|
this.frame = 0;
|
||||||
}
|
for (let node of this.cancelledNodes) {
|
||||||
}
|
node._destroy();
|
||||||
});
|
}
|
||||||
|
this.cancelledNodes.clear();
|
||||||
|
for (let task of this.tasks) {
|
||||||
|
this.processFiber(task);
|
||||||
|
}
|
||||||
|
for (let task of this.tasks) {
|
||||||
|
if (task.node.status === STATUS.DESTROYED) {
|
||||||
|
this.tasks.delete(task);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,15 +7,20 @@ import type { Component } from "./component";
|
|||||||
export const enum STATUS {
|
export const enum STATUS {
|
||||||
NEW,
|
NEW,
|
||||||
MOUNTED, // is ready, and in DOM. It has a valid el
|
MOUNTED, // is ready, and in DOM. It has a valid el
|
||||||
|
// component has been created, but has been replaced by a newer component before being mounted
|
||||||
|
// it is cancelled until the next animation frame where it will be destroyed
|
||||||
|
CANCELLED,
|
||||||
DESTROYED,
|
DESTROYED,
|
||||||
}
|
}
|
||||||
|
|
||||||
type STATUS_DESCR = "new" | "mounted" | "destroyed";
|
type STATUS_DESCR = "new" | "mounted" | "cancelled" | "destroyed";
|
||||||
|
|
||||||
export function status(component: Component): STATUS_DESCR {
|
export function status(component: Component): STATUS_DESCR {
|
||||||
switch (component.__owl__.status) {
|
switch (component.__owl__.status) {
|
||||||
case STATUS.NEW:
|
case STATUS.NEW:
|
||||||
return "new";
|
return "new";
|
||||||
|
case STATUS.CANCELLED:
|
||||||
|
return "cancelled";
|
||||||
case STATUS.MOUNTED:
|
case STATUS.MOUNTED:
|
||||||
return "mounted";
|
return "mounted";
|
||||||
case STATUS.DESTROYED:
|
case STATUS.DESTROYED:
|
||||||
|
|||||||
@@ -60,18 +60,26 @@ function withKey(elem: any, k: string) {
|
|||||||
return elem;
|
return elem;
|
||||||
}
|
}
|
||||||
|
|
||||||
function prepareList(collection: any): [any[], any[], number, any[]] {
|
function prepareList(collection: unknown): [unknown[], unknown[], number, undefined[]] {
|
||||||
let keys: any[];
|
let keys: unknown[];
|
||||||
let values: any[];
|
let values: unknown[];
|
||||||
|
|
||||||
if (Array.isArray(collection)) {
|
if (Array.isArray(collection)) {
|
||||||
keys = collection;
|
keys = collection;
|
||||||
values = collection;
|
values = collection;
|
||||||
} else if (collection) {
|
} else if (collection instanceof Map) {
|
||||||
values = Object.keys(collection);
|
keys = [...collection.keys()];
|
||||||
keys = Object.values(collection);
|
values = [...collection.values()];
|
||||||
|
} else if (collection && typeof collection === "object") {
|
||||||
|
if (Symbol.iterator in collection) {
|
||||||
|
keys = [...(<Iterable<unknown>>collection)];
|
||||||
|
values = keys;
|
||||||
|
} else {
|
||||||
|
values = Object.keys(collection);
|
||||||
|
keys = Object.values(collection);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new OwlError("Invalid loop expression");
|
throw new OwlError(`Invalid loop expression: "${collection}" is not iterable`);
|
||||||
}
|
}
|
||||||
const n = values.length;
|
const n = values.length;
|
||||||
return [keys, values, n, new Array(n)];
|
return [keys, values, n, new Array(n)];
|
||||||
|
|||||||
+7
-14
@@ -9,20 +9,13 @@ export type Callback = () => void;
|
|||||||
* @returns a batched version of the original callback
|
* @returns a batched version of the original callback
|
||||||
*/
|
*/
|
||||||
export function batched(callback: Callback): Callback {
|
export function batched(callback: Callback): Callback {
|
||||||
let called = false;
|
let scheduled = false;
|
||||||
return async () => {
|
return async (...args) => {
|
||||||
// This await blocks all calls to the callback here, then releases them sequentially
|
if (!scheduled) {
|
||||||
// in the next microtick. This line decides the granularity of the batch.
|
scheduled = true;
|
||||||
await Promise.resolve();
|
await Promise.resolve();
|
||||||
if (!called) {
|
scheduled = false;
|
||||||
called = true;
|
callback(...args);
|
||||||
// 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.
|
|
||||||
// Schedule this before calling the callback so that calls to the batched function
|
|
||||||
// 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();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,2 +1,2 @@
|
|||||||
// do not modify manually. This file is generated by the release script.
|
// do not modify manually. This file is generated by the release script.
|
||||||
export const version = "2.1.4";
|
export const version = "2.2";
|
||||||
|
|||||||
@@ -77,6 +77,62 @@ exports[`t-foreach iterate on items 1`] = `
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`t-foreach iterate, Map param 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { prepareList, withKey } = helpers;
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
const [k_block1, v_block1, l_block1, c_block1] = prepareList(ctx['value']);;
|
||||||
|
for (let i1 = 0; i1 < l_block1; i1++) {
|
||||||
|
ctx[\`item\`] = v_block1[i1];
|
||||||
|
ctx[\`item_index\`] = i1;
|
||||||
|
ctx[\`item_value\`] = k_block1[i1];
|
||||||
|
const key1 = ctx['item_index'];
|
||||||
|
const b3 = text(\` [\`);
|
||||||
|
const b4 = text(ctx['item_index']);
|
||||||
|
const b5 = text(\`: \`);
|
||||||
|
const b6 = text(ctx['item']);
|
||||||
|
const b7 = text(\` \`);
|
||||||
|
const b8 = text(ctx['item_value']);
|
||||||
|
const b9 = text(\`] \`);
|
||||||
|
c_block1[i1] = withKey(multi([b3, b4, b5, b6, b7, b8, b9]), key1);
|
||||||
|
}
|
||||||
|
return list(c_block1);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`t-foreach iterate, Set param 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { prepareList, withKey } = helpers;
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
const [k_block1, v_block1, l_block1, c_block1] = prepareList(ctx['value']);;
|
||||||
|
for (let i1 = 0; i1 < l_block1; i1++) {
|
||||||
|
ctx[\`item\`] = v_block1[i1];
|
||||||
|
ctx[\`item_index\`] = i1;
|
||||||
|
ctx[\`item_value\`] = k_block1[i1];
|
||||||
|
const key1 = ctx['item_index'];
|
||||||
|
const b3 = text(\` [\`);
|
||||||
|
const b4 = text(ctx['item_index']);
|
||||||
|
const b5 = text(\`: \`);
|
||||||
|
const b6 = text(ctx['item']);
|
||||||
|
const b7 = text(\` \`);
|
||||||
|
const b8 = text(ctx['item_value']);
|
||||||
|
const b9 = text(\`] \`);
|
||||||
|
c_block1[i1] = withKey(multi([b3, b4, b5, b6, b7, b8, b9]), key1);
|
||||||
|
}
|
||||||
|
return list(c_block1);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`t-foreach iterate, dict param 1`] = `
|
exports[`t-foreach iterate, dict param 1`] = `
|
||||||
"function anonymous(app, bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
@@ -108,6 +164,62 @@ exports[`t-foreach iterate, dict param 1`] = `
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`t-foreach iterate, generator param 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { prepareList, withKey } = helpers;
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
const [k_block1, v_block1, l_block1, c_block1] = prepareList(ctx['gen']());;
|
||||||
|
for (let i1 = 0; i1 < l_block1; i1++) {
|
||||||
|
ctx[\`item\`] = v_block1[i1];
|
||||||
|
ctx[\`item_index\`] = i1;
|
||||||
|
ctx[\`item_value\`] = k_block1[i1];
|
||||||
|
const key1 = ctx['item_index'];
|
||||||
|
const b3 = text(\` [\`);
|
||||||
|
const b4 = text(ctx['item_index']);
|
||||||
|
const b5 = text(\`: \`);
|
||||||
|
const b6 = text(ctx['item']);
|
||||||
|
const b7 = text(\` \`);
|
||||||
|
const b8 = text(ctx['item_value']);
|
||||||
|
const b9 = text(\`] \`);
|
||||||
|
c_block1[i1] = withKey(multi([b3, b4, b5, b6, b7, b8, b9]), key1);
|
||||||
|
}
|
||||||
|
return list(c_block1);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`t-foreach iterate, iterable param 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { prepareList, withKey } = helpers;
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
const [k_block1, v_block1, l_block1, c_block1] = prepareList(ctx['map'].values());;
|
||||||
|
for (let i1 = 0; i1 < l_block1; i1++) {
|
||||||
|
ctx[\`item\`] = v_block1[i1];
|
||||||
|
ctx[\`item_index\`] = i1;
|
||||||
|
ctx[\`item_value\`] = k_block1[i1];
|
||||||
|
const key1 = ctx['item_index'];
|
||||||
|
const b3 = text(\` [\`);
|
||||||
|
const b4 = text(ctx['item_index']);
|
||||||
|
const b5 = text(\`: \`);
|
||||||
|
const b6 = text(ctx['item']);
|
||||||
|
const b7 = text(\` \`);
|
||||||
|
const b8 = text(ctx['item_value']);
|
||||||
|
const b9 = text(\`] \`);
|
||||||
|
c_block1[i1] = withKey(multi([b3, b4, b5, b6, b7, b8, b9]), key1);
|
||||||
|
}
|
||||||
|
return list(c_block1);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`t-foreach iterate, position 1`] = `
|
exports[`t-foreach iterate, position 1`] = `
|
||||||
"function anonymous(app, bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -1991,8 +1991,8 @@ describe("qweb parser", () => {
|
|||||||
baseExpr: "state",
|
baseExpr: "state",
|
||||||
expr: "'stuff'",
|
expr: "'stuff'",
|
||||||
eventType: "click",
|
eventType: "click",
|
||||||
shouldNumberize: false,
|
shouldNumberize: true,
|
||||||
shouldTrim: false,
|
shouldTrim: true,
|
||||||
targetAttr: "value",
|
targetAttr: "value",
|
||||||
hasDynamicChildren: false,
|
hasDynamicChildren: false,
|
||||||
specialInitTargetAttr: "checked",
|
specialInitTargetAttr: "checked",
|
||||||
|
|||||||
@@ -105,6 +105,64 @@ describe("t-foreach", () => {
|
|||||||
expect(renderToString(template, context)).toBe(expected);
|
expect(renderToString(template, context)).toBe(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("iterate, Map param", () => {
|
||||||
|
const template = `
|
||||||
|
<t t-foreach="value" t-as="item" t-key="item_index">
|
||||||
|
[<t t-esc="item_index"/>: <t t-esc="item"/> <t t-esc="item_value"/>]
|
||||||
|
</t>`;
|
||||||
|
const expected = ` [0: 1 a] [1: 2 b] [2: 3 c] `;
|
||||||
|
const context = {
|
||||||
|
value: new Map([
|
||||||
|
["a", 1],
|
||||||
|
["b", 2],
|
||||||
|
["c", 3],
|
||||||
|
]),
|
||||||
|
};
|
||||||
|
expect(renderToString(template, context)).toBe(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("iterate, Set param", () => {
|
||||||
|
const template = `
|
||||||
|
<t t-foreach="value" t-as="item" t-key="item_index">
|
||||||
|
[<t t-esc="item_index"/>: <t t-esc="item"/> <t t-esc="item_value"/>]
|
||||||
|
</t>`;
|
||||||
|
const expected = ` [0: 1 1] [1: 2 2] [2: 3 3] `;
|
||||||
|
const context = { value: new Set([1, 2, 3]) };
|
||||||
|
expect(renderToString(template, context)).toBe(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("iterate, iterable param", () => {
|
||||||
|
const template = `
|
||||||
|
<t t-foreach="map.values()" t-as="item" t-key="item_index">
|
||||||
|
[<t t-esc="item_index"/>: <t t-esc="item"/> <t t-esc="item_value"/>]
|
||||||
|
</t>`;
|
||||||
|
const expected = ` [0: 1 1] [1: 2 2] [2: 3 3] `;
|
||||||
|
const context = {
|
||||||
|
map: new Map([
|
||||||
|
["a", 1],
|
||||||
|
["b", 2],
|
||||||
|
["c", 3],
|
||||||
|
]),
|
||||||
|
};
|
||||||
|
expect(renderToString(template, context)).toBe(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("iterate, generator param", () => {
|
||||||
|
const template = `
|
||||||
|
<t t-foreach="gen()" t-as="item" t-key="item_index">
|
||||||
|
[<t t-esc="item_index"/>: <t t-esc="item"/> <t t-esc="item_value"/>]
|
||||||
|
</t>`;
|
||||||
|
const expected = ` [0: 1 1] [1: 2 2] [2: 3 3] `;
|
||||||
|
const context = {
|
||||||
|
*gen() {
|
||||||
|
yield 1;
|
||||||
|
yield 2;
|
||||||
|
yield 3;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
expect(renderToString(template, context)).toBe(expected);
|
||||||
|
});
|
||||||
|
|
||||||
test("does not pollute the rendering context", () => {
|
test("does not pollute the rendering context", () => {
|
||||||
const template = `
|
const template = `
|
||||||
<div>
|
<div>
|
||||||
@@ -193,7 +251,9 @@ describe("t-foreach", () => {
|
|||||||
|
|
||||||
test("throws error if invalid loop expression", () => {
|
test("throws error if invalid loop expression", () => {
|
||||||
const test = `<div><t t-foreach="abc" t-as="item" t-key="item"><span t-key="item_index"/></t></div>`;
|
const test = `<div><t t-foreach="abc" t-as="item" t-key="item"><span t-key="item_index"/></t></div>`;
|
||||||
expect(() => renderToString(test)).toThrow("Invalid loop expression");
|
expect(() => renderToString(test)).toThrow(
|
||||||
|
'Invalid loop expression: "undefined" is not iterable'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("t-foreach with t-if inside", () => {
|
test("t-foreach with t-if inside", () => {
|
||||||
|
|||||||
@@ -212,6 +212,73 @@ exports[`changing state before first render does not trigger a render 1`] = `
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`component destroyed just after render 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
const comp1 = app.createComponent(\`B\`, true, false, false, []);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
return comp1({}, key + \`__1\`, node, this, null);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`component destroyed just after render 2`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
const b2 = text(\`B\`);
|
||||||
|
const b3 = text(ctx['state'].value);
|
||||||
|
return multi([b2, b3]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`components are not destroyed between animation frame 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
const comp1 = app.createComponent(\`B\`, true, false, false, []);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
let b2,b3;
|
||||||
|
b2 = text(\`A\`);
|
||||||
|
if (ctx['state'].flag) {
|
||||||
|
b3 = comp1({}, key + \`__1\`, node, this, null);
|
||||||
|
}
|
||||||
|
return multi([b2, b3]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`components are not destroyed between animation frame 2`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
const comp1 = app.createComponent(\`C\`, true, false, false, []);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
const b2 = text(\`B\`);
|
||||||
|
const b3 = comp1({}, key + \`__1\`, node, this, null);
|
||||||
|
return multi([b2, b3]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`components are not destroyed between animation frame 3`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
return text(\`C\`);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`concurrent renderings scenario 1 1`] = `
|
exports[`concurrent renderings scenario 1 1`] = `
|
||||||
"function anonymous(app, bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -468,6 +468,36 @@ exports[`t-model directive t-model on select with static options 1`] = `
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`t-model directive t-model with dynamic number values on select options in foreach 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { toNumber, prepareList, withKey } = helpers;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<select block-handler-0=\\"change\\"><block-child-0/></select>\`);
|
||||||
|
let block3 = createBlock(\`<option block-attribute-0=\\"value\\" block-attribute-1=\\"selected\\"><block-text-2/></option>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
const bExpr1 = ctx['state'];
|
||||||
|
const expr1 = 'value';
|
||||||
|
const bValue1 = bExpr1[expr1];
|
||||||
|
let hdlr1 = [(ev) => { bExpr1[expr1] = toNumber(ev.target.value); }];
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['state'].options);;
|
||||||
|
for (let i1 = 0; i1 < l_block2; i1++) {
|
||||||
|
ctx[\`o\`] = v_block2[i1];
|
||||||
|
const key1 = ctx['o'].value;
|
||||||
|
let attr1 = ctx['o'].value;
|
||||||
|
let attr2 = bValue1 === ctx['o'].value;
|
||||||
|
let txt1 = ctx['o'].value;
|
||||||
|
c_block2[i1] = withKey(block3([attr1, attr2, txt1]), key1);
|
||||||
|
}
|
||||||
|
const b2 = list(c_block2);
|
||||||
|
return block1([hdlr1], [b2]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`t-model directive t-model with dynamic values on select options -- 2 1`] = `
|
exports[`t-model directive t-model with dynamic values on select options -- 2 1`] = `
|
||||||
"function anonymous(app, bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -115,13 +115,7 @@ test("destroying/recreating a subwidget with different props (if start is not ov
|
|||||||
await nextMicroTick();
|
await nextMicroTick();
|
||||||
expect(n).toBe(2);
|
expect(n).toBe(2);
|
||||||
|
|
||||||
expect([
|
expect(["W:willRender", "Child:setup", "Child:willStart", "W:rendered"]).toBeLogged();
|
||||||
"Child:willDestroy",
|
|
||||||
"W:willRender",
|
|
||||||
"Child:setup",
|
|
||||||
"Child:willStart",
|
|
||||||
"W:rendered",
|
|
||||||
]).toBeLogged();
|
|
||||||
|
|
||||||
def.resolve();
|
def.resolve();
|
||||||
await nextTick();
|
await nextTick();
|
||||||
@@ -130,6 +124,7 @@ test("destroying/recreating a subwidget with different props (if start is not ov
|
|||||||
expect([
|
expect([
|
||||||
"Child:willRender",
|
"Child:willRender",
|
||||||
"Child:rendered",
|
"Child:rendered",
|
||||||
|
"Child:willDestroy",
|
||||||
"W:willPatch",
|
"W:willPatch",
|
||||||
"Child:mounted",
|
"Child:mounted",
|
||||||
"W:patched",
|
"W:patched",
|
||||||
@@ -178,13 +173,13 @@ test("destroying/recreating a subcomponent, other scenario", async () => {
|
|||||||
"Child:setup",
|
"Child:setup",
|
||||||
"Child:willStart",
|
"Child:willStart",
|
||||||
"Parent:rendered",
|
"Parent:rendered",
|
||||||
"Child:willDestroy",
|
|
||||||
"Parent:willRender",
|
"Parent:willRender",
|
||||||
"Child:setup",
|
"Child:setup",
|
||||||
"Child:willStart",
|
"Child:willStart",
|
||||||
"Parent:rendered",
|
"Parent:rendered",
|
||||||
"Child:willRender",
|
"Child:willRender",
|
||||||
"Child:rendered",
|
"Child:rendered",
|
||||||
|
"Child:willDestroy",
|
||||||
"Parent:willPatch",
|
"Parent:willPatch",
|
||||||
"Child:mounted",
|
"Child:mounted",
|
||||||
"Parent:patched",
|
"Parent:patched",
|
||||||
@@ -251,13 +246,13 @@ test("creating two async components, scenario 1", async () => {
|
|||||||
await nextTick();
|
await nextTick();
|
||||||
expect(fixture.innerHTML).toBe("");
|
expect(fixture.innerHTML).toBe("");
|
||||||
expect([
|
expect([
|
||||||
"ChildA:willDestroy",
|
|
||||||
"Parent:willRender",
|
"Parent:willRender",
|
||||||
"ChildA:setup",
|
"ChildA:setup",
|
||||||
"ChildA:willStart",
|
"ChildA:willStart",
|
||||||
"ChildB:setup",
|
"ChildB:setup",
|
||||||
"ChildB:willStart",
|
"ChildB:willStart",
|
||||||
"Parent:rendered",
|
"Parent:rendered",
|
||||||
|
"ChildA:willDestroy",
|
||||||
]).toBeLogged();
|
]).toBeLogged();
|
||||||
|
|
||||||
defB.resolve();
|
defB.resolve();
|
||||||
@@ -703,13 +698,13 @@ test("rendering component again in next microtick", async () => {
|
|||||||
"Child:setup",
|
"Child:setup",
|
||||||
"Child:willStart",
|
"Child:willStart",
|
||||||
"Parent:rendered",
|
"Parent:rendered",
|
||||||
"Child:willDestroy",
|
|
||||||
"Parent:willRender",
|
"Parent:willRender",
|
||||||
"Child:setup",
|
"Child:setup",
|
||||||
"Child:willStart",
|
"Child:willStart",
|
||||||
"Parent:rendered",
|
"Parent:rendered",
|
||||||
"Child:willRender",
|
"Child:willRender",
|
||||||
"Child:rendered",
|
"Child:rendered",
|
||||||
|
"Child:willDestroy",
|
||||||
"Parent:willPatch",
|
"Parent:willPatch",
|
||||||
"Child:mounted",
|
"Child:mounted",
|
||||||
"Parent:patched",
|
"Parent:patched",
|
||||||
@@ -1732,9 +1727,9 @@ test("concurrent renderings scenario 10", async () => {
|
|||||||
expect(fixture.innerHTML).toBe("<div><p></p></div>");
|
expect(fixture.innerHTML).toBe("<div><p></p></div>");
|
||||||
expect([
|
expect([
|
||||||
"ComponentA:willRender",
|
"ComponentA:willRender",
|
||||||
"ComponentC:willDestroy",
|
|
||||||
"ComponentB:willUpdateProps",
|
"ComponentB:willUpdateProps",
|
||||||
"ComponentA:rendered",
|
"ComponentA:rendered",
|
||||||
|
"ComponentC:willDestroy",
|
||||||
]).toBeLogged();
|
]).toBeLogged();
|
||||||
|
|
||||||
defB.resolve();
|
defB.resolve();
|
||||||
@@ -2282,7 +2277,6 @@ test("concurrent renderings scenario 16", async () => {
|
|||||||
"D:setup",
|
"D:setup",
|
||||||
"D:willStart",
|
"D:willStart",
|
||||||
"C:rendered",
|
"C:rendered",
|
||||||
"D:willDestroy",
|
|
||||||
"B:willRender",
|
"B:willRender",
|
||||||
"C:willUpdateProps",
|
"C:willUpdateProps",
|
||||||
"B:rendered",
|
"B:rendered",
|
||||||
@@ -2290,6 +2284,7 @@ test("concurrent renderings scenario 16", async () => {
|
|||||||
"D:setup",
|
"D:setup",
|
||||||
"D:willStart",
|
"D:willStart",
|
||||||
"C:rendered",
|
"C:rendered",
|
||||||
|
"D:willDestroy",
|
||||||
]).toBeLogged();
|
]).toBeLogged();
|
||||||
|
|
||||||
// at this point, C rendering is still pending, and nothing should have been
|
// at this point, C rendering is still pending, and nothing should have been
|
||||||
@@ -2997,11 +2992,11 @@ test("t-key on dom node having a component", async () => {
|
|||||||
|
|
||||||
expect(fixture.innerHTML).toBe("<div>3</div>");
|
expect(fixture.innerHTML).toBe("<div>3</div>");
|
||||||
expect([
|
expect([
|
||||||
"Child (2):willDestroy",
|
|
||||||
"Child (3):setup",
|
"Child (3):setup",
|
||||||
"Child (3):willStart",
|
"Child (3):willStart",
|
||||||
"Child (3):willRender",
|
"Child (3):willRender",
|
||||||
"Child (3):rendered",
|
"Child (3):rendered",
|
||||||
|
"Child (2):willDestroy",
|
||||||
"Child (1):willUnmount",
|
"Child (1):willUnmount",
|
||||||
"Child (1):willDestroy",
|
"Child (1):willDestroy",
|
||||||
"Child (3):mounted",
|
"Child (3):mounted",
|
||||||
@@ -3055,11 +3050,11 @@ test("t-key on dynamic async component (toggler is never patched)", async () =>
|
|||||||
|
|
||||||
expect(fixture.innerHTML).toBe("<div>3</div>");
|
expect(fixture.innerHTML).toBe("<div>3</div>");
|
||||||
expect([
|
expect([
|
||||||
"Child (2):willDestroy",
|
|
||||||
"Child (3):setup",
|
"Child (3):setup",
|
||||||
"Child (3):willStart",
|
"Child (3):willStart",
|
||||||
"Child (3):willRender",
|
"Child (3):willRender",
|
||||||
"Child (3):rendered",
|
"Child (3):rendered",
|
||||||
|
"Child (2):willDestroy",
|
||||||
"Child (1):willUnmount",
|
"Child (1):willUnmount",
|
||||||
"Child (1):willDestroy",
|
"Child (1):willDestroy",
|
||||||
"Child (3):mounted",
|
"Child (3):mounted",
|
||||||
@@ -3114,11 +3109,11 @@ test("t-foreach with dynamic async component", async () => {
|
|||||||
|
|
||||||
expect(fixture.innerHTML).toBe("<div>3</div>");
|
expect(fixture.innerHTML).toBe("<div>3</div>");
|
||||||
expect([
|
expect([
|
||||||
"Child (2):willDestroy",
|
|
||||||
"Child (3):setup",
|
"Child (3):setup",
|
||||||
"Child (3):willStart",
|
"Child (3):willStart",
|
||||||
"Child (3):willRender",
|
"Child (3):willRender",
|
||||||
"Child (3):rendered",
|
"Child (3):rendered",
|
||||||
|
"Child (2):willDestroy",
|
||||||
"Child (1):willUnmount",
|
"Child (1):willUnmount",
|
||||||
"Child (1):willDestroy",
|
"Child (1):willDestroy",
|
||||||
"Child (3):mounted",
|
"Child (3):mounted",
|
||||||
@@ -3801,7 +3796,7 @@ test("destroyed component causes other soon to be destroyed component to rerende
|
|||||||
static template = xml`<t t-esc="state.val + props.value"/>`;
|
static template = xml`<t t-esc="state.val + props.value"/>`;
|
||||||
state = useState({ val: 0 });
|
state = useState({ val: 0 });
|
||||||
setup() {
|
setup() {
|
||||||
c = this;
|
c = c || this;
|
||||||
useLogLifecycle();
|
useLogLifecycle();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3846,8 +3841,6 @@ test("destroyed component causes other soon to be destroyed component to rerende
|
|||||||
parent.state.valueB = 2;
|
parent.state.valueB = 2;
|
||||||
await nextTick();
|
await nextTick();
|
||||||
expect([
|
expect([
|
||||||
"B:willDestroy",
|
|
||||||
"C:willDestroy",
|
|
||||||
"A:willRender",
|
"A:willRender",
|
||||||
"B:setup",
|
"B:setup",
|
||||||
"B:willStart",
|
"B:willStart",
|
||||||
@@ -3858,6 +3851,8 @@ test("destroyed component causes other soon to be destroyed component to rerende
|
|||||||
"B:rendered",
|
"B:rendered",
|
||||||
"C:willRender",
|
"C:willRender",
|
||||||
"C:rendered",
|
"C:rendered",
|
||||||
|
"B:willDestroy",
|
||||||
|
"C:willDestroy",
|
||||||
"A:willPatch",
|
"A:willPatch",
|
||||||
"C:mounted",
|
"C:mounted",
|
||||||
"B:mounted",
|
"B:mounted",
|
||||||
@@ -4200,6 +4195,116 @@ test("delayed render is not cancelled by upcoming render", async () => {
|
|||||||
]).toBeLogged();
|
]).toBeLogged();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("components are not destroyed between animation frame", async () => {
|
||||||
|
const def = makeDeferred();
|
||||||
|
class C extends Component {
|
||||||
|
static template = xml`C`;
|
||||||
|
setup() {
|
||||||
|
useLogLifecycle();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class B extends Component {
|
||||||
|
static template = xml`B<C/>`;
|
||||||
|
static components = { C };
|
||||||
|
setup() {
|
||||||
|
useLogLifecycle();
|
||||||
|
onWillStart(() => {
|
||||||
|
return def;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class A extends Component {
|
||||||
|
static template = xml`A<B t-if="state.flag"/>`;
|
||||||
|
static components = { B };
|
||||||
|
|
||||||
|
state = useState({ flag: false });
|
||||||
|
setup() {
|
||||||
|
useLogLifecycle();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const a = await mount(A, fixture);
|
||||||
|
expect(fixture.innerHTML).toBe("A");
|
||||||
|
expect(["A:setup", "A:willStart", "A:willRender", "A:rendered", "A:mounted"]).toBeLogged();
|
||||||
|
|
||||||
|
// turn the flag on, this will render A and stops at B because of def
|
||||||
|
a.state.flag = true;
|
||||||
|
await nextTick();
|
||||||
|
expect(["A:willRender", "B:setup", "B:willStart", "A:rendered"]).toBeLogged();
|
||||||
|
|
||||||
|
// force a render of A
|
||||||
|
// => owl will need to create a new B component
|
||||||
|
// => initial B component will be cancelled
|
||||||
|
a.render();
|
||||||
|
await nextMicroTick();
|
||||||
|
expect([
|
||||||
|
// note that B is not destroyed here. It is cancelled instead
|
||||||
|
"A:willRender",
|
||||||
|
"B:setup",
|
||||||
|
"B:willStart",
|
||||||
|
"A:rendered",
|
||||||
|
]).toBeLogged();
|
||||||
|
|
||||||
|
// resolve def, so B render is unblocked
|
||||||
|
def.resolve();
|
||||||
|
await nextTick();
|
||||||
|
expect([
|
||||||
|
"B:willRender",
|
||||||
|
"C:setup",
|
||||||
|
"C:willStart",
|
||||||
|
"B:rendered",
|
||||||
|
"C:willRender",
|
||||||
|
"C:rendered",
|
||||||
|
// animation frame callback starts here
|
||||||
|
"B:willDestroy", // B is destroyed here
|
||||||
|
"A:willPatch",
|
||||||
|
"C:mounted",
|
||||||
|
"B:mounted",
|
||||||
|
"A:patched",
|
||||||
|
]).toBeLogged();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("component destroyed just after render", async () => {
|
||||||
|
let stateB: any;
|
||||||
|
|
||||||
|
class B extends Component {
|
||||||
|
static template = xml`B<t t-esc="state.value"/>`;
|
||||||
|
state = useState({ value: 1 });
|
||||||
|
setup() {
|
||||||
|
stateB = this.state;
|
||||||
|
useLogLifecycle();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class A extends Component {
|
||||||
|
static template = xml`<B/>`;
|
||||||
|
static components = { B };
|
||||||
|
setup() {
|
||||||
|
useLogLifecycle();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const a = await mount(A, fixture);
|
||||||
|
expect(fixture.innerHTML).toBe("B1");
|
||||||
|
expect([
|
||||||
|
"A:setup",
|
||||||
|
"A:willStart",
|
||||||
|
"A:willRender",
|
||||||
|
"B:setup",
|
||||||
|
"B:willStart",
|
||||||
|
"A:rendered",
|
||||||
|
"B:willRender",
|
||||||
|
"B:rendered",
|
||||||
|
"B:mounted",
|
||||||
|
"A:mounted",
|
||||||
|
]).toBeLogged();
|
||||||
|
|
||||||
|
stateB!.value++; // force a render of B
|
||||||
|
await nextMicroTick(); // wait for B render to actually start
|
||||||
|
a.__owl__.app.destroy();
|
||||||
|
expect(["A:willUnmount", "B:willUnmount", "B:willDestroy", "A:willDestroy"]).toBeLogged();
|
||||||
|
await nextTick();
|
||||||
|
// check that B was not rendered after being destroyed
|
||||||
|
expect([]).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 };
|
||||||
|
|
||||||
|
|||||||
@@ -1444,6 +1444,7 @@ describe("can catch errors", () => {
|
|||||||
"Parent:willPatch",
|
"Parent:willPatch",
|
||||||
"Child:willUnmount",
|
"Child:willUnmount",
|
||||||
"Child:willDestroy",
|
"Child:willDestroy",
|
||||||
|
"Parent:patched",
|
||||||
"Parent:willRender",
|
"Parent:willRender",
|
||||||
"Parent:rendered",
|
"Parent:rendered",
|
||||||
"Parent:willPatch",
|
"Parent:willPatch",
|
||||||
@@ -1506,12 +1507,15 @@ describe("can catch errors", () => {
|
|||||||
parent.state.hasChild = false;
|
parent.state.hasChild = false;
|
||||||
await nextTick();
|
await nextTick();
|
||||||
expect([
|
expect([
|
||||||
|
"Parent:willRender",
|
||||||
|
"Parent:rendered",
|
||||||
"Child:willDestroy",
|
"Child:willDestroy",
|
||||||
"Parent:willRender",
|
"Parent:willRender",
|
||||||
"Parent:rendered",
|
"Parent:rendered",
|
||||||
"Parent:willPatch",
|
|
||||||
"Parent:patched",
|
|
||||||
]).toBeLogged();
|
]).toBeLogged();
|
||||||
|
expect(fixture.innerHTML).toBe("1");
|
||||||
|
await nextTick();
|
||||||
|
expect(["Parent:willPatch", "Parent:patched"]).toBeLogged();
|
||||||
expect(fixture.innerHTML).toBe("2");
|
expect(fixture.innerHTML).toBe("2");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -626,6 +626,39 @@ describe("t-model directive", () => {
|
|||||||
expect(fixture.querySelector("select")!.value).toEqual("b");
|
expect(fixture.querySelector("select")!.value).toEqual("b");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("t-model with dynamic number values on select options in foreach", async () => {
|
||||||
|
class Test extends Component {
|
||||||
|
static template = xml`
|
||||||
|
<select t-model.number="state.value">
|
||||||
|
<t t-foreach="state.options" t-as="o" t-key="o.value">
|
||||||
|
<option t-att-value="o.value" t-esc="o.value"/>
|
||||||
|
</t>
|
||||||
|
</select>
|
||||||
|
`;
|
||||||
|
state: any;
|
||||||
|
setup() {
|
||||||
|
this.state = useState({
|
||||||
|
value: 2,
|
||||||
|
options: [{ value: 1 }, { value: 2 }, { value: 3 }],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const comp = await mount(Test, fixture);
|
||||||
|
// check that we have a value of 2 selected
|
||||||
|
expect(fixture.querySelector("select")!.value).toEqual("2");
|
||||||
|
expect(comp.state.value).toBe(2);
|
||||||
|
|
||||||
|
// emulate a click on the option=3 element
|
||||||
|
fixture.querySelectorAll("option")[2].selected = true;
|
||||||
|
fixture.querySelector("select")!.dispatchEvent(new Event("change"));
|
||||||
|
|
||||||
|
await nextTick();
|
||||||
|
// check that we have now selected the number 3 (and not the string)
|
||||||
|
expect(fixture.querySelector("select")!.value).toEqual("3");
|
||||||
|
expect(comp.state.value).toBe(3);
|
||||||
|
});
|
||||||
|
|
||||||
test("t-model is applied before t-on-input", async () => {
|
test("t-model is applied before t-on-input", async () => {
|
||||||
expect.assertions(3);
|
expect.assertions(3);
|
||||||
class SomeComponent extends Component {
|
class SomeComponent extends Component {
|
||||||
|
|||||||
+1
-1
@@ -47,7 +47,7 @@ export class ObjectTreeElement extends Component {
|
|||||||
|
|
||||||
classFor(object) {
|
classFor(object) {
|
||||||
// Prototype items will be dyed down to appear less important
|
// Prototype items will be dyed down to appear less important
|
||||||
if (object.path.some((item) => item?.type === "prototype")) {
|
if (object.path.some((item) => item?.type === "prototype") && !object.keepLit) {
|
||||||
return "attenuate";
|
return "attenuate";
|
||||||
}
|
}
|
||||||
// Same for subscription items which are not present in the keys while the keys will be bold
|
// Same for subscription items which are not present in the keys while the keys will be bold
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ export const store = reactive({
|
|||||||
if (IS_FIREFOX) {
|
if (IS_FIREFOX) {
|
||||||
await evalInWindow("window.$0 = $0;", this.activeFrame);
|
await evalInWindow("window.$0 = $0;", this.activeFrame);
|
||||||
}
|
}
|
||||||
const [apps, component] = await evalFunctionInWindow(
|
const [apps, details] = await evalFunctionInWindow(
|
||||||
"getComponentsTree",
|
"getComponentsTree",
|
||||||
fromOld && this.activeComponent
|
fromOld && this.activeComponent
|
||||||
? [this.activeComponent.path, this.apps, this.activeComponent]
|
? [this.activeComponent.path, this.apps, this.activeComponent]
|
||||||
@@ -113,7 +113,8 @@ export const store = reactive({
|
|||||||
if (!fromOld && this.settings.expandByDefault) {
|
if (!fromOld && this.settings.expandByDefault) {
|
||||||
this.apps.forEach((tree) => expandNodes(tree, true));
|
this.apps.forEach((tree) => expandNodes(tree, true));
|
||||||
}
|
}
|
||||||
this.activeComponent = component;
|
keepEnvLit(details);
|
||||||
|
this.activeComponent = details;
|
||||||
},
|
},
|
||||||
|
|
||||||
// Select a component by retrieving its details from the page based on its path
|
// Select a component by retrieving its details from the page based on its path
|
||||||
@@ -150,9 +151,11 @@ export const store = reactive({
|
|||||||
[component.path],
|
[component.path],
|
||||||
this.activeFrame
|
this.activeFrame
|
||||||
);
|
);
|
||||||
this.activeComponent = details;
|
if (!details) {
|
||||||
if (!this.activeComponent) {
|
|
||||||
await this.loadComponentsTree(false);
|
await this.loadComponentsTree(false);
|
||||||
|
} else {
|
||||||
|
keepEnvLit(details);
|
||||||
|
this.activeComponent = details;
|
||||||
}
|
}
|
||||||
if (this.page !== "ComponentsTab") {
|
if (this.page !== "ComponentsTab") {
|
||||||
this.switchTab("ComponentsTab");
|
this.switchTab("ComponentsTab");
|
||||||
@@ -887,6 +890,31 @@ function expandNodes(node, blacklist = false) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This function transforms the env part of the details such that all env keys are not
|
||||||
|
// greyed out in the UI at their first occurence
|
||||||
|
function keepEnvLit(details) {
|
||||||
|
let alreadyMet = new Set();
|
||||||
|
for (let i = 0; i < details.env.children.length; i++) {
|
||||||
|
if (i < details.env.children.length - 1) {
|
||||||
|
alreadyMet.add(details.env.children[i].name);
|
||||||
|
} else {
|
||||||
|
let lastElement = details.env.children[i];
|
||||||
|
while (lastElement.children.at(-1).name === "[[Prototype]]") {
|
||||||
|
for (const [index, child] of lastElement.children.entries()) {
|
||||||
|
if (index < lastElement.children.length - 1) {
|
||||||
|
if (!alreadyMet.has(child.name)) {
|
||||||
|
child.keepLit = true;
|
||||||
|
alreadyMet.add(child.name);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
lastElement = child;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Fold the node given in entry and all of its children
|
// Fold the node given in entry and all of its children
|
||||||
function foldNodes(node) {
|
function foldNodes(node) {
|
||||||
node.toggled = false;
|
node.toggled = false;
|
||||||
|
|||||||
@@ -117,6 +117,15 @@
|
|||||||
length += element.length;
|
length += element.length;
|
||||||
result.push(element);
|
result.push(element);
|
||||||
}
|
}
|
||||||
|
for (const key of Object.getOwnPropertySymbols(obj)) {
|
||||||
|
if (length > 25) {
|
||||||
|
result.push("...");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
const element = key.toString() + ": " + this.serializeItem(obj[key]);
|
||||||
|
length += element.length;
|
||||||
|
result.push(element);
|
||||||
|
}
|
||||||
return "{" + result.join(", ") + "}";
|
return "{" + result.join(", ") + "}";
|
||||||
},
|
},
|
||||||
map(obj) {
|
map(obj) {
|
||||||
@@ -739,6 +748,9 @@
|
|||||||
child.contentType = "object";
|
child.contentType = "object";
|
||||||
child.content = this.serializer.serializeItem(Object.getPrototypeOf(parentObj), true);
|
child.content = this.serializer.serializeItem(Object.getPrototypeOf(parentObj), true);
|
||||||
child.hasChildren = true;
|
child.hasChildren = true;
|
||||||
|
if (!oldTree && type === "env") {
|
||||||
|
child.toggled = true;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case "set entries":
|
case "set entries":
|
||||||
case "map entries":
|
case "map entries":
|
||||||
@@ -815,7 +827,8 @@
|
|||||||
break;
|
break;
|
||||||
case obj instanceof Object:
|
case obj instanceof Object:
|
||||||
child.contentType = "object";
|
child.contentType = "object";
|
||||||
child.hasChildren = Object.keys(obj).length > 0;
|
child.hasChildren =
|
||||||
|
Object.keys(obj).length || Object.getOwnPropertySymbols(obj).length;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
child.contentType = typeof obj;
|
child.contentType = typeof obj;
|
||||||
@@ -880,7 +893,7 @@
|
|||||||
const children = [];
|
const children = [];
|
||||||
depth = depth + 1;
|
depth = depth + 1;
|
||||||
let obj = this.getObjectProperty(path);
|
let obj = this.getObjectProperty(path);
|
||||||
let oldBranch = this.getObjectInOldTree(oldTree, path, objType);
|
let oldBranch = oldTree && this.getObjectInOldTree(oldTree, path, objType);
|
||||||
if (!obj) {
|
if (!obj) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
@@ -895,7 +908,7 @@
|
|||||||
depth,
|
depth,
|
||||||
objType,
|
objType,
|
||||||
path,
|
path,
|
||||||
oldBranch.children[0],
|
oldBranch?.children[0],
|
||||||
oldTree
|
oldTree
|
||||||
);
|
);
|
||||||
children.push(mapKey);
|
children.push(mapKey);
|
||||||
@@ -905,7 +918,7 @@
|
|||||||
depth,
|
depth,
|
||||||
objType,
|
objType,
|
||||||
path,
|
path,
|
||||||
oldBranch.children[1],
|
oldBranch?.children[1],
|
||||||
oldTree
|
oldTree
|
||||||
);
|
);
|
||||||
children.push(mapValue);
|
children.push(mapValue);
|
||||||
@@ -916,7 +929,7 @@
|
|||||||
depth,
|
depth,
|
||||||
objType,
|
objType,
|
||||||
path,
|
path,
|
||||||
oldBranch.children[0],
|
oldBranch?.children[0],
|
||||||
oldTree
|
oldTree
|
||||||
);
|
);
|
||||||
children.push(setValue);
|
children.push(setValue);
|
||||||
@@ -937,7 +950,7 @@
|
|||||||
depth,
|
depth,
|
||||||
objType,
|
objType,
|
||||||
path,
|
path,
|
||||||
oldBranch.children[index],
|
oldBranch?.children[index],
|
||||||
oldTree
|
oldTree
|
||||||
);
|
);
|
||||||
if (child) {
|
if (child) {
|
||||||
@@ -952,7 +965,7 @@
|
|||||||
depth,
|
depth,
|
||||||
objType,
|
objType,
|
||||||
path,
|
path,
|
||||||
oldBranch.children[index],
|
oldBranch?.children[index],
|
||||||
oldTree
|
oldTree
|
||||||
);
|
);
|
||||||
if (child) {
|
if (child) {
|
||||||
@@ -969,7 +982,7 @@
|
|||||||
depth,
|
depth,
|
||||||
objType,
|
objType,
|
||||||
path,
|
path,
|
||||||
oldBranch.children[index],
|
oldBranch?.children[index],
|
||||||
oldTree
|
oldTree
|
||||||
);
|
);
|
||||||
if (entries) {
|
if (entries) {
|
||||||
@@ -983,7 +996,7 @@
|
|||||||
depth,
|
depth,
|
||||||
objType,
|
objType,
|
||||||
path,
|
path,
|
||||||
oldBranch.children[index],
|
oldBranch?.children[index],
|
||||||
oldTree
|
oldTree
|
||||||
);
|
);
|
||||||
if (child) {
|
if (child) {
|
||||||
@@ -1018,7 +1031,7 @@
|
|||||||
depth,
|
depth,
|
||||||
objType,
|
objType,
|
||||||
path,
|
path,
|
||||||
oldBranch.children[index],
|
oldBranch?.children[index],
|
||||||
oldTree
|
oldTree
|
||||||
);
|
);
|
||||||
if (child) children.push(child);
|
if (child) children.push(child);
|
||||||
@@ -1051,14 +1064,14 @@
|
|||||||
});
|
});
|
||||||
proto = Object.getPrototypeOf(proto);
|
proto = Object.getPrototypeOf(proto);
|
||||||
}
|
}
|
||||||
if (!(obj.constructor.name === "Object")) {
|
if (obj.__proto__) {
|
||||||
prototype = this.serializeObjectChild(
|
prototype = this.serializeObjectChild(
|
||||||
obj,
|
obj,
|
||||||
{ type: "prototype", childIndex: children.length },
|
{ type: "prototype", childIndex: children.length },
|
||||||
depth,
|
depth,
|
||||||
objType,
|
objType,
|
||||||
path,
|
path,
|
||||||
oldBranch.children.at(-1),
|
oldBranch?.children.at(-1),
|
||||||
oldTree
|
oldTree
|
||||||
);
|
);
|
||||||
children.push(prototype);
|
children.push(prototype);
|
||||||
@@ -1433,8 +1446,11 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const key = path.pop().value;
|
const item = path.pop();
|
||||||
const obj = this.getObjectProperty(path);
|
const obj = this.getObjectProperty(path);
|
||||||
|
const key = item.hasOwnProperty("symbolIndex")
|
||||||
|
? Object.getOwnPropertySymbols(obj)[item.symbolIndex]
|
||||||
|
: item.value;
|
||||||
if (!obj) {
|
if (!obj) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1503,8 +1519,9 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If nothing was found, return the first app's root component path
|
// If nothing was found, return the path of the first root component found in the apps
|
||||||
return ["0", "root"];
|
const appIndex = [...this.apps].findIndex((app) => app.root);
|
||||||
|
return [appIndex.toString(), "root"];
|
||||||
}
|
}
|
||||||
// Returns the tree of components of the inspected page in a parsed format
|
// Returns the tree of components of the inspected page in a parsed format
|
||||||
// Use inspectedPath to specify the path of the selected component
|
// Use inspectedPath to specify the path of the selected component
|
||||||
|
|||||||
Reference in New Issue
Block a user