mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
Compare commits
23 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| fb97955729 | |||
| 9d99f8936b | |||
| 7bc9d34a64 | |||
| b1a3b322ee | |||
| ca688d8640 | |||
| ea9f533536 | |||
| 875ebdcfb0 | |||
| 2e07799250 | |||
| 0d9d21a5c1 | |||
| 836e12b1c5 | |||
| 7538aeae0e | |||
| 3e9ba9ca8e | |||
| e4c296a7d2 | |||
| 44748270da | |||
| 8b1dc4c43d | |||
| c105c6da38 | |||
| 3001420a1d | |||
| 432ff444a1 | |||
| aa3c88a6c4 | |||
| 601a98e649 | |||
| 23c7d19ef0 | |||
| 59c49b5833 | |||
| 2cca0bd819 |
@@ -117,7 +117,7 @@ const { loadFile, mount } = owl;
|
|||||||
Dev mode activates some additional checks and developer amenities:
|
Dev mode activates some additional checks and developer amenities:
|
||||||
|
|
||||||
- [Props validation](./props.md#props-validation) is performed
|
- [Props validation](./props.md#props-validation) is performed
|
||||||
- [t-foreach](./templates.md#loops) loops check for key unicity
|
- [t-for and t-foreach](./templates.md#loops) loops check for key unicity
|
||||||
- Lifecycle hooks are wrapped to report their errors in a more developer-friendly way
|
- Lifecycle hooks are wrapped to report their errors in a more developer-friendly way
|
||||||
- onWillStart and onWillUpdateProps will emit a warning in the console when they
|
- onWillStart and onWillUpdateProps will emit a warning in the console when they
|
||||||
take longer than 3 seconds in an effort to ease debugging the presence of deadlocks
|
take longer than 3 seconds in an effort to ease debugging the presence of deadlocks
|
||||||
|
|||||||
@@ -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
|
||||||
```
|
```
|
||||||
|
|||||||
+37
-25
@@ -61,7 +61,7 @@ For reference, here is a list of all standard QWeb directives:
|
|||||||
| `t-out` | [Outputting value, possibly without escaping](#outputting-data) |
|
| `t-out` | [Outputting value, possibly without escaping](#outputting-data) |
|
||||||
| `t-set`, `t-value` | [Setting variables](#setting-variables) |
|
| `t-set`, `t-value` | [Setting variables](#setting-variables) |
|
||||||
| `t-if`, `t-elif`, `t-else`, | [conditionally rendering](#conditionals) |
|
| `t-if`, `t-elif`, `t-else`, | [conditionally rendering](#conditionals) |
|
||||||
| `t-foreach`, `t-as` | [Loops](#loops) |
|
| `t-for/t-of`, `t-foreach/t-as` | [Loops](#loops) |
|
||||||
| `t-att`, `t-attf-*`, `t-att-*` | [Dynamic attributes](#dynamic-attributes) |
|
| `t-att`, `t-attf-*`, `t-att-*` | [Dynamic attributes](#dynamic-attributes) |
|
||||||
| `t-call` | [Rendering sub templates](#sub-templates) |
|
| `t-call` | [Rendering sub templates](#sub-templates) |
|
||||||
| `t-debug`, `t-log` | [Debugging](#debugging) |
|
| `t-debug`, `t-log` | [Debugging](#debugging) |
|
||||||
@@ -372,19 +372,39 @@ Like conditions, `t-foreach` applies to the element bearing the directive’s at
|
|||||||
|
|
||||||
is equivalent to the previous example.
|
is equivalent to the previous example.
|
||||||
|
|
||||||
|
Owl also has another pair of directives that can be used for looping that allow
|
||||||
|
destructuring the contents of the loop item: `t-for` and `t-of`, which behaves
|
||||||
|
much like `for..of` in javascript:
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<t t-for="[left, right]" t-of="[['a', 1], ['b', 2], ['c', 3]]" t-key="left">
|
||||||
|
<p><t t-esc="left"/>: <t t-esc="right"/></p>
|
||||||
|
</t>
|
||||||
|
```
|
||||||
|
|
||||||
|
will be rendered as:
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<p>a: 1</p>
|
||||||
|
<p>b: 2</p>
|
||||||
|
<p>c: 3</p>
|
||||||
|
```
|
||||||
|
|
||||||
An important difference should be made with the usual `QWeb` behaviour: Owl
|
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` (but not `t-for`) provides
|
||||||
variables for various data points (note: `$as` will be replaced with the name
|
a few other useful variables (note: `$as` will be replaced with the name passed
|
||||||
passed to `t-as`):
|
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`)
|
||||||
@@ -392,10 +412,9 @@ passed to `t-as`):
|
|||||||
(equivalent to `$as_index + 1 == $as_size`), requires the iteratee’s size be
|
(equivalent to `$as_index + 1 == $as_size`), requires the iteratee’s size be
|
||||||
available
|
available
|
||||||
|
|
||||||
These extra variables provided and all new variables created into the `t-foreach`
|
These variables and all new variables created inside`t-foreach` and `t-for` are
|
||||||
are only available in the scope of the `t-foreach`. If the variable exists outside
|
only available inside of the loop. If a variable existed outside the context of
|
||||||
the context of the `t-foreach`, the value is copied at the end of the foreach
|
the loop, the assignment will affect the outer variable.
|
||||||
into the global context.
|
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
<t t-set="existing_variable" t-value="false"/>
|
<t t-set="existing_variable" t-value="false"/>
|
||||||
@@ -407,7 +426,7 @@ into the global context.
|
|||||||
<!-- existing_variable and new_variable now true -->
|
<!-- existing_variable and new_variable now true -->
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<!-- existing_variable always true -->
|
<!-- existing_variable still true -->
|
||||||
<!-- new_variable undefined -->
|
<!-- new_variable undefined -->
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -470,18 +489,11 @@ are all equivalent:
|
|||||||
</t>
|
</t>
|
||||||
```
|
```
|
||||||
|
|
||||||
If there is no `t-key` directive, Owl will use the index as a default key.
|
The `t-key` directive is mandatory, and as mentioned should represent the object's
|
||||||
|
identity. You may be tempted to use the loop index as a key, but keep in mind that
|
||||||
Note: the `t-foreach` directive only accepts arrays (lists) or objects. It does
|
this is only correct if items in the loop cannot be reordered. If this is not the
|
||||||
not work with other iterables, such as `Set`. However, it is only a matter of
|
case, using the index as the key can lead to bugs that are difficult to find, so
|
||||||
using the `...` javascript operator. For example:
|
use the index as the key only if you are sure items cannot be reordered.
|
||||||
|
|
||||||
```xml
|
|
||||||
<t t-foreach="[...items]" t-as="item">...</t>
|
|
||||||
```
|
|
||||||
|
|
||||||
The `...` operator will convert the `Set` (or any other iterables) into a list,
|
|
||||||
which will work with Owl QWeb.
|
|
||||||
|
|
||||||
### Sub Templates
|
### Sub Templates
|
||||||
|
|
||||||
|
|||||||
+146
-82
@@ -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`);
|
||||||
@@ -175,11 +177,21 @@ function createAttrUpdater(attr) {
|
|||||||
}
|
}
|
||||||
function attrsSetter(attrs) {
|
function attrsSetter(attrs) {
|
||||||
if (isArray(attrs)) {
|
if (isArray(attrs)) {
|
||||||
setAttribute.call(this, attrs[0], attrs[1]);
|
if (attrs[0] === "class") {
|
||||||
|
setClass.call(this, attrs[1]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
setAttribute.call(this, attrs[0], attrs[1]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for (let k in attrs) {
|
for (let k in attrs) {
|
||||||
setAttribute.call(this, k, attrs[k]);
|
if (k === "class") {
|
||||||
|
setClass.call(this, attrs[k]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
setAttribute.call(this, k, attrs[k]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -191,7 +203,12 @@ function attrsUpdater(attrs, oldAttrs) {
|
|||||||
if (val === oldAttrs[1]) {
|
if (val === oldAttrs[1]) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setAttribute.call(this, name, val);
|
if (name === "class") {
|
||||||
|
updateClass.call(this, val, oldAttrs[1]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
setAttribute.call(this, name, val);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
removeAttribute.call(this, oldAttrs[0]);
|
removeAttribute.call(this, oldAttrs[0]);
|
||||||
@@ -201,13 +218,23 @@ function attrsUpdater(attrs, oldAttrs) {
|
|||||||
else {
|
else {
|
||||||
for (let k in oldAttrs) {
|
for (let k in oldAttrs) {
|
||||||
if (!(k in attrs)) {
|
if (!(k in attrs)) {
|
||||||
removeAttribute.call(this, k);
|
if (k === "class") {
|
||||||
|
updateClass.call(this, "", oldAttrs[k]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
removeAttribute.call(this, k);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (let k in attrs) {
|
for (let k in attrs) {
|
||||||
const val = attrs[k];
|
const val = attrs[k];
|
||||||
if (val !== oldAttrs[k]) {
|
if (val !== oldAttrs[k]) {
|
||||||
setAttribute.call(this, k, val);
|
if (k === "class") {
|
||||||
|
updateClass.call(this, val, oldAttrs[k]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
setAttribute.call(this, k, val);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -286,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();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -1632,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) {
|
||||||
@@ -2360,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();
|
||||||
@@ -2385,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
|
||||||
@@ -2403,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();
|
||||||
@@ -2430,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;
|
||||||
@@ -2963,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)];
|
||||||
@@ -3875,6 +3919,10 @@ class CodeGenerator {
|
|||||||
})
|
})
|
||||||
.join("");
|
.join("");
|
||||||
}
|
}
|
||||||
|
translate(str) {
|
||||||
|
const match = translationRE.exec(str);
|
||||||
|
return match[1] + this.translateFn(match[2]) + match[3];
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* @returns the newly created block name, if any
|
* @returns the newly created block name, if any
|
||||||
*/
|
*/
|
||||||
@@ -3952,8 +4000,7 @@ class CodeGenerator {
|
|||||||
let { block, forceNewBlock } = ctx;
|
let { block, forceNewBlock } = ctx;
|
||||||
let value = ast.value;
|
let value = ast.value;
|
||||||
if (value && ctx.translate !== false) {
|
if (value && ctx.translate !== false) {
|
||||||
const match = translationRE.exec(value);
|
value = this.translate(value);
|
||||||
value = match[1] + this.translateFn(match[2]) + match[3];
|
|
||||||
}
|
}
|
||||||
if (!ctx.inPreTag) {
|
if (!ctx.inPreTag) {
|
||||||
value = value.replace(whitespaceRE, " ");
|
value = value.replace(whitespaceRE, " ");
|
||||||
@@ -4494,11 +4541,12 @@ class CodeGenerator {
|
|||||||
else {
|
else {
|
||||||
let value;
|
let value;
|
||||||
if (ast.defaultValue) {
|
if (ast.defaultValue) {
|
||||||
|
const defaultValue = ctx.translate ? this.translate(ast.defaultValue) : ast.defaultValue;
|
||||||
if (ast.value) {
|
if (ast.value) {
|
||||||
value = `withDefault(${expr}, \`${ast.defaultValue}\`)`;
|
value = `withDefault(${expr}, \`${defaultValue}\`)`;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
value = `\`${ast.defaultValue}\``;
|
value = `\`${defaultValue}\``;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -4791,10 +4839,10 @@ function parseNode(node, ctx) {
|
|||||||
parseTCall(node, ctx) ||
|
parseTCall(node, ctx) ||
|
||||||
parseTCallBlock(node) ||
|
parseTCallBlock(node) ||
|
||||||
parseTEscNode(node, ctx) ||
|
parseTEscNode(node, ctx) ||
|
||||||
|
parseTOutNode(node, ctx) ||
|
||||||
parseTKey(node, ctx) ||
|
parseTKey(node, ctx) ||
|
||||||
parseTTranslation(node, ctx) ||
|
parseTTranslation(node, ctx) ||
|
||||||
parseTSlot(node, ctx) ||
|
parseTSlot(node, ctx) ||
|
||||||
parseTOutNode(node, ctx) ||
|
|
||||||
parseComponent(node, ctx) ||
|
parseComponent(node, ctx) ||
|
||||||
parseDOMNode(node, ctx) ||
|
parseDOMNode(node, ctx) ||
|
||||||
parseTSetNode(node, ctx) ||
|
parseTSetNode(node, ctx) ||
|
||||||
@@ -4879,10 +4927,10 @@ function parseDOMNode(node, ctx) {
|
|||||||
let model = null;
|
let model = null;
|
||||||
for (let attr of nodeAttrsNames) {
|
for (let attr of nodeAttrsNames) {
|
||||||
const value = node.getAttribute(attr);
|
const value = node.getAttribute(attr);
|
||||||
if (attr.startsWith("t-on")) {
|
if (attr === "t-on" || attr === "t-on-") {
|
||||||
if (attr === "t-on") {
|
throw new OwlError("Missing event name with t-on directive");
|
||||||
throw new OwlError("Missing event name with t-on directive");
|
}
|
||||||
}
|
if (attr.startsWith("t-on-")) {
|
||||||
on = on || {};
|
on = on || {};
|
||||||
on[attr.slice(5)] = value;
|
on[attr.slice(5)] = value;
|
||||||
}
|
}
|
||||||
@@ -4907,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");
|
||||||
@@ -4922,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
|
||||||
@@ -4986,9 +5032,6 @@ function parseTEscNode(node, ctx) {
|
|||||||
content: [tesc],
|
content: [tesc],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (ast.type === 11 /* TComponent */) {
|
|
||||||
throw new OwlError("t-esc is not supported on Component nodes");
|
|
||||||
}
|
|
||||||
return tesc;
|
return tesc;
|
||||||
}
|
}
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
@@ -5430,19 +5473,21 @@ function normalizeTIf(el) {
|
|||||||
*
|
*
|
||||||
* @param el the element containing the tree that should be normalized
|
* @param el the element containing the tree that should be normalized
|
||||||
*/
|
*/
|
||||||
function normalizeTEsc(el) {
|
function normalizeTEscTOut(el) {
|
||||||
const elements = [...el.querySelectorAll("[t-esc]")].filter((el) => el.tagName[0] === el.tagName[0].toUpperCase() || el.hasAttribute("t-component"));
|
for (const d of ["t-esc", "t-out"]) {
|
||||||
for (const el of elements) {
|
const elements = [...el.querySelectorAll(`[${d}]`)].filter((el) => el.tagName[0] === el.tagName[0].toUpperCase() || el.hasAttribute("t-component"));
|
||||||
if (el.childNodes.length) {
|
for (const el of elements) {
|
||||||
throw new OwlError("Cannot have t-esc on a component that already has content");
|
if (el.childNodes.length) {
|
||||||
|
throw new OwlError(`Cannot have ${d} on a component that already has content`);
|
||||||
|
}
|
||||||
|
const value = el.getAttribute(d);
|
||||||
|
el.removeAttribute(d);
|
||||||
|
const t = el.ownerDocument.createElement("t");
|
||||||
|
if (value != null) {
|
||||||
|
t.setAttribute(d, value);
|
||||||
|
}
|
||||||
|
el.appendChild(t);
|
||||||
}
|
}
|
||||||
const value = el.getAttribute("t-esc");
|
|
||||||
el.removeAttribute("t-esc");
|
|
||||||
const t = el.ownerDocument.createElement("t");
|
|
||||||
if (value != null) {
|
|
||||||
t.setAttribute("t-esc", value);
|
|
||||||
}
|
|
||||||
el.appendChild(t);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -5453,7 +5498,7 @@ function normalizeTEsc(el) {
|
|||||||
*/
|
*/
|
||||||
function normalizeXML(el) {
|
function normalizeXML(el) {
|
||||||
normalizeTIf(el);
|
normalizeTIf(el);
|
||||||
normalizeTEsc(el);
|
normalizeTEscTOut(el);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Parses an XML string into an XML document, throwing errors on parser errors
|
* Parses an XML string into an XML document, throwing errors on parser errors
|
||||||
@@ -5506,7 +5551,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.2";
|
const version = "2.2.3";
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Scheduler
|
// Scheduler
|
||||||
@@ -5516,11 +5561,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.
|
||||||
@@ -5530,21 +5582,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) {
|
||||||
@@ -5557,7 +5616,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;
|
||||||
}
|
}
|
||||||
@@ -5585,6 +5644,8 @@ window.__OWL_DEVTOOLS__ || (window.__OWL_DEVTOOLS__ = {
|
|||||||
apps: new Set(),
|
apps: new Set(),
|
||||||
Fiber: Fiber,
|
Fiber: Fiber,
|
||||||
RootFiber: RootFiber,
|
RootFiber: RootFiber,
|
||||||
|
toRaw: toRaw,
|
||||||
|
reactive: reactive,
|
||||||
});
|
});
|
||||||
class App extends TemplateSet {
|
class App extends TemplateSet {
|
||||||
constructor(Root, config = {}) {
|
constructor(Root, config = {}) {
|
||||||
@@ -5647,8 +5708,8 @@ class App extends TemplateSet {
|
|||||||
}
|
}
|
||||||
destroy() {
|
destroy() {
|
||||||
if (this.root) {
|
if (this.root) {
|
||||||
this.scheduler.flush();
|
|
||||||
this.root.destroy();
|
this.root.destroy();
|
||||||
|
this.scheduler.processTasks();
|
||||||
}
|
}
|
||||||
window.__OWL_DEVTOOLS__.apps.delete(this);
|
window.__OWL_DEVTOOLS__.apps.delete(this);
|
||||||
}
|
}
|
||||||
@@ -5779,9 +5840,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";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5837,8 +5900,9 @@ function useChildSubEnv(envExtension) {
|
|||||||
* will run a cleanup function before patching and before unmounting the
|
* will run a cleanup function before patching and before unmounting the
|
||||||
* the component.
|
* the component.
|
||||||
*
|
*
|
||||||
* @param {Effect} effect the effect to run on component mount and/or patch
|
* @template T
|
||||||
* @param {()=>any[]} [computeDependencies=()=>[NaN]] a callback to compute
|
* @param {Effect<T>} effect the effect to run on component mount and/or patch
|
||||||
|
* @param {()=>T} [computeDependencies=()=>[NaN]] a callback to compute
|
||||||
* dependencies that will decide if the effect needs to be cleaned up and
|
* dependencies that will decide if the effect needs to be cleaned up and
|
||||||
* run again. If the dependencies did not change, the effect will not run
|
* run again. If the dependencies did not change, the effect will not run
|
||||||
* again. The default value returns an array containing only NaN because
|
* again. The default value returns an array containing only NaN because
|
||||||
@@ -5920,6 +5984,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-04-29T07:45:54.333Z';
|
__info__.date = '2023-07-20T06:05:29.796Z';
|
||||||
__info__.hash = 'aabb755';
|
__info__.hash = 'b1a3b32';
|
||||||
__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.3",
|
"version": "2.2.3",
|
||||||
"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.3",
|
"version": "2.2.3",
|
||||||
"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",
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import {
|
|||||||
ASTTCallBlock,
|
ASTTCallBlock,
|
||||||
ASTTEsc,
|
ASTTEsc,
|
||||||
ASTText,
|
ASTText,
|
||||||
|
ASTTFor,
|
||||||
ASTTForEach,
|
ASTTForEach,
|
||||||
ASTTif,
|
ASTTif,
|
||||||
ASTTKey,
|
ASTTKey,
|
||||||
@@ -471,6 +472,8 @@ export class CodeGenerator {
|
|||||||
return this.compileTIf(ast, ctx);
|
return this.compileTIf(ast, ctx);
|
||||||
case ASTType.TForEach:
|
case ASTType.TForEach:
|
||||||
return this.compileTForeach(ast, ctx);
|
return this.compileTForeach(ast, ctx);
|
||||||
|
case ASTType.TFor:
|
||||||
|
return this.compileTFor(ast, ctx);
|
||||||
case ASTType.TKey:
|
case ASTType.TKey:
|
||||||
return this.compileTKey(ast, ctx);
|
return this.compileTKey(ast, ctx);
|
||||||
case ASTType.Multi:
|
case ASTType.Multi:
|
||||||
@@ -907,7 +910,7 @@ export class CodeGenerator {
|
|||||||
if (!ast.hasNoValue) {
|
if (!ast.hasNoValue) {
|
||||||
this.addLine(`ctx[\`${ast.elem}_value\`] = ${keys}[${loopVar}];`);
|
this.addLine(`ctx[\`${ast.elem}_value\`] = ${keys}[${loopVar}];`);
|
||||||
}
|
}
|
||||||
this.define(`key${this.target.loopLevel}`, ast.key ? compileExpr(ast.key) : loopVar);
|
this.define(`key${this.target.loopLevel}`, compileExpr(ast.key));
|
||||||
if (this.dev) {
|
if (this.dev) {
|
||||||
// Throw error on duplicate keys in dev mode
|
// Throw error on duplicate keys in dev mode
|
||||||
this.helpers.add("OwlError");
|
this.helpers.add("OwlError");
|
||||||
@@ -954,6 +957,46 @@ export class CodeGenerator {
|
|||||||
return block.varName;
|
return block.varName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
compileTFor(ast: ASTTFor, ctx: Context): string {
|
||||||
|
let { block } = ctx;
|
||||||
|
if (block) {
|
||||||
|
this.insertAnchor(block);
|
||||||
|
}
|
||||||
|
block = this.createBlock(block, "list", ctx);
|
||||||
|
this.target.loopLevel++;
|
||||||
|
this.addLine(`ctx = Object.create(ctx);`);
|
||||||
|
// Throw errors on duplicate keys in dev mode
|
||||||
|
if (this.dev) {
|
||||||
|
this.define(`keys${block.id}`, `new Set()`);
|
||||||
|
}
|
||||||
|
this.define(`c_block${block.id}`, "[]");
|
||||||
|
const index = `i${this.target.loopLevel}`;
|
||||||
|
this.addLine(`let ${index} = ${0};`);
|
||||||
|
const binding = compileExpr(ast.binding);
|
||||||
|
this.addLine(`for (${binding} of ${compileExpr(ast.iterable)}) {`);
|
||||||
|
this.target.indentLevel++;
|
||||||
|
this.define(`key${this.target.loopLevel}`, compileExpr(ast.key));
|
||||||
|
if (this.dev) {
|
||||||
|
// Throw error on duplicate keys in dev mode
|
||||||
|
this.helpers.add("OwlError");
|
||||||
|
this.addLine(
|
||||||
|
`if (keys${block.id}.has(String(key${this.target.loopLevel}))) { throw new OwlError(\`Got duplicate key in t-for: \${key${this.target.loopLevel}}\`)}`
|
||||||
|
);
|
||||||
|
this.addLine(`keys${block.id}.add(String(key${this.target.loopLevel}));`);
|
||||||
|
}
|
||||||
|
const subCtx = createContext(ctx, { block, index });
|
||||||
|
this.compileAST(ast.body, subCtx);
|
||||||
|
this.addLine(`${index}++;`);
|
||||||
|
this.target.indentLevel--;
|
||||||
|
this.target.loopLevel--;
|
||||||
|
this.addLine(`}`);
|
||||||
|
if (!ctx.isLast) {
|
||||||
|
this.addLine(`ctx = ctx.__proto__;`);
|
||||||
|
}
|
||||||
|
this.insertBlock("l", block, ctx);
|
||||||
|
return block.varName;
|
||||||
|
}
|
||||||
|
|
||||||
compileTKey(ast: ASTTKey, ctx: Context): string | null {
|
compileTKey(ast: ASTTKey, ctx: Context): string | null {
|
||||||
const tKeyExpr = generateId("tKey_");
|
const tKeyExpr = generateId("tKey_");
|
||||||
this.define(tKeyExpr, compileExpr(ast.expr));
|
this.define(tKeyExpr, compileExpr(ast.expr));
|
||||||
|
|||||||
+12
-1
@@ -2,6 +2,7 @@ import type { TemplateSet } from "../runtime/template_set";
|
|||||||
import type { BDom } from "../runtime/blockdom";
|
import type { BDom } from "../runtime/blockdom";
|
||||||
import { CodeGenerator, Config } from "./code_generator";
|
import { CodeGenerator, Config } from "./code_generator";
|
||||||
import { parse } from "./parser";
|
import { parse } from "./parser";
|
||||||
|
import { OwlError } from "../runtime";
|
||||||
|
|
||||||
export type Template = (context: any, vnode: any, key?: string) => BDom;
|
export type Template = (context: any, vnode: any, key?: string) => BDom;
|
||||||
|
|
||||||
@@ -27,5 +28,15 @@ export function compile(
|
|||||||
const codeGenerator = new CodeGenerator(ast, { ...options, hasSafeContext });
|
const codeGenerator = new CodeGenerator(ast, { ...options, hasSafeContext });
|
||||||
const code = codeGenerator.generateCode();
|
const code = codeGenerator.generateCode();
|
||||||
// template function
|
// template function
|
||||||
return new Function("app, bdom, helpers", code) as TemplateFunction;
|
try {
|
||||||
|
return new Function("app, bdom, helpers", code) as TemplateFunction;
|
||||||
|
} catch (originalError: any) {
|
||||||
|
const { name } = options;
|
||||||
|
const nameStr = name ? `template "${name}"` : "anonymous template";
|
||||||
|
const err = new OwlError(
|
||||||
|
`Failed to compile ${nameStr}: ${originalError.message}\n\ngenerated code:\nfunction(app, bdom, helpers) {\n${code}\n}`
|
||||||
|
);
|
||||||
|
err.cause = originalError;
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+62
-24
@@ -26,6 +26,7 @@ export const enum ASTType {
|
|||||||
TCallBlock,
|
TCallBlock,
|
||||||
TTranslation,
|
TTranslation,
|
||||||
TPortal,
|
TPortal,
|
||||||
|
TFor,
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ASTText {
|
export interface ASTText {
|
||||||
@@ -104,7 +105,15 @@ export interface ASTTForEach {
|
|||||||
hasNoLast: boolean;
|
hasNoLast: boolean;
|
||||||
hasNoIndex: boolean;
|
hasNoIndex: boolean;
|
||||||
hasNoValue: boolean;
|
hasNoValue: boolean;
|
||||||
key: string | null;
|
key: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ASTTFor {
|
||||||
|
type: ASTType.TFor;
|
||||||
|
iterable: string;
|
||||||
|
binding: string;
|
||||||
|
body: AST;
|
||||||
|
key: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ASTTKey {
|
export interface ASTTKey {
|
||||||
@@ -183,6 +192,7 @@ export type AST =
|
|||||||
| ASTTCall
|
| ASTTCall
|
||||||
| ASTTOut
|
| ASTTOut
|
||||||
| ASTTForEach
|
| ASTTForEach
|
||||||
|
| ASTTFor
|
||||||
| ASTTKey
|
| ASTTKey
|
||||||
| ASTComponent
|
| ASTComponent
|
||||||
| ASTSlot
|
| ASTSlot
|
||||||
@@ -230,15 +240,16 @@ function parseNode(node: Node, ctx: ParsingContext): AST | null {
|
|||||||
return (
|
return (
|
||||||
parseTDebugLog(node, ctx) ||
|
parseTDebugLog(node, ctx) ||
|
||||||
parseTForEach(node, ctx) ||
|
parseTForEach(node, ctx) ||
|
||||||
|
parseTFor(node, ctx) ||
|
||||||
parseTIf(node, ctx) ||
|
parseTIf(node, ctx) ||
|
||||||
parseTPortal(node, ctx) ||
|
parseTPortal(node, ctx) ||
|
||||||
parseTCall(node, ctx) ||
|
parseTCall(node, ctx) ||
|
||||||
parseTCallBlock(node, ctx) ||
|
parseTCallBlock(node, ctx) ||
|
||||||
parseTEscNode(node, ctx) ||
|
parseTEscNode(node, ctx) ||
|
||||||
|
parseTOutNode(node, ctx) ||
|
||||||
parseTKey(node, ctx) ||
|
parseTKey(node, ctx) ||
|
||||||
parseTTranslation(node, ctx) ||
|
parseTTranslation(node, ctx) ||
|
||||||
parseTSlot(node, ctx) ||
|
parseTSlot(node, ctx) ||
|
||||||
parseTOutNode(node, ctx) ||
|
|
||||||
parseComponent(node, ctx) ||
|
parseComponent(node, ctx) ||
|
||||||
parseDOMNode(node, ctx) ||
|
parseDOMNode(node, ctx) ||
|
||||||
parseTSetNode(node, ctx) ||
|
parseTSetNode(node, ctx) ||
|
||||||
@@ -365,10 +376,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 +390,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
|
||||||
@@ -446,9 +455,6 @@ function parseTEscNode(node: Element, ctx: ParsingContext): AST | null {
|
|||||||
content: [tesc],
|
content: [tesc],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (ast.type === ASTType.TComponent) {
|
|
||||||
throw new OwlError("t-esc is not supported on Component nodes");
|
|
||||||
}
|
|
||||||
return tesc;
|
return tesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -536,6 +542,36 @@ function parseTForEach(node: Element, ctx: ParsingContext): AST | null {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parseTFor(node: Element, ctx: ParsingContext): AST | null {
|
||||||
|
if (!node.hasAttribute("t-for")) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const binding = node.getAttribute("t-for")!;
|
||||||
|
node.removeAttribute("t-for");
|
||||||
|
const iterable = node.getAttribute("t-of") || "";
|
||||||
|
node.removeAttribute("t-of");
|
||||||
|
const key = node.getAttribute("t-key");
|
||||||
|
if (!key) {
|
||||||
|
throw new OwlError(
|
||||||
|
`"Directive t-for should always be used with a t-key!" (expression: t-for="${binding}" t-of="${iterable}")`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
node.removeAttribute("t-key");
|
||||||
|
const body = parseNode(node, ctx);
|
||||||
|
|
||||||
|
if (!body) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
type: ASTType.TFor,
|
||||||
|
iterable,
|
||||||
|
binding,
|
||||||
|
body,
|
||||||
|
key,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function parseTKey(node: Element, ctx: ParsingContext): AST | null {
|
function parseTKey(node: Element, ctx: ParsingContext): AST | null {
|
||||||
if (!node.hasAttribute("t-key")) {
|
if (!node.hasAttribute("t-key")) {
|
||||||
return null;
|
return null;
|
||||||
@@ -943,21 +979,23 @@ function normalizeTIf(el: Element) {
|
|||||||
*
|
*
|
||||||
* @param el the element containing the tree that should be normalized
|
* @param el the element containing the tree that should be normalized
|
||||||
*/
|
*/
|
||||||
function normalizeTEsc(el: Element) {
|
function normalizeTEscTOut(el: Element) {
|
||||||
const elements = [...el.querySelectorAll("[t-esc]")].filter(
|
for (const d of ["t-esc", "t-out"]) {
|
||||||
(el) => el.tagName[0] === el.tagName[0].toUpperCase() || el.hasAttribute("t-component")
|
const elements = [...el.querySelectorAll(`[${d}]`)].filter(
|
||||||
);
|
(el) => el.tagName[0] === el.tagName[0].toUpperCase() || el.hasAttribute("t-component")
|
||||||
for (const el of elements) {
|
);
|
||||||
if (el.childNodes.length) {
|
for (const el of elements) {
|
||||||
throw new OwlError("Cannot have t-esc on a component that already has content");
|
if (el.childNodes.length) {
|
||||||
|
throw new OwlError(`Cannot have ${d} on a component that already has content`);
|
||||||
|
}
|
||||||
|
const value = el.getAttribute(d);
|
||||||
|
el.removeAttribute(d);
|
||||||
|
const t = el.ownerDocument.createElement("t");
|
||||||
|
if (value != null) {
|
||||||
|
t.setAttribute(d, value);
|
||||||
|
}
|
||||||
|
el.appendChild(t);
|
||||||
}
|
}
|
||||||
const value = el.getAttribute("t-esc");
|
|
||||||
el.removeAttribute("t-esc");
|
|
||||||
const t = el.ownerDocument.createElement("t");
|
|
||||||
if (value != null) {
|
|
||||||
t.setAttribute("t-esc", value);
|
|
||||||
}
|
|
||||||
el.appendChild(t);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -969,7 +1007,7 @@ function normalizeTEsc(el: Element) {
|
|||||||
*/
|
*/
|
||||||
function normalizeXML(el: Element) {
|
function normalizeXML(el: Element) {
|
||||||
normalizeTIf(el);
|
normalizeTIf(el);
|
||||||
normalizeTEsc(el);
|
normalizeTEscTOut(el);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+1
-1
@@ -136,8 +136,8 @@ export class App<
|
|||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
if (this.root) {
|
if (this.root) {
|
||||||
this.scheduler.flush();
|
|
||||||
this.root.destroy();
|
this.root.destroy();
|
||||||
|
this.scheduler.processTasks();
|
||||||
}
|
}
|
||||||
window.__OWL_DEVTOOLS__.apps.delete(this);
|
window.__OWL_DEVTOOLS__.apps.delete(this);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,10 +36,18 @@ export function createAttrUpdater(attr: string): Setter<HTMLElement> {
|
|||||||
|
|
||||||
export function attrsSetter(this: HTMLElement, attrs: any) {
|
export function attrsSetter(this: HTMLElement, attrs: any) {
|
||||||
if (isArray(attrs)) {
|
if (isArray(attrs)) {
|
||||||
setAttribute.call(this, attrs[0], attrs[1]);
|
if (attrs[0] === "class") {
|
||||||
|
setClass.call(this, attrs[1]);
|
||||||
|
} else {
|
||||||
|
setAttribute.call(this, attrs[0], attrs[1]);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
for (let k in attrs) {
|
for (let k in attrs) {
|
||||||
setAttribute.call(this, k, attrs[k]);
|
if (k === "class") {
|
||||||
|
setClass.call(this, attrs[k]);
|
||||||
|
} else {
|
||||||
|
setAttribute.call(this, k, attrs[k]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -52,7 +60,11 @@ export function attrsUpdater(this: HTMLElement, attrs: any, oldAttrs: any) {
|
|||||||
if (val === oldAttrs[1]) {
|
if (val === oldAttrs[1]) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setAttribute.call(this, name, val);
|
if (name === "class") {
|
||||||
|
updateClass.call(this, val, oldAttrs[1]);
|
||||||
|
} else {
|
||||||
|
setAttribute.call(this, name, val);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
removeAttribute.call(this, oldAttrs[0]);
|
removeAttribute.call(this, oldAttrs[0]);
|
||||||
setAttribute.call(this, name, val);
|
setAttribute.call(this, name, val);
|
||||||
@@ -60,13 +72,21 @@ export function attrsUpdater(this: HTMLElement, attrs: any, oldAttrs: any) {
|
|||||||
} else {
|
} else {
|
||||||
for (let k in oldAttrs) {
|
for (let k in oldAttrs) {
|
||||||
if (!(k in attrs)) {
|
if (!(k in attrs)) {
|
||||||
removeAttribute.call(this, k);
|
if (k === "class") {
|
||||||
|
updateClass.call(this, "", oldAttrs[k]);
|
||||||
|
} else {
|
||||||
|
removeAttribute.call(this, k);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (let k in attrs) {
|
for (let k in attrs) {
|
||||||
const val = attrs[k];
|
const val = attrs[k];
|
||||||
if (val !== oldAttrs[k]) {
|
if (val !== oldAttrs[k]) {
|
||||||
setAttribute.call(this, k, val);
|
if (k === "class") {
|
||||||
|
updateClass.call(this, val, oldAttrs[k]);
|
||||||
|
} else {
|
||||||
|
setAttribute.call(this, k, val);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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:
|
||||||
|
|||||||
@@ -8,12 +8,6 @@ import { OwlError } from "./error_handling";
|
|||||||
import type { ComponentNode } from "./component_node";
|
import type { ComponentNode } from "./component_node";
|
||||||
|
|
||||||
const ObjectCreate = Object.create;
|
const ObjectCreate = Object.create;
|
||||||
const ObjectGetPrototypeOf = Object.getPrototypeOf;
|
|
||||||
const ObjectGetOwnPropertyDescriptors = Object.getOwnPropertyDescriptors;
|
|
||||||
const ObjectDefineProperty = Object.defineProperty;
|
|
||||||
const ObjectEntries = Object.entries;
|
|
||||||
const hasOwnProperty = (obj: Object, prop: PropertyKey) =>
|
|
||||||
Object.prototype.hasOwnProperty.call(obj, prop);
|
|
||||||
/**
|
/**
|
||||||
* This file contains utility functions that will be injected in each template,
|
* This file contains utility functions that will be injected in each template,
|
||||||
* to perform various useful tasks in the compiled code.
|
* to perform various useful tasks in the compiled code.
|
||||||
@@ -55,14 +49,8 @@ function callSlot(
|
|||||||
|
|
||||||
function capture(ctx: any): any {
|
function capture(ctx: any): any {
|
||||||
const result = ObjectCreate(ctx);
|
const result = ObjectCreate(ctx);
|
||||||
let current = ctx;
|
for (let k in ctx) {
|
||||||
while (current && current !== Object.prototype) {
|
result[k] = ctx[k];
|
||||||
for (const [key, descriptor] of ObjectEntries(ObjectGetOwnPropertyDescriptors(current))) {
|
|
||||||
if (!hasOwnProperty(result, key) && "value" in descriptor) {
|
|
||||||
ObjectDefineProperty(result, key, descriptor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
current = ObjectGetPrototypeOf(current);
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -72,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.3";
|
export const version = "2.2.3";
|
||||||
|
|||||||
@@ -15,6 +15,34 @@ exports[`app App supports env with getters/setters 1`] = `
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`app app: clear scheduler tasks and destroy cancelled nodes immediately on destroy 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'].value) {
|
||||||
|
b3 = comp1({}, key + \`__1\`, node, this, null);
|
||||||
|
}
|
||||||
|
return multi([b2, b3]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`app app: clear scheduler tasks and destroy cancelled nodes immediately on destroy 2`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
return text(\`B\`);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`app can configure an app with props 1`] = `
|
exports[`app can configure an app with props 1`] = `
|
||||||
"function anonymous(app, bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
|
|||||||
+50
-2
@@ -1,6 +1,14 @@
|
|||||||
import { App, Component, mount, xml } from "../../src";
|
import { App, Component, mount, onWillStart, useState, xml } from "../../src";
|
||||||
import { status } from "../../src/runtime/status";
|
import { status } from "../../src/runtime/status";
|
||||||
import { makeTestFixture, snapshotEverything, nextTick, elem } from "../helpers";
|
import {
|
||||||
|
makeTestFixture,
|
||||||
|
snapshotEverything,
|
||||||
|
nextTick,
|
||||||
|
elem,
|
||||||
|
useLogLifecycle,
|
||||||
|
makeDeferred,
|
||||||
|
nextMicroTick,
|
||||||
|
} from "../helpers";
|
||||||
|
|
||||||
let fixture: HTMLElement;
|
let fixture: HTMLElement;
|
||||||
|
|
||||||
@@ -94,4 +102,44 @@ describe("app", () => {
|
|||||||
expect(iframeDoc.contains(div)).toBe(false);
|
expect(iframeDoc.contains(div)).toBe(false);
|
||||||
expect(status(comp)).toBe("destroyed");
|
expect(status(comp)).toBe("destroyed");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("app: clear scheduler tasks and destroy cancelled nodes immediately on destroy", async () => {
|
||||||
|
let def = makeDeferred();
|
||||||
|
class B extends Component {
|
||||||
|
static template = xml`B`;
|
||||||
|
setup() {
|
||||||
|
useLogLifecycle();
|
||||||
|
onWillStart(() => def);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class A extends Component {
|
||||||
|
static template = xml`A<t t-if="state.value"><B/></t>`;
|
||||||
|
static components = { B };
|
||||||
|
state = useState({ value: false });
|
||||||
|
setup() {
|
||||||
|
useLogLifecycle();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const app = new App(A);
|
||||||
|
const comp = await app.mount(fixture);
|
||||||
|
expect(["A:setup", "A:willStart", "A:willRender", "A:rendered", "A:mounted"]).toBeLogged();
|
||||||
|
|
||||||
|
comp.state.value = true;
|
||||||
|
await nextTick();
|
||||||
|
expect(["A:willRender", "B:setup", "B:willStart", "A:rendered"]).toBeLogged();
|
||||||
|
|
||||||
|
// rerender to force the instantiation of a new B component (and cancelling the first)
|
||||||
|
comp.render();
|
||||||
|
await nextMicroTick();
|
||||||
|
expect(["A:willRender", "B:setup", "B:willStart", "A:rendered"]).toBeLogged();
|
||||||
|
|
||||||
|
app.destroy();
|
||||||
|
expect([
|
||||||
|
"A:willUnmount",
|
||||||
|
"B:willDestroy",
|
||||||
|
"A:willDestroy",
|
||||||
|
"B:willDestroy", // make sure the 2 B instances have been destroyed synchronously
|
||||||
|
]).toBeLogged();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -145,3 +145,34 @@ test("class attribute (with a preexisting value", async () => {
|
|||||||
patch(tree, block([""]));
|
patch(tree, block([""]));
|
||||||
expect(fixture.innerHTML).toBe(`<div class="tomato"></div>`);
|
expect(fixture.innerHTML).toBe(`<div class="tomato"></div>`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("block-class attributes with preexisting class attribute", async () => {
|
||||||
|
const block = createBlock('<div block-attributes="0" class="owl"></div>');
|
||||||
|
const tree = block([{ class: "eagle" }]);
|
||||||
|
|
||||||
|
mount(tree, fixture);
|
||||||
|
expect(fixture.innerHTML).toBe(`<div class="owl eagle"></div>`);
|
||||||
|
|
||||||
|
patch(tree, block([{ class: "falcon" }]));
|
||||||
|
expect(fixture.innerHTML).toBe(`<div class="owl falcon"></div>`);
|
||||||
|
|
||||||
|
patch(tree, block([{}]));
|
||||||
|
expect(fixture.innerHTML).toBe(`<div class="owl"></div>`);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("block-class attributes (array syntax) with preexisting class attribute", async () => {
|
||||||
|
const block = createBlock('<div block-attributes="0" class="owl"></div>');
|
||||||
|
const tree = block([["class", "eagle"]]);
|
||||||
|
|
||||||
|
mount(tree, fixture);
|
||||||
|
expect(fixture.innerHTML).toBe(`<div class="owl eagle"></div>`);
|
||||||
|
|
||||||
|
patch(tree, block([["class", "falcon"]]));
|
||||||
|
expect(fixture.innerHTML).toBe(`<div class="owl falcon"></div>`);
|
||||||
|
|
||||||
|
patch(tree, block([["class", ""]]));
|
||||||
|
expect(fixture.innerHTML).toBe(`<div class="owl"></div>`);
|
||||||
|
|
||||||
|
patch(tree, block([["class", "buzzard"]]));
|
||||||
|
expect(fixture.innerHTML).toBe(`<div class="owl buzzard"></div>`);
|
||||||
|
});
|
||||||
|
|||||||
@@ -707,6 +707,123 @@ exports[`attributes updating classes (with obj notation) 1`] = `
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`attributes various combinations of class, t-att-class, and t-att 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div block-attributes=\\"0\\" class=\\"c\\">content</div>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
let attr1 = {class:'a'};
|
||||||
|
return block1([attr1]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`attributes various combinations of class, t-att-class, and t-att 2`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div block-attributes=\\"0\\" block-attribute-1=\\"class\\" class=\\"c\\">content</div>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
let attr1 = {class:'a'};
|
||||||
|
let attr2 = {'b':true};
|
||||||
|
return block1([attr1, attr2]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`attributes various combinations of class, t-att-class, and t-att 3`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div block-attributes=\\"0\\" class=\\"c\\" block-attribute-1=\\"class\\">content</div>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
let attr1 = {class:'a'};
|
||||||
|
let attr2 = {'b':true};
|
||||||
|
return block1([attr1, attr2]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`attributes various combinations of class, t-att-class, and t-att 4`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div class=\\"c\\" block-attributes=\\"0\\" block-attribute-1=\\"class\\">content</div>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
let attr1 = {class:'a'};
|
||||||
|
let attr2 = {'b':true};
|
||||||
|
return block1([attr1, attr2]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`attributes various combinations of class, t-att-class, and t-att 5`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div class=\\"c\\" block-attribute-0=\\"class\\" block-attributes=\\"1\\">content</div>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
let attr1 = {'b':true};
|
||||||
|
let attr2 = {class:'a'};
|
||||||
|
return block1([attr1, attr2]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`attributes various combinations of class, t-att-class, and t-att 6`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div class=\\"c\\" block-attribute-0=\\"class\\">content</div>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
let attr1 = {'b':true};
|
||||||
|
return block1([attr1]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`attributes various combinations of class, t-att-class, and t-att 7`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div class=\\"c\\" block-attribute-0=\\"class\\">content</div>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
let attr1 = ('b');
|
||||||
|
return block1([attr1]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`attributes various combinations of class, t-att-class, and t-att 8`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div block-attributes=\\"0\\" block-attribute-1=\\"class\\">content</div>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
let attr1 = {class:'a'};
|
||||||
|
let attr2 = {'b':true};
|
||||||
|
return block1([attr1, attr2]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`attributes various escapes 1`] = `
|
exports[`attributes various escapes 1`] = `
|
||||||
"function anonymous(app, bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -0,0 +1,670 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`t-for destructuring array items 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { withKey } = helpers;
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
const c_block1 = [];
|
||||||
|
let i1 = 0;
|
||||||
|
for ([ctx['key'],ctx['value']] of Object.entries({a:1,b:2})) {
|
||||||
|
const key1 = ctx['key'];
|
||||||
|
const b3 = text(\`(\`);
|
||||||
|
const b4 = text(ctx['key']);
|
||||||
|
const b5 = text(\`: \`);
|
||||||
|
const b6 = text(ctx['value']);
|
||||||
|
const b7 = text(\`)\`);
|
||||||
|
c_block1[i1] = withKey(multi([b3, b4, b5, b6, b7]), key1);
|
||||||
|
i1++;
|
||||||
|
}
|
||||||
|
return list(c_block1);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`t-for destructuring array items: rest 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { withKey } = helpers;
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
const c_block1 = [];
|
||||||
|
let i1 = 0;
|
||||||
|
for ([ctx['head'],...ctx['tail']] of [[1,2,3],[4,5,6]]) {
|
||||||
|
const key1 = ctx['head'];
|
||||||
|
const b3 = text(\`(\`);
|
||||||
|
const b4 = text(ctx['head']);
|
||||||
|
const b5 = text(\`;\`);
|
||||||
|
const b6 = text(ctx['tail']);
|
||||||
|
const b7 = text(\`)\`);
|
||||||
|
c_block1[i1] = withKey(multi([b3, b4, b5, b6, b7]), key1);
|
||||||
|
i1++;
|
||||||
|
}
|
||||||
|
return list(c_block1);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`t-for destructuring object items 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { withKey } = helpers;
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
const c_block1 = [];
|
||||||
|
let i1 = 0;
|
||||||
|
for ({k:ctx['k'],v:ctx['v']} of [{k:'a',v:1},{k:'b',v:2}]) {
|
||||||
|
const key1 = ctx['k'];
|
||||||
|
const b3 = text(\`(\`);
|
||||||
|
const b4 = text(ctx['k']);
|
||||||
|
const b5 = text(\`: \`);
|
||||||
|
const b6 = text(ctx['v']);
|
||||||
|
const b7 = text(\`)\`);
|
||||||
|
c_block1[i1] = withKey(multi([b3, b4, b5, b6, b7]), key1);
|
||||||
|
i1++;
|
||||||
|
}
|
||||||
|
return list(c_block1);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`t-for destructuring object items: rest 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { withKey } = helpers;
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
const c_block1 = [];
|
||||||
|
let i1 = 0;
|
||||||
|
for ({k:ctx['k'],v:ctx['v']} of [{k:'a',v:1},{k:'b',v:2}]) {
|
||||||
|
const key1 = ctx['k'];
|
||||||
|
const b3 = text(\`(\`);
|
||||||
|
const b4 = text(ctx['k']);
|
||||||
|
const b5 = text(\`: \`);
|
||||||
|
const b6 = text(ctx['v']);
|
||||||
|
const b7 = text(\`)\`);
|
||||||
|
c_block1[i1] = withKey(multi([b3, b4, b5, b6, b7]), key1);
|
||||||
|
i1++;
|
||||||
|
}
|
||||||
|
return list(c_block1);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`t-for does not pollute the rendering context 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { withKey } = helpers;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
const c_block2 = [];
|
||||||
|
let i1 = 0;
|
||||||
|
for (ctx['item'] of [1]) {
|
||||||
|
const key1 = ctx['item'];
|
||||||
|
c_block2[i1] = withKey(text(ctx['item']), key1);
|
||||||
|
i1++;
|
||||||
|
}
|
||||||
|
const b2 = list(c_block2);
|
||||||
|
return block1([], [b2]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`t-for iterate on items (on a element node) 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { withKey } = helpers;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
let block3 = createBlock(\`<span><block-text-0/></span>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
const c_block2 = [];
|
||||||
|
let i1 = 0;
|
||||||
|
for (ctx['item'] of [1,2]) {
|
||||||
|
const key1 = ctx['item'];
|
||||||
|
let txt1 = ctx['item'];
|
||||||
|
c_block2[i1] = withKey(block3([txt1]), key1);
|
||||||
|
i1++;
|
||||||
|
}
|
||||||
|
const b2 = list(c_block2);
|
||||||
|
return block1([], [b2]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`t-for iterate, Map param 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { withKey } = helpers;
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
const c_block1 = [];
|
||||||
|
let i1 = 0;
|
||||||
|
for ([ctx['key'],ctx['value']] of ctx['map']) {
|
||||||
|
const key1 = ctx['key'];
|
||||||
|
const b3 = text(\` [\`);
|
||||||
|
const b4 = text(ctx['key']);
|
||||||
|
const b5 = text(\`: \`);
|
||||||
|
const b6 = text(ctx['value']);
|
||||||
|
const b7 = text(\`] \`);
|
||||||
|
c_block1[i1] = withKey(multi([b3, b4, b5, b6, b7]), key1);
|
||||||
|
i1++;
|
||||||
|
}
|
||||||
|
return list(c_block1);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`t-for iterate, Set param 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { withKey } = helpers;
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
const c_block1 = [];
|
||||||
|
let i1 = 0;
|
||||||
|
for (ctx['item'] of ctx['set']) {
|
||||||
|
const key1 = ctx['item'];
|
||||||
|
c_block1[i1] = withKey(text(ctx['item']), key1);
|
||||||
|
i1++;
|
||||||
|
}
|
||||||
|
return list(c_block1);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`t-for iterate, generator param 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { withKey } = helpers;
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
const c_block1 = [];
|
||||||
|
let i1 = 0;
|
||||||
|
for (ctx['item'] of ctx['gen']()) {
|
||||||
|
const key1 = ctx['item'];
|
||||||
|
c_block1[i1] = withKey(text(ctx['item']), key1);
|
||||||
|
i1++;
|
||||||
|
}
|
||||||
|
return list(c_block1);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`t-for iterate, iterable param 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { withKey } = helpers;
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
const c_block1 = [];
|
||||||
|
let i1 = 0;
|
||||||
|
for (ctx['item'] of ctx['map'].values()) {
|
||||||
|
const key1 = ctx['item'];
|
||||||
|
c_block1[i1] = withKey(text(ctx['item']), key1);
|
||||||
|
i1++;
|
||||||
|
}
|
||||||
|
return list(c_block1);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`t-for nested destructuring 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { withKey } = helpers;
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
const c_block1 = [];
|
||||||
|
let i1 = 0;
|
||||||
|
for ([ctx['key'],{left:ctx['left'],right:ctx['right']}] of Object.entries(ctx['obj'])) {
|
||||||
|
const key1 = ctx['key'];
|
||||||
|
const b3 = text(\`(\`);
|
||||||
|
const b4 = text(ctx['key']);
|
||||||
|
const b5 = text(\`: [\`);
|
||||||
|
const b6 = text(ctx['left']);
|
||||||
|
const b7 = text(\`, \`);
|
||||||
|
const b8 = text(ctx['right']);
|
||||||
|
const b9 = text(\`])\`);
|
||||||
|
c_block1[i1] = withKey(multi([b3, b4, b5, b6, b7, b8, b9]), key1);
|
||||||
|
i1++;
|
||||||
|
}
|
||||||
|
return list(c_block1);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`t-for simple iteration (in a node) 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { withKey } = helpers;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
const c_block2 = [];
|
||||||
|
let i1 = 0;
|
||||||
|
for (ctx['item'] of [3,2,1]) {
|
||||||
|
const key1 = ctx['item'];
|
||||||
|
c_block2[i1] = withKey(text(ctx['item']), key1);
|
||||||
|
i1++;
|
||||||
|
}
|
||||||
|
const b2 = list(c_block2);
|
||||||
|
return block1([], [b2]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`t-for simple iteration 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { withKey } = helpers;
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
const c_block1 = [];
|
||||||
|
let i1 = 0;
|
||||||
|
for (ctx['item'] of [3,2,1]) {
|
||||||
|
const key1 = ctx['item'];
|
||||||
|
c_block1[i1] = withKey(text(ctx['item']), key1);
|
||||||
|
i1++;
|
||||||
|
}
|
||||||
|
return list(c_block1);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`t-for simple iteration with two nodes inside 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { withKey } = helpers;
|
||||||
|
|
||||||
|
let block3 = createBlock(\`<span>a<block-text-0/></span>\`);
|
||||||
|
let block4 = createBlock(\`<span>b<block-text-0/></span>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
const c_block1 = [];
|
||||||
|
let i1 = 0;
|
||||||
|
for (ctx['item'] of [3,2,1]) {
|
||||||
|
const key1 = ctx['item'];
|
||||||
|
let txt1 = ctx['item'];
|
||||||
|
const b3 = block3([txt1]);
|
||||||
|
let txt2 = ctx['item'];
|
||||||
|
const b4 = block4([txt2]);
|
||||||
|
c_block1[i1] = withKey(multi([b3, b4]), key1);
|
||||||
|
i1++;
|
||||||
|
}
|
||||||
|
return list(c_block1);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`t-for t-call with body in t-for in t-for 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { isBoundary, withDefault, setContextValue, withKey } = helpers;
|
||||||
|
const callTemplate_1 = app.getTemplate(\`sub\`);
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div><block-child-0/><span>[<block-text-0/>][<block-text-1/>][<block-text-2/>]</span></div>\`);
|
||||||
|
let block6 = createBlock(\`<span><block-text-0/></span>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
ctx[isBoundary] = 1
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
const c_block2 = [];
|
||||||
|
let i1 = 0;
|
||||||
|
for (ctx['a'] of ctx['numbers']) {
|
||||||
|
const key1 = ctx['a'];
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
const c_block4 = [];
|
||||||
|
let i2 = 0;
|
||||||
|
for (ctx['b'] of ctx['letters']) {
|
||||||
|
const key2 = ctx['b'];
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
ctx[isBoundary] = 1;
|
||||||
|
setContextValue(ctx, \\"c\\", 'x'+'_'+ctx['a']+'_'+ctx['b']);
|
||||||
|
c_block4[i2] = withKey(callTemplate_1.call(this, ctx, node, key + \`__1__\${key1}__\${key2}\`), key2);
|
||||||
|
ctx = ctx.__proto__;
|
||||||
|
i2++;
|
||||||
|
}
|
||||||
|
ctx = ctx.__proto__;
|
||||||
|
const b4 = list(c_block4);
|
||||||
|
let txt1 = ctx['c'];
|
||||||
|
const b6 = block6([txt1]);
|
||||||
|
c_block2[i1] = withKey(multi([b4, b6]), key1);
|
||||||
|
i1++;
|
||||||
|
}
|
||||||
|
ctx = ctx.__proto__;
|
||||||
|
const b2 = list(c_block2);
|
||||||
|
let txt2 = ctx['a'];
|
||||||
|
let txt3 = ctx['b'];
|
||||||
|
let txt4 = ctx['c'];
|
||||||
|
return block1([txt2, txt3, txt4], [b2]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`t-for t-call with body in t-for in t-for 2`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
const b2 = text(\` [\`);
|
||||||
|
const b3 = text(ctx['a']);
|
||||||
|
const b4 = text(\`] [\`);
|
||||||
|
const b5 = text(ctx['b']);
|
||||||
|
const b6 = text(\`] [\`);
|
||||||
|
const b7 = text(ctx['c']);
|
||||||
|
const b8 = text(\`] \`);
|
||||||
|
return multi([b2, b3, b4, b5, b6, b7, b8]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`t-for t-call without body in t-for in t-for 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { withKey } = helpers;
|
||||||
|
const callTemplate_1 = app.getTemplate(\`sub\`);
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div><block-child-0/><span>[<block-text-0/>][<block-text-1/>][<block-text-2/>]</span></div>\`);
|
||||||
|
let block6 = createBlock(\`<span><block-text-0/></span>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
const c_block2 = [];
|
||||||
|
let i1 = 0;
|
||||||
|
for (ctx['a'] of ctx['numbers']) {
|
||||||
|
const key1 = ctx['a'];
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
const c_block4 = [];
|
||||||
|
let i2 = 0;
|
||||||
|
for (ctx['b'] of ctx['letters']) {
|
||||||
|
const key2 = ctx['b'];
|
||||||
|
c_block4[i2] = withKey(callTemplate_1.call(this, ctx, node, key + \`__1__\${key1}__\${key2}\`), key2);
|
||||||
|
i2++;
|
||||||
|
}
|
||||||
|
ctx = ctx.__proto__;
|
||||||
|
const b4 = list(c_block4);
|
||||||
|
let txt1 = ctx['c'];
|
||||||
|
const b6 = block6([txt1]);
|
||||||
|
c_block2[i1] = withKey(multi([b4, b6]), key1);
|
||||||
|
i1++;
|
||||||
|
}
|
||||||
|
ctx = ctx.__proto__;
|
||||||
|
const b2 = list(c_block2);
|
||||||
|
let txt2 = ctx['a'];
|
||||||
|
let txt3 = ctx['b'];
|
||||||
|
let txt4 = ctx['c'];
|
||||||
|
return block1([txt2, txt3, txt4], [b2]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`t-for t-call without body in t-for in t-for 2`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { isBoundary, withDefault, setContextValue } = helpers;
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
ctx[isBoundary] = 1
|
||||||
|
setContextValue(ctx, \\"c\\", 'x'+'_'+ctx['a']+'_'+ctx['b']);
|
||||||
|
const b2 = text(\` [\`);
|
||||||
|
const b3 = text(ctx['a']);
|
||||||
|
const b4 = text(\`] [\`);
|
||||||
|
const b5 = text(ctx['b']);
|
||||||
|
const b6 = text(\`] [\`);
|
||||||
|
const b7 = text(ctx['c']);
|
||||||
|
const b8 = text(\`] \`);
|
||||||
|
return multi([b2, b3, b4, b5, b6, b7, b8]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`t-for t-for in t-for 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { withKey } = helpers;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
const c_block2 = [];
|
||||||
|
let i1 = 0;
|
||||||
|
for (ctx['number'] of ctx['numbers']) {
|
||||||
|
const key1 = ctx['number'];
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
const c_block3 = [];
|
||||||
|
let i2 = 0;
|
||||||
|
for (ctx['letter'] of ctx['letters']) {
|
||||||
|
const key2 = ctx['letter'];
|
||||||
|
const b5 = text(\` [\`);
|
||||||
|
const b6 = text(ctx['number']);
|
||||||
|
const b7 = text(ctx['letter']);
|
||||||
|
const b8 = text(\`] \`);
|
||||||
|
c_block3[i2] = withKey(multi([b5, b6, b7, b8]), key2);
|
||||||
|
i2++;
|
||||||
|
}
|
||||||
|
ctx = ctx.__proto__;
|
||||||
|
c_block2[i1] = withKey(list(c_block3), key1);
|
||||||
|
i1++;
|
||||||
|
}
|
||||||
|
const b2 = list(c_block2);
|
||||||
|
return block1([], [b2]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`t-for t-for in t-foreach 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { prepareList, withKey } = helpers;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['numbers']);;
|
||||||
|
for (let i1 = 0; i1 < l_block2; i1++) {
|
||||||
|
ctx[\`number\`] = v_block2[i1];
|
||||||
|
const key1 = ctx['number'];
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
const c_block3 = [];
|
||||||
|
let i2 = 0;
|
||||||
|
for (ctx['letter'] of ctx['letters']) {
|
||||||
|
const key2 = ctx['letter'];
|
||||||
|
const b5 = text(\` [\`);
|
||||||
|
const b6 = text(ctx['number']);
|
||||||
|
const b7 = text(ctx['letter']);
|
||||||
|
const b8 = text(\`] \`);
|
||||||
|
c_block3[i2] = withKey(multi([b5, b6, b7, b8]), key2);
|
||||||
|
i2++;
|
||||||
|
}
|
||||||
|
ctx = ctx.__proto__;
|
||||||
|
c_block2[i1] = withKey(list(c_block3), key1);
|
||||||
|
}
|
||||||
|
const b2 = list(c_block2);
|
||||||
|
return block1([], [b2]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`t-for t-for with t-if inside (no external node) 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { withKey } = helpers;
|
||||||
|
|
||||||
|
let block3 = createBlock(\`<span><block-text-0/></span>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
const c_block1 = [];
|
||||||
|
let i1 = 0;
|
||||||
|
for ({id:ctx['id'],text:ctx['text']} of ctx['elems']) {
|
||||||
|
const key1 = ctx['id'];
|
||||||
|
let b3;
|
||||||
|
if (ctx['id']<3) {
|
||||||
|
let txt1 = ctx['text'];
|
||||||
|
b3 = block3([txt1]);
|
||||||
|
}
|
||||||
|
c_block1[i1] = withKey(multi([b3]), key1);
|
||||||
|
i1++;
|
||||||
|
}
|
||||||
|
return list(c_block1);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`t-for t-for with t-if inside 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { withKey } = helpers;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
let block4 = createBlock(\`<span><block-text-0/></span>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
const c_block2 = [];
|
||||||
|
let i1 = 0;
|
||||||
|
for ({id:ctx['id'],text:ctx['text']} of ctx['elems']) {
|
||||||
|
const key1 = ctx['id'];
|
||||||
|
let b4;
|
||||||
|
if (ctx['id']<3) {
|
||||||
|
let txt1 = ctx['text'];
|
||||||
|
b4 = block4([txt1]);
|
||||||
|
}
|
||||||
|
c_block2[i1] = withKey(multi([b4]), key1);
|
||||||
|
i1++;
|
||||||
|
}
|
||||||
|
const b2 = list(c_block2);
|
||||||
|
return block1([], [b2]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`t-for t-foreach in t-for 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { prepareList, withKey } = helpers;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
const c_block2 = [];
|
||||||
|
let i1 = 0;
|
||||||
|
for (ctx['number'] of ctx['numbers']) {
|
||||||
|
const key1 = ctx['number'];
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
const [k_block3, v_block3, l_block3, c_block3] = prepareList(ctx['letters']);;
|
||||||
|
for (let i2 = 0; i2 < l_block3; i2++) {
|
||||||
|
ctx[\`letter\`] = v_block3[i2];
|
||||||
|
const key2 = ctx['letter'];
|
||||||
|
const b5 = text(\` [\`);
|
||||||
|
const b6 = text(ctx['number']);
|
||||||
|
const b7 = text(ctx['letter']);
|
||||||
|
const b8 = text(\`] \`);
|
||||||
|
c_block3[i2] = withKey(multi([b5, b6, b7, b8]), key2);
|
||||||
|
}
|
||||||
|
ctx = ctx.__proto__;
|
||||||
|
c_block2[i1] = withKey(list(c_block3), key1);
|
||||||
|
i1++;
|
||||||
|
}
|
||||||
|
const b2 = list(c_block2);
|
||||||
|
return block1([], [b2]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`t-for t-key on t-for 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { withKey } = helpers;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
let block3 = createBlock(\`<span/>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
const c_block2 = [];
|
||||||
|
let i1 = 0;
|
||||||
|
for (ctx['thing'] of ctx['things']) {
|
||||||
|
const key1 = ctx['thing'];
|
||||||
|
c_block2[i1] = withKey(block3(), key1);
|
||||||
|
i1++;
|
||||||
|
}
|
||||||
|
const b2 = list(c_block2);
|
||||||
|
return block1([], [b2]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`t-for throws error if invalid loop expression 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { withKey } = helpers;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
let block3 = createBlock(\`<span/>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
const c_block2 = [];
|
||||||
|
let i1 = 0;
|
||||||
|
for (ctx['item'] of ctx['abc']) {
|
||||||
|
const key1 = ctx['item'];
|
||||||
|
const tKey_1 = ctx['item'];
|
||||||
|
c_block2[i1] = withKey(block3(), tKey_1 + key1);
|
||||||
|
i1++;
|
||||||
|
}
|
||||||
|
const b2 = list(c_block2);
|
||||||
|
return block1([], [b2]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
@@ -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
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -335,6 +335,99 @@ exports[`t-set t-set evaluates an expression only once 1`] = `
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`t-set t-set outside modified in t-for 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { isBoundary, withDefault, setContextValue, withKey } = helpers;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div><block-child-0/><p>EndLoop: <block-text-0/></p></div>\`);
|
||||||
|
let block3 = createBlock(\`<p>InLoop: <block-text-0/></p>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
ctx[isBoundary] = 1
|
||||||
|
setContextValue(ctx, \\"iter\\", 0);
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
const c_block2 = [];
|
||||||
|
let i1 = 0;
|
||||||
|
for (ctx['val'] of ['a','b']) {
|
||||||
|
const key1 = ctx['val'];
|
||||||
|
let txt1 = ctx['iter'];
|
||||||
|
c_block2[i1] = withKey(block3([txt1]), key1);
|
||||||
|
setContextValue(ctx, \\"iter\\", ctx['iter']+1);
|
||||||
|
i1++;
|
||||||
|
}
|
||||||
|
ctx = ctx.__proto__;
|
||||||
|
const b2 = list(c_block2);
|
||||||
|
let txt2 = ctx['iter'];
|
||||||
|
return block1([txt2], [b2]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`t-set t-set outside modified in t-for increment-after operator 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { isBoundary, withDefault, setContextValue, withKey } = helpers;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div><block-child-0/><p>EndLoop: <block-text-0/></p></div>\`);
|
||||||
|
let block3 = createBlock(\`<p>InLoop: <block-text-0/></p>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
ctx[isBoundary] = 1
|
||||||
|
setContextValue(ctx, \\"iter\\", 0);
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
const c_block2 = [];
|
||||||
|
let i1 = 0;
|
||||||
|
for (ctx['val'] of ['a','b']) {
|
||||||
|
const key1 = ctx['val'];
|
||||||
|
let txt1 = ctx['iter'];
|
||||||
|
c_block2[i1] = withKey(block3([txt1]), key1);
|
||||||
|
setContextValue(ctx, \\"iter\\", ctx['iter']++);
|
||||||
|
i1++;
|
||||||
|
}
|
||||||
|
ctx = ctx.__proto__;
|
||||||
|
const b2 = list(c_block2);
|
||||||
|
let txt2 = ctx['iter'];
|
||||||
|
return block1([txt2], [b2]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`t-set t-set outside modified in t-for increment-before operator 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { isBoundary, withDefault, setContextValue, withKey } = helpers;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div><block-child-0/><p>EndLoop: <block-text-0/></p></div>\`);
|
||||||
|
let block3 = createBlock(\`<p>InLoop: <block-text-0/></p>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
ctx[isBoundary] = 1
|
||||||
|
setContextValue(ctx, \\"iter\\", 0);
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
const c_block2 = [];
|
||||||
|
let i1 = 0;
|
||||||
|
for (ctx['val'] of ['a','b']) {
|
||||||
|
const key1 = ctx['val'];
|
||||||
|
let txt1 = ctx['iter'];
|
||||||
|
c_block2[i1] = withKey(block3([txt1]), key1);
|
||||||
|
setContextValue(ctx, \\"iter\\", ++ctx['iter']);
|
||||||
|
i1++;
|
||||||
|
}
|
||||||
|
ctx = ctx.__proto__;
|
||||||
|
const b2 = list(c_block2);
|
||||||
|
let txt2 = ctx['iter'];
|
||||||
|
return block1([txt2], [b2]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`t-set t-set outside modified in t-foreach 1`] = `
|
exports[`t-set t-set outside modified in t-foreach 1`] = `
|
||||||
"function anonymous(app, bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
@@ -454,6 +547,35 @@ exports[`t-set t-set should reuse variable if possible 1`] = `
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`t-set t-set should reuse variable if possible: for..of 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { isBoundary, withDefault, setContextValue, withKey } = helpers;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
let block3 = createBlock(\`<div><span>v<block-text-0/></span></div>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
ctx[isBoundary] = 1
|
||||||
|
setContextValue(ctx, \\"v\\", 1);
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
const c_block2 = [];
|
||||||
|
let i1 = 0;
|
||||||
|
for (ctx['elem'] of ctx['list']) {
|
||||||
|
const key1 = ctx['elem_index'];
|
||||||
|
let txt1 = ctx['v'];
|
||||||
|
setContextValue(ctx, \\"v\\", ctx['elem']);
|
||||||
|
c_block2[i1] = withKey(block3([txt1]), key1);
|
||||||
|
i1++;
|
||||||
|
}
|
||||||
|
const b2 = list(c_block2);
|
||||||
|
return block1([], [b2]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`t-set t-set with content and sub t-esc 1`] = `
|
exports[`t-set t-set with content and sub t-esc 1`] = `
|
||||||
"function anonymous(app, bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -371,4 +371,33 @@ describe("attributes", () => {
|
|||||||
// not sure about this. maybe we want to remove the attribute?
|
// not sure about this. maybe we want to remove the attribute?
|
||||||
expect(fixture.innerHTML).toBe('<div class="hoy a b"></div>');
|
expect(fixture.innerHTML).toBe('<div class="hoy a b"></div>');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("various combinations of class, t-att-class, and t-att", () => {
|
||||||
|
const template1 = `<div t-att="{ class: 'a' }" class="c">content</div>`;
|
||||||
|
expect(renderToString(template1)).toBe('<div class="c a">content</div>');
|
||||||
|
|
||||||
|
const template2 = `<div t-att="{ class: 'a' }" t-att-class="{'b': true}" class="c">content</div>`;
|
||||||
|
expect(renderToString(template2)).toBe('<div class="c a b">content</div>');
|
||||||
|
|
||||||
|
const template3 = `<div t-att="{ class: 'a' }" class="c" t-att-class="{'b': true}">content</div>`;
|
||||||
|
expect(renderToString(template3)).toBe('<div class="c a b">content</div>');
|
||||||
|
|
||||||
|
const template4 = `<div class="c" t-att="{ class: 'a' }" t-att-class="{'b': true}">content</div>`;
|
||||||
|
expect(renderToString(template4)).toBe('<div class="c a b">content</div>');
|
||||||
|
|
||||||
|
const template5 = `<div class="c" t-att-class="{'b': true}" t-att="{ class: 'a' }">content</div>`;
|
||||||
|
expect(renderToString(template5)).toBe('<div class="c b a">content</div>');
|
||||||
|
|
||||||
|
const template6 = `<div class="c" t-att-class="{'b': true}">content</div>`;
|
||||||
|
expect(renderToString(template6)).toBe('<div class="c b">content</div>');
|
||||||
|
|
||||||
|
const template7 = `<div class="c" t-attf-class="{{'b'}}">content</div>`;
|
||||||
|
expect(renderToString(template7)).toBe('<div class="c b">content</div>');
|
||||||
|
|
||||||
|
const template8 = `<div t-att="{ class: 'a' }" class="c" t-att-class="{'b': true}">content</div>`;
|
||||||
|
expect(renderToString(template8)).toBe('<div class="c a b">content</div>');
|
||||||
|
|
||||||
|
const template9 = `<div t-att="{ class: 'a' }" t-att-class="{'b': true}">content</div>`;
|
||||||
|
expect(renderToString(template9)).toBe('<div class="a b">content</div>');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1569,6 +1569,12 @@ describe("qweb parser", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("component with t-out", async () => {
|
||||||
|
expect(parse(`<MyComponent t-out="someValue"/>`)).toEqual(
|
||||||
|
parse(`<MyComponent><t t-out="someValue"/></MyComponent>`)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
test("component with t-esc and content", async () => {
|
test("component with t-esc and content", async () => {
|
||||||
expect(() => parse(`<MyComponent t-esc="someValue">Some content</MyComponent>`)).toThrow(
|
expect(() => parse(`<MyComponent t-esc="someValue">Some content</MyComponent>`)).toThrow(
|
||||||
"Cannot have t-esc on a component that already has content"
|
"Cannot have t-esc on a component that already has content"
|
||||||
@@ -1991,8 +1997,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",
|
||||||
|
|||||||
@@ -0,0 +1,317 @@
|
|||||||
|
import {
|
||||||
|
renderToBdom,
|
||||||
|
renderToString,
|
||||||
|
snapshotEverything,
|
||||||
|
TestContext,
|
||||||
|
makeTestFixture,
|
||||||
|
} from "../helpers";
|
||||||
|
import { mount, patch } from "../../src/runtime/blockdom";
|
||||||
|
|
||||||
|
snapshotEverything();
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// t-for
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
describe("t-for", () => {
|
||||||
|
test("simple iteration", () => {
|
||||||
|
const template = `<t t-for="item" t-of="[3, 2, 1]" t-key="item"><t t-esc="item"/></t>`;
|
||||||
|
expect(renderToString(template)).toBe("321");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("simple iteration with two nodes inside", () => {
|
||||||
|
const template = `
|
||||||
|
<t t-for="item" t-of="[3, 2, 1]" t-key="item">
|
||||||
|
<span>a<t t-esc="item"/></span>
|
||||||
|
<span>b<t t-esc="item"/></span>
|
||||||
|
</t>`;
|
||||||
|
const expected =
|
||||||
|
"<span>a3</span><span>b3</span><span>a2</span><span>b2</span><span>a1</span><span>b1</span>";
|
||||||
|
expect(renderToString(template)).toBe(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("destructuring array items", () => {
|
||||||
|
const template = `<t t-for="[key, value]" t-of="Object.entries({ a: 1, b: 2 })" t-key="key">(<t t-esc="key"/>: <t t-esc="value"/>)</t>`;
|
||||||
|
expect(renderToString(template)).toBe("(a: 1)(b: 2)");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("destructuring array items: rest", () => {
|
||||||
|
const template = `<t t-for="[head, ...tail]" t-of="[[1, 2, 3], [4, 5, 6]]" t-key="head">(<t t-esc="head"/>;<t t-esc="tail"/>)</t>`;
|
||||||
|
expect(renderToString(template)).toBe("(1;2,3)(4;5,6)");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("destructuring object items", () => {
|
||||||
|
const template = `<t t-for="{ k, v }" t-of="[{ k: 'a', v: 1 }, { k: 'b', v: 2 }]" t-key="k">(<t t-esc="k"/>: <t t-esc="v"/>)</t>`;
|
||||||
|
expect(renderToString(template)).toBe("(a: 1)(b: 2)");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("destructuring object items: rest", () => {
|
||||||
|
const template = `<t t-for="{ k, v }" t-of="[{ k: 'a', v: 1 }, { k: 'b', v: 2 }]" t-key="k">(<t t-esc="k"/>: <t t-esc="v"/>)</t>`;
|
||||||
|
expect(renderToString(template)).toBe("(a: 1)(b: 2)");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("nested destructuring", () => {
|
||||||
|
const template = `<t t-for="[key, {left, right}]" t-of="Object.entries(obj)" t-key="key">(<t t-esc="key"/>: [<t t-esc="left"/>, <t t-esc="right"/>])</t>`;
|
||||||
|
expect(
|
||||||
|
renderToString(template, {
|
||||||
|
obj: {
|
||||||
|
a: { left: 1, right: 2 },
|
||||||
|
b: { left: 3, right: 4 },
|
||||||
|
},
|
||||||
|
})
|
||||||
|
).toBe("(a: [1, 2])(b: [3, 4])");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("t-key on t-for", async () => {
|
||||||
|
const template = `
|
||||||
|
<div>
|
||||||
|
<t t-for="thing" t-of="things" t-key="thing">
|
||||||
|
<span/>
|
||||||
|
</t>
|
||||||
|
</div>`;
|
||||||
|
|
||||||
|
const fixture = makeTestFixture();
|
||||||
|
|
||||||
|
const vnode1 = renderToBdom(template, { things: [1, 2] });
|
||||||
|
mount(vnode1, fixture);
|
||||||
|
let elm = fixture;
|
||||||
|
expect(elm.innerHTML).toBe("<div><span></span><span></span></div>");
|
||||||
|
const first = elm.querySelectorAll("span")[0];
|
||||||
|
const second = elm.querySelectorAll("span")[1];
|
||||||
|
|
||||||
|
const vnode2 = renderToBdom(template, { things: [2, 1] });
|
||||||
|
patch(vnode1, vnode2);
|
||||||
|
|
||||||
|
expect(elm.innerHTML).toBe("<div><span></span><span></span></div>");
|
||||||
|
expect(first).toBe(elm.querySelectorAll("span")[1]);
|
||||||
|
expect(second).toBe(elm.querySelectorAll("span")[0]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("simple iteration (in a node)", () => {
|
||||||
|
const template = `
|
||||||
|
<div>
|
||||||
|
<t t-for="item" t-of="[3, 2, 1]" t-key="item"><t t-esc="item"/></t>
|
||||||
|
</div>`;
|
||||||
|
expect(renderToString(template)).toBe("<div>321</div>");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("iterate on items (on a element node)", () => {
|
||||||
|
const template = `
|
||||||
|
<div>
|
||||||
|
<span t-for="item" t-of="[1, 2]" t-key="item"><t t-esc="item"/></span>
|
||||||
|
</div>`;
|
||||||
|
const expected = `<div><span>1</span><span>2</span></div>`;
|
||||||
|
expect(renderToString(template)).toBe(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("iterate, Map param", () => {
|
||||||
|
const template = `
|
||||||
|
<t t-for="[key, value]" t-of="map" t-key="key">
|
||||||
|
[<t t-esc="key"/>: <t t-esc="value"/>]
|
||||||
|
</t>`;
|
||||||
|
const expected = ` [a: 1] [b: 2] [c: 3] `;
|
||||||
|
const context = {
|
||||||
|
map: new Map([
|
||||||
|
["a", 1],
|
||||||
|
["b", 2],
|
||||||
|
["c", 3],
|
||||||
|
]),
|
||||||
|
};
|
||||||
|
expect(renderToString(template, context)).toBe(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("iterate, Set param", () => {
|
||||||
|
const template = `
|
||||||
|
<t t-for="item" t-of="set" t-key="item">
|
||||||
|
<t t-esc="item"/>
|
||||||
|
</t>`;
|
||||||
|
const expected = `123`;
|
||||||
|
const context = { set: new Set([1, 2, 3]) };
|
||||||
|
expect(renderToString(template, context)).toBe(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("iterate, iterable param", () => {
|
||||||
|
const template = `
|
||||||
|
<t t-for="item" t-of="map.values()" t-key="item">
|
||||||
|
<t t-esc="item"/>
|
||||||
|
</t>`;
|
||||||
|
const expected = `123`;
|
||||||
|
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-for="item" t-of="gen()" t-key="item">
|
||||||
|
<t t-esc="item"/>
|
||||||
|
</t>`;
|
||||||
|
const expected = `123`;
|
||||||
|
const context = {
|
||||||
|
*gen() {
|
||||||
|
yield 1;
|
||||||
|
yield 2;
|
||||||
|
yield 3;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
expect(renderToString(template, context)).toBe(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("does not pollute the rendering context", () => {
|
||||||
|
const template = `
|
||||||
|
<div>
|
||||||
|
<t t-for="item" t-of="[1]" t-key="item"><t t-esc="item"/></t>
|
||||||
|
</div>`;
|
||||||
|
const context = { __owl__: {} };
|
||||||
|
renderToString(template, context);
|
||||||
|
expect(Object.keys(context)).toEqual(["__owl__"]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("t-for in t-for", () => {
|
||||||
|
const template = `
|
||||||
|
<div>
|
||||||
|
<t t-for="number" t-of="numbers" t-key="number">
|
||||||
|
<t t-for="letter" t-of="letters" t-key="letter">
|
||||||
|
[<t t-esc="number"/><t t-esc="letter"/>]
|
||||||
|
</t>
|
||||||
|
</t>
|
||||||
|
</div>`;
|
||||||
|
|
||||||
|
const context = { numbers: [1, 2, 3], letters: ["a", "b"] };
|
||||||
|
const expected = "<div> [1a] [1b] [2a] [2b] [3a] [3b] </div>";
|
||||||
|
expect(renderToString(template, context)).toBe(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("t-for in t-foreach", () => {
|
||||||
|
const template = `
|
||||||
|
<div>
|
||||||
|
<t t-foreach="numbers" t-as="number" t-key="number">
|
||||||
|
<t t-for="letter" t-of="letters" t-key="letter">
|
||||||
|
[<t t-esc="number"/><t t-esc="letter"/>]
|
||||||
|
</t>
|
||||||
|
</t>
|
||||||
|
</div>`;
|
||||||
|
|
||||||
|
const context = { numbers: [1, 2, 3], letters: ["a", "b"] };
|
||||||
|
const expected = "<div> [1a] [1b] [2a] [2b] [3a] [3b] </div>";
|
||||||
|
expect(renderToString(template, context)).toBe(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("t-foreach in t-for", () => {
|
||||||
|
const template = `
|
||||||
|
<div>
|
||||||
|
<t t-for="number" t-of="numbers" t-key="number">
|
||||||
|
<t t-foreach="letters" t-as="letter" t-key="letter">
|
||||||
|
[<t t-esc="number"/><t t-esc="letter"/>]
|
||||||
|
</t>
|
||||||
|
</t>
|
||||||
|
</div>`;
|
||||||
|
|
||||||
|
const context = { numbers: [1, 2, 3], letters: ["a", "b"] };
|
||||||
|
const expected = "<div> [1a] [1b] [2a] [2b] [3a] [3b] </div>";
|
||||||
|
expect(renderToString(template, context)).toBe(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("t-call without body in t-for in t-for", () => {
|
||||||
|
const context = new TestContext();
|
||||||
|
const sub = `
|
||||||
|
<t>
|
||||||
|
<t t-set="c" t-value="'x' + '_' + a + '_'+ b" />
|
||||||
|
[<t t-esc="a" />]
|
||||||
|
[<t t-esc="b" />]
|
||||||
|
[<t t-esc="c" />]
|
||||||
|
</t>`;
|
||||||
|
|
||||||
|
const main = `
|
||||||
|
<div>
|
||||||
|
<t t-for="a" t-of="numbers" t-key="a">
|
||||||
|
<t t-for="b" t-of="letters" t-key="b">
|
||||||
|
<t t-call="sub" />
|
||||||
|
</t>
|
||||||
|
<span t-esc="c"/>
|
||||||
|
</t>
|
||||||
|
<span>[<t t-esc="a" />][<t t-esc="b" />][<t t-esc="c" />]</span>
|
||||||
|
</div>`;
|
||||||
|
|
||||||
|
context.addTemplate("sub", sub);
|
||||||
|
context.addTemplate("main", main);
|
||||||
|
|
||||||
|
const ctx = { numbers: [1, 2, 3], letters: ["a", "b"] };
|
||||||
|
const expected =
|
||||||
|
"<div> [1] [a] [x_1_a] [1] [b] [x_1_b] <span></span> [2] [a] [x_2_a] [2] [b] [x_2_b] <span></span> [3] [a] [x_3_a] [3] [b] [x_3_b] <span></span><span>[][][]</span></div>";
|
||||||
|
expect(context.renderToString("main", ctx)).toBe(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("t-call with body in t-for in t-for", () => {
|
||||||
|
const context = new TestContext();
|
||||||
|
const sub = `
|
||||||
|
<t>
|
||||||
|
[<t t-esc="a" />]
|
||||||
|
[<t t-esc="b" />]
|
||||||
|
[<t t-esc="c" />]
|
||||||
|
</t>`;
|
||||||
|
|
||||||
|
const main = `
|
||||||
|
<div>
|
||||||
|
<t t-for="a" t-of="numbers" t-key="a">
|
||||||
|
<t t-for="b" t-of="letters" t-key="b">
|
||||||
|
<t t-call="sub" >
|
||||||
|
<t t-set="c" t-value="'x' + '_' + a + '_'+ b" />
|
||||||
|
</t>
|
||||||
|
</t>
|
||||||
|
<span t-esc="c"/>
|
||||||
|
</t>
|
||||||
|
<span>[<t t-esc="a" />][<t t-esc="b" />][<t t-esc="c" />]</span>
|
||||||
|
</div>`;
|
||||||
|
|
||||||
|
context.addTemplate("sub", sub);
|
||||||
|
context.addTemplate("main", main);
|
||||||
|
|
||||||
|
const ctx = { numbers: [1, 2, 3], letters: ["a", "b"] };
|
||||||
|
const expected =
|
||||||
|
"<div> [1] [a] [x_1_a] [1] [b] [x_1_b] <span></span> [2] [a] [x_2_a] [2] [b] [x_2_b] <span></span> [3] [a] [x_3_a] [3] [b] [x_3_b] <span></span><span>[][][]</span></div>";
|
||||||
|
expect(context.renderToString("main", ctx)).toBe(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("throws error if invalid loop expression", () => {
|
||||||
|
const test = `<div><t t-for="item" t-of="abc" t-key="item"><span t-key="item"/></t></div>`;
|
||||||
|
expect(() => renderToString(test)).toThrow("ctx.abc is not iterable");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("t-for with t-if inside", () => {
|
||||||
|
const template = `
|
||||||
|
<div>
|
||||||
|
<t t-for="{ id, text }" t-of="elems" t-key="id">
|
||||||
|
<span t-if="id lt 3"><t t-esc="text"/></span>
|
||||||
|
</t>
|
||||||
|
</div>`;
|
||||||
|
const ctx = {
|
||||||
|
elems: [
|
||||||
|
{ id: 1, text: "a" },
|
||||||
|
{ id: 2, text: "b" },
|
||||||
|
{ id: 3, text: "c" },
|
||||||
|
],
|
||||||
|
};
|
||||||
|
expect(renderToString(template, ctx)).toBe("<div><span>a</span><span>b</span></div>");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("t-for with t-if inside (no external node)", () => {
|
||||||
|
const template = `
|
||||||
|
<t t-for="{ id, text }" t-of="elems" t-key="id">
|
||||||
|
<span t-if="id lt 3"><t t-esc="text"/></span>
|
||||||
|
</t>`;
|
||||||
|
const ctx = {
|
||||||
|
elems: [
|
||||||
|
{ id: 1, text: "a" },
|
||||||
|
{ id: 2, text: "b" },
|
||||||
|
{ id: 3, text: "c" },
|
||||||
|
],
|
||||||
|
};
|
||||||
|
expect(renderToString(template, ctx)).toBe("<span>a</span><span>b</span>");
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -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", () => {
|
||||||
|
|||||||
@@ -122,6 +122,19 @@ describe("t-set", () => {
|
|||||||
expect(renderToString(template, { list: ["a", "b"] })).toBe(expected);
|
expect(renderToString(template, { list: ["a", "b"] })).toBe(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("t-set should reuse variable if possible: for..of", () => {
|
||||||
|
const template = `
|
||||||
|
<div>
|
||||||
|
<t t-set="v" t-value="1"/>
|
||||||
|
<div t-for="elem" t-of="list" t-key="elem_index">
|
||||||
|
<span>v<t t-esc="v"/></span>
|
||||||
|
<t t-set="v" t-value="elem"/>
|
||||||
|
</div>
|
||||||
|
</div>`;
|
||||||
|
const expected = "<div><div><span>v1</span></div><div><span>va</span></div></div>";
|
||||||
|
expect(renderToString(template, { list: ["a", "b"] })).toBe(expected);
|
||||||
|
});
|
||||||
|
|
||||||
test("t-set with content and sub t-esc", () => {
|
test("t-set with content and sub t-esc", () => {
|
||||||
const template = `
|
const template = `
|
||||||
<div>
|
<div>
|
||||||
@@ -232,6 +245,22 @@ describe("t-set", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("t-set outside modified in t-for", async () => {
|
||||||
|
const template = `
|
||||||
|
<div>
|
||||||
|
<t t-set="iter" t-value="0"/>
|
||||||
|
<t t-for="val" t-of="['a','b']" t-key="val">
|
||||||
|
<p>InLoop: <t t-esc="iter"/></p>
|
||||||
|
<t t-set="iter" t-value="iter + 1"/>
|
||||||
|
</t>
|
||||||
|
<p>EndLoop: <t t-esc="iter"/></p>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
expect(renderToString(template)).toBe(
|
||||||
|
"<div><p>InLoop: 0</p><p>InLoop: 1</p><p>EndLoop: 2</p></div>"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
test("t-set outside modified in t-foreach increment-after operator", async () => {
|
test("t-set outside modified in t-foreach increment-after operator", async () => {
|
||||||
const template = `
|
const template = `
|
||||||
<div>
|
<div>
|
||||||
@@ -248,6 +277,22 @@ describe("t-set", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("t-set outside modified in t-for increment-after operator", async () => {
|
||||||
|
const template = `
|
||||||
|
<div>
|
||||||
|
<t t-set="iter" t-value="0"/>
|
||||||
|
<t t-for="val" t-of="['a','b']" t-key="val">
|
||||||
|
<p>InLoop: <t t-esc="iter"/></p>
|
||||||
|
<t t-set="iter" t-value="iter++"/>
|
||||||
|
</t>
|
||||||
|
<p>EndLoop: <t t-esc="iter"/></p>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
expect(renderToString(template)).toBe(
|
||||||
|
"<div><p>InLoop: 0</p><p>InLoop: 0</p><p>EndLoop: 0</p></div>"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
test("t-set outside modified in t-foreach increment-before operator", async () => {
|
test("t-set outside modified in t-foreach increment-before operator", async () => {
|
||||||
const template = `
|
const template = `
|
||||||
<div>
|
<div>
|
||||||
@@ -264,6 +309,22 @@ describe("t-set", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("t-set outside modified in t-for increment-before operator", async () => {
|
||||||
|
const template = `
|
||||||
|
<div>
|
||||||
|
<t t-set="iter" t-value="0"/>
|
||||||
|
<t t-for="val" t-of="['a','b']" t-key="val">
|
||||||
|
<p>InLoop: <t t-esc="iter"/></p>
|
||||||
|
<t t-set="iter" t-value="++iter"/>
|
||||||
|
</t>
|
||||||
|
<p>EndLoop: <t t-esc="iter"/></p>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
expect(renderToString(template)).toBe(
|
||||||
|
"<div><p>InLoop: 0</p><p>InLoop: 1</p><p>EndLoop: 0</p></div>"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
test("t-set can't alter from within callee", async () => {
|
test("t-set can't alter from within callee", async () => {
|
||||||
const context = new TestContext();
|
const context = new TestContext();
|
||||||
const sub = `<div><t t-esc="iter"/><t t-set="iter" t-value="'called'"/><t t-esc="iter"/></div>`;
|
const sub = `<div><t t-esc="iter"/><t t-set="iter" t-value="'called'"/><t t-esc="iter"/></div>`;
|
||||||
|
|||||||
@@ -37,4 +37,22 @@ describe("basic validation", () => {
|
|||||||
const template = `<div t-best-beer="rochefort 10">test</div>`;
|
const template = `<div t-best-beer="rochefort 10">test</div>`;
|
||||||
expect(() => renderToString(template)).toThrow("Unknown QWeb directive: 't-best-beer'");
|
expect(() => renderToString(template)).toThrow("Unknown QWeb directive: 't-best-beer'");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("compilation error", () => {
|
||||||
|
const template = `<div t-att-class="a b">test</div>`;
|
||||||
|
expect(() => renderToString(template))
|
||||||
|
.toThrow(`Failed to compile anonymous template: Unexpected identifier
|
||||||
|
|
||||||
|
generated code:
|
||||||
|
function(app, bdom, helpers) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div block-attribute-0="class">test</div>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = "") {
|
||||||
|
let attr1 = ctx['a']ctx['b'];
|
||||||
|
return block1([attr1]);
|
||||||
|
}
|
||||||
|
}`);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -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
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -12,6 +12,18 @@ exports[`basics display a nice error if a component is not a component 1`] = `
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`basics display a nice error if a non-root component template fails to compile 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
const comp1 = app.createComponent(\`Child\`, true, false, false, []);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
return comp1({}, key + \`__1\`, node, this, null);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`basics display a nice error if it cannot find component (in dev mode) 1`] = `
|
exports[`basics display a nice error if it cannot find component (in dev mode) 1`] = `
|
||||||
"function anonymous(app, bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -1,50 +1,5 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`t-call component with an enumerable getter, t-call inside slot 1`] = `
|
|
||||||
"function anonymous(app, bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
||||||
let { capture, markRaw } = helpers;
|
|
||||||
const callTemplate_1 = app.getTemplate(\`sub\`);
|
|
||||||
const comp1 = app.createComponent(\`Child\`, true, true, false, []);
|
|
||||||
|
|
||||||
function slot1(ctx, node, key = \\"\\") {
|
|
||||||
return callTemplate_1.call(this, ctx, node, key + \`__1\`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const ctx1 = capture(ctx);
|
|
||||||
return comp1({slots: markRaw({'default': {__render: slot1.bind(this), __ctx: ctx1}})}, key + \`__2\`, node, this, null);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-call component with an enumerable getter, t-call inside slot 2`] = `
|
|
||||||
"function anonymous(app, bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let txt1 = ctx['foo'];
|
|
||||||
return block1([txt1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-call component with an enumerable getter, t-call inside slot 3`] = `
|
|
||||||
"function anonymous(app, bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
||||||
let { callSlot } = helpers;
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return callSlot(ctx, node, key, 'default', false, {});
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-call dynamic t-call 1`] = `
|
exports[`t-call dynamic t-call 1`] = `
|
||||||
"function anonymous(app, bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -0,0 +1,493 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`list of components components in a node in a t-for 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { withKey } = helpers;
|
||||||
|
const comp1 = app.createComponent(\`Child\`, true, false, false, [\\"item\\"]);
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div><ul><block-child-0/></ul></div>\`);
|
||||||
|
let block3 = createBlock(\`<li><block-child-0/></li>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
const c_block2 = [];
|
||||||
|
let i1 = 0;
|
||||||
|
for (ctx['item'] of ctx['items']) {
|
||||||
|
const key1 = 'li_'+ctx['item'];
|
||||||
|
const b4 = comp1({item: ctx['item']}, key + \`__1__\${key1}\`, node, this, null);
|
||||||
|
c_block2[i1] = withKey(block3([], [b4]), key1);
|
||||||
|
i1++;
|
||||||
|
}
|
||||||
|
const b2 = list(c_block2);
|
||||||
|
return block1([], [b2]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`list of components components in a node in a t-for 2`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
let txt1 = ctx['props'].item;
|
||||||
|
return block1([txt1]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`list of components crash on duplicate key in dev mode 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { OwlError, withKey } = helpers;
|
||||||
|
const comp1 = app.createComponent(\`Child\`, true, false, false, []);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
const keys1 = new Set();
|
||||||
|
const c_block1 = [];
|
||||||
|
let i1 = 0;
|
||||||
|
for (ctx['item'] of [1,2]) {
|
||||||
|
const key1 = 'child';
|
||||||
|
if (keys1.has(String(key1))) { throw new OwlError(\`Got duplicate key in t-for: \${key1}\`)}
|
||||||
|
keys1.add(String(key1));
|
||||||
|
const props1 = {};
|
||||||
|
helpers.validateProps(\`Child\`, props1, this);
|
||||||
|
c_block1[i1] = withKey(comp1(props1, key + \`__1__\${key1}\`, node, this, null), key1);
|
||||||
|
i1++;
|
||||||
|
}
|
||||||
|
return list(c_block1);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`list of components crash on duplicate key in dev mode 2`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
return text(\`\`);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`list of components crash when using object as keys that serialize to the same string 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { OwlError, withKey } = helpers;
|
||||||
|
const comp1 = app.createComponent(\`Child\`, true, false, false, []);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
const keys1 = new Set();
|
||||||
|
const c_block1 = [];
|
||||||
|
let i1 = 0;
|
||||||
|
for (ctx['item'] of [{},{}]) {
|
||||||
|
const key1 = ctx['item'];
|
||||||
|
if (keys1.has(String(key1))) { throw new OwlError(\`Got duplicate key in t-for: \${key1}\`)}
|
||||||
|
keys1.add(String(key1));
|
||||||
|
const props1 = {};
|
||||||
|
helpers.validateProps(\`Child\`, props1, this);
|
||||||
|
c_block1[i1] = withKey(comp1(props1, key + \`__1__\${key1}\`, node, this, null), key1);
|
||||||
|
i1++;
|
||||||
|
}
|
||||||
|
return list(c_block1);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`list of components crash when using object as keys that serialize to the same string 2`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
return text(\`\`);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`list of components list of sub components inside other nodes 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { withKey } = helpers;
|
||||||
|
const comp1 = app.createComponent(\`SubComponent\`, true, false, false, []);
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
let block3 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
const c_block2 = [];
|
||||||
|
let i1 = 0;
|
||||||
|
for (ctx['blip'] of ctx['state'].blips) {
|
||||||
|
const key1 = ctx['blip'].id;
|
||||||
|
const b4 = comp1({}, key + \`__1__\${key1}\`, node, this, null);
|
||||||
|
c_block2[i1] = withKey(block3([], [b4]), key1);
|
||||||
|
i1++;
|
||||||
|
}
|
||||||
|
const b2 = list(c_block2);
|
||||||
|
return block1([], [b2]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`list of components list of sub components inside other nodes 2`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<span>asdf</span>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
return block1();
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`list of components order is correct when slots are not of same type 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { capture, markRaw } = helpers;
|
||||||
|
const comp1 = app.createComponent(\`Child\`, true, true, false, []);
|
||||||
|
|
||||||
|
let block2 = createBlock(\`<div>A</div>\`);
|
||||||
|
|
||||||
|
function slot1(ctx, node, key = \\"\\") {
|
||||||
|
let b2;
|
||||||
|
if (!ctx['state'].active) {
|
||||||
|
b2 = block2();
|
||||||
|
}
|
||||||
|
return multi([b2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function slot2(ctx, node, key = \\"\\") {
|
||||||
|
return text(\`B\`);
|
||||||
|
}
|
||||||
|
|
||||||
|
function slot3(ctx, node, key = \\"\\") {
|
||||||
|
return text(\`C\`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
const ctx1 = capture(ctx);
|
||||||
|
return comp1({slots: markRaw({'a': {__render: slot1.bind(this), __ctx: ctx1, active: !ctx['state'].active}, 'b': {__render: slot2.bind(this), __ctx: ctx1, active: true}, 'c': {__render: slot3.bind(this), __ctx: ctx1, active: ctx['state'].active}})}, key + \`__1\`, node, this, null);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`list of components order is correct when slots are not of same type 2`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { callSlot, withKey } = helpers;
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
const c_block1 = [];
|
||||||
|
let i1 = 0;
|
||||||
|
for (ctx['slotName'] of ctx['slotNames']) {
|
||||||
|
const key1 = ctx['slotName'];
|
||||||
|
const slot1 = (ctx['slotName']);
|
||||||
|
c_block1[i1] = withKey(toggler(slot1, callSlot(ctx, node, key1 + \`__1__\${key1}\`, slot1, true, {})), key1);
|
||||||
|
i1++;
|
||||||
|
}
|
||||||
|
return list(c_block1);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`list of components reconciliation alg works for t-for in t-for 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { withKey } = helpers;
|
||||||
|
const comp1 = app.createComponent(\`Child\`, true, false, false, [\\"blip\\"]);
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
const c_block2 = [];
|
||||||
|
let i1 = 0;
|
||||||
|
for (ctx['section'] of ctx['state'].s) {
|
||||||
|
const key1 = ctx['section'];
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
const c_block3 = [];
|
||||||
|
let i2 = 0;
|
||||||
|
for (ctx['blip'] of ctx['section'].blips) {
|
||||||
|
const key2 = ctx['blip'];
|
||||||
|
c_block3[i2] = withKey(comp1({blip: ctx['blip']}, key + \`__1__\${key1}__\${key2}\`, node, this, null), key2);
|
||||||
|
i2++;
|
||||||
|
}
|
||||||
|
ctx = ctx.__proto__;
|
||||||
|
c_block2[i1] = withKey(list(c_block3), key1);
|
||||||
|
i1++;
|
||||||
|
}
|
||||||
|
const b2 = list(c_block2);
|
||||||
|
return block1([], [b2]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`list of components reconciliation alg works for t-for in t-for 2`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
let txt1 = ctx['props'].blip;
|
||||||
|
return block1([txt1]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`list of components reconciliation alg works for t-for in t-for, 2 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { withKey } = helpers;
|
||||||
|
const comp1 = app.createComponent(\`Child\`, true, false, false, [\\"row\\",\\"col\\"]);
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
let block3 = createBlock(\`<p><block-child-0/></p>\`);
|
||||||
|
let block5 = createBlock(\`<p><block-child-0/></p>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
const c_block2 = [];
|
||||||
|
let i1 = 0;
|
||||||
|
for (ctx['row'] of ctx['state'].rows) {
|
||||||
|
const key1 = ctx['row'];
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
const c_block4 = [];
|
||||||
|
let i2 = 0;
|
||||||
|
for (ctx['col'] of ctx['state'].cols) {
|
||||||
|
const key2 = ctx['col'];
|
||||||
|
const b6 = comp1({row: ctx['row'],col: ctx['col']}, key + \`__1__\${key1}__\${key2}\`, node, this, null);
|
||||||
|
c_block4[i2] = withKey(block5([], [b6]), key2);
|
||||||
|
i2++;
|
||||||
|
}
|
||||||
|
ctx = ctx.__proto__;
|
||||||
|
const b4 = list(c_block4);
|
||||||
|
c_block2[i1] = withKey(block3([], [b4]), key1);
|
||||||
|
i1++;
|
||||||
|
}
|
||||||
|
const b2 = list(c_block2);
|
||||||
|
return block1([], [b2]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`list of components reconciliation alg works for t-for in t-for, 2 2`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
let txt1 = ctx['props'].row+'_'+ctx['props'].col;
|
||||||
|
return block1([txt1]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`list of components simple list 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { withKey } = helpers;
|
||||||
|
const comp1 = app.createComponent(\`Child\`, true, false, false, [\\"value\\"]);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
const c_block1 = [];
|
||||||
|
let i1 = 0;
|
||||||
|
for (ctx['elem'] of ctx['state'].elems) {
|
||||||
|
const key1 = ctx['elem'].id;
|
||||||
|
c_block1[i1] = withKey(comp1({value: ctx['elem'].value}, key + \`__1__\${key1}\`, node, this, null), key1);
|
||||||
|
i1++;
|
||||||
|
}
|
||||||
|
return list(c_block1);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`list of components simple list 2`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
let txt1 = ctx['props'].value;
|
||||||
|
return block1([txt1]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`list of components sub components rendered in a loop 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { withKey } = helpers;
|
||||||
|
const comp1 = app.createComponent(\`Child\`, true, false, false, [\\"n\\"]);
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
const c_block2 = [];
|
||||||
|
let i1 = 0;
|
||||||
|
for (ctx['number'] of ctx['state'].numbers) {
|
||||||
|
const key1 = ctx['number'];
|
||||||
|
c_block2[i1] = withKey(comp1({n: ctx['number']}, key + \`__1__\${key1}\`, node, this, null), key1);
|
||||||
|
i1++;
|
||||||
|
}
|
||||||
|
const b2 = list(c_block2);
|
||||||
|
return block1([], [b2]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`list of components sub components rendered in a loop 2`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<p><block-text-0/></p>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
let txt1 = ctx['props'].n;
|
||||||
|
return block1([txt1]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`list of components sub components with some state rendered in a loop 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { withKey } = helpers;
|
||||||
|
const comp1 = app.createComponent(\`Child\`, true, false, false, []);
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
const c_block2 = [];
|
||||||
|
let i1 = 0;
|
||||||
|
for (ctx['number'] of ctx['state'].numbers) {
|
||||||
|
const key1 = ctx['number'];
|
||||||
|
c_block2[i1] = withKey(comp1({}, key + \`__1__\${key1}\`, node, this, null), key1);
|
||||||
|
i1++;
|
||||||
|
}
|
||||||
|
const b2 = list(c_block2);
|
||||||
|
return block1([], [b2]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`list of components sub components with some state rendered in a loop 2`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<p><block-text-0/></p>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
let txt1 = ctx['state'].n;
|
||||||
|
return block1([txt1]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`list of components switch component position 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { withKey } = helpers;
|
||||||
|
const comp1 = app.createComponent(\`Child\`, true, false, false, [\\"key\\"]);
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
const c_block2 = [];
|
||||||
|
let i1 = 0;
|
||||||
|
for (ctx['c'] of ctx['clist']) {
|
||||||
|
const key1 = ctx['c'];
|
||||||
|
c_block2[i1] = withKey(comp1({key: ctx['c']}, key + \`__1__\${key1}\`, node, this, null), key1);
|
||||||
|
i1++;
|
||||||
|
}
|
||||||
|
const b2 = list(c_block2);
|
||||||
|
return block1([], [b2]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`list of components switch component position 2`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
let txt1 = ctx['props'].key;
|
||||||
|
return block1([txt1]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`list of components t-for with t-component, and update 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { withKey } = helpers;
|
||||||
|
const comp1 = app.createComponent(\`Child\`, true, false, false, [\\"val\\"]);
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
const c_block2 = [];
|
||||||
|
let i1 = 0;
|
||||||
|
for (ctx['n'] of [0,1]) {
|
||||||
|
const key1 = ctx['n'];
|
||||||
|
c_block2[i1] = withKey(comp1({val: ctx['n']}, key + \`__1__\${key1}\`, node, this, null), key1);
|
||||||
|
i1++;
|
||||||
|
}
|
||||||
|
const b2 = list(c_block2);
|
||||||
|
return block1([], [b2]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`list of components t-for with t-component, and update 2`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<span><block-text-0/><block-text-1/></span>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
let txt1 = ctx['state'].val;
|
||||||
|
let txt2 = ctx['props'].val;
|
||||||
|
return block1([txt1, txt2]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
@@ -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 };
|
||||||
|
|
||||||
|
|||||||
@@ -143,6 +143,66 @@ describe("basics", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("display a nice error if the root component template fails to compile", async () => {
|
||||||
|
// This is a special case: mount throws synchronously and we don't have any
|
||||||
|
// node which can handle the error, hence the different structure of this test
|
||||||
|
class Comp extends Component {
|
||||||
|
static template = xml`<div t-att-class="a b">test</div>`;
|
||||||
|
}
|
||||||
|
const app = new App(Comp);
|
||||||
|
let error: Error;
|
||||||
|
try {
|
||||||
|
await app.mount(fixture);
|
||||||
|
} catch (e) {
|
||||||
|
error = e as Error;
|
||||||
|
}
|
||||||
|
const expectedErrorMessage = `Failed to compile anonymous template: Unexpected identifier
|
||||||
|
|
||||||
|
generated code:
|
||||||
|
function(app, bdom, helpers) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div block-attribute-0="class">test</div>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = "") {
|
||||||
|
let attr1 = ctx['a']ctx['b'];
|
||||||
|
return block1([attr1]);
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
expect(error!).toBeDefined();
|
||||||
|
expect(error!.message).toBe(expectedErrorMessage);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("display a nice error if a non-root component template fails to compile", async () => {
|
||||||
|
class Child extends Component {
|
||||||
|
static template = xml`<div t-att-class="a b">test</div>`;
|
||||||
|
}
|
||||||
|
class Parent extends Component {
|
||||||
|
static components = { Child };
|
||||||
|
static template = xml`<Child/>`;
|
||||||
|
}
|
||||||
|
const expectedErrorMessage = `Failed to compile anonymous template: Unexpected identifier
|
||||||
|
|
||||||
|
generated code:
|
||||||
|
function(app, bdom, helpers) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div block-attribute-0="class">test</div>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = "") {
|
||||||
|
let attr1 = ctx['a']ctx['b'];
|
||||||
|
return block1([attr1]);
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
const app = new App(Parent as typeof Component);
|
||||||
|
let error: Error;
|
||||||
|
const mountProm = app.mount(fixture).catch((e: Error) => (error = e));
|
||||||
|
await expect(nextAppError(app)).resolves.toThrow(expectedErrorMessage);
|
||||||
|
await mountProm;
|
||||||
|
expect(error!).toBeDefined();
|
||||||
|
expect(error!.message).toBe(expectedErrorMessage);
|
||||||
|
});
|
||||||
|
|
||||||
test("simple catchError", async () => {
|
test("simple catchError", async () => {
|
||||||
class Boom extends Component {
|
class Boom extends Component {
|
||||||
static template = xml`<div t-esc="a.b.c"/>`;
|
static template = xml`<div t-esc="a.b.c"/>`;
|
||||||
@@ -1444,6 +1504,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 +1567,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");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -425,26 +425,4 @@ describe("t-call", () => {
|
|||||||
await nextTick();
|
await nextTick();
|
||||||
expect(fixture.innerHTML).toBe("Bchild");
|
expect(fixture.innerHTML).toBe("Bchild");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("component with an enumerable getter, t-call inside slot", async () => {
|
|
||||||
class Child extends Component {
|
|
||||||
static template = xml`<t t-slot="default"/>`;
|
|
||||||
}
|
|
||||||
class Parent extends Component {
|
|
||||||
static components = { Child };
|
|
||||||
static template = xml`<Child><t t-call="sub"/></Child>`;
|
|
||||||
}
|
|
||||||
// simulate adding a getter with patch in odoo: getter will be enumarable
|
|
||||||
Object.defineProperty(Parent.prototype, "foo", {
|
|
||||||
get() {
|
|
||||||
return 1;
|
|
||||||
},
|
|
||||||
enumerable: true,
|
|
||||||
});
|
|
||||||
const app = new App(Parent);
|
|
||||||
app.addTemplate("sub", `<div t-esc="foo"/>`);
|
|
||||||
|
|
||||||
await app.mount(fixture);
|
|
||||||
expect(fixture.innerHTML).toBe("<div>1</div>");
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,391 @@
|
|||||||
|
import { App, Component, mount, onMounted, useState, xml } from "../../src/index";
|
||||||
|
import {
|
||||||
|
makeTestFixture,
|
||||||
|
nextAppError,
|
||||||
|
nextTick,
|
||||||
|
snapshotEverything,
|
||||||
|
useLogLifecycle,
|
||||||
|
} from "../helpers";
|
||||||
|
|
||||||
|
snapshotEverything();
|
||||||
|
|
||||||
|
let originalconsoleWarn = console.warn;
|
||||||
|
let mockConsoleWarn: any;
|
||||||
|
|
||||||
|
let fixture: HTMLElement;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = makeTestFixture();
|
||||||
|
mockConsoleWarn = jest.fn(() => {});
|
||||||
|
console.warn = mockConsoleWarn;
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
console.warn = originalconsoleWarn;
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("list of components", () => {
|
||||||
|
test("simple list", async () => {
|
||||||
|
class Child extends Component {
|
||||||
|
static template = xml`<span><t t-esc="props.value"/></span>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
class Parent extends Component {
|
||||||
|
static template = xml`
|
||||||
|
<t t-for="elem" t-of="state.elems" t-key="elem.id">
|
||||||
|
<Child value="elem.value"/>
|
||||||
|
</t>`;
|
||||||
|
static components = { Child };
|
||||||
|
|
||||||
|
state = useState({
|
||||||
|
elems: [
|
||||||
|
{ id: 1, value: "a" },
|
||||||
|
{ id: 2, value: "b" },
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const parent = await mount(Parent, fixture);
|
||||||
|
expect(fixture.innerHTML).toBe("<span>a</span><span>b</span>");
|
||||||
|
parent.state.elems.push({ id: 4, value: "d" });
|
||||||
|
await nextTick();
|
||||||
|
expect(fixture.innerHTML).toBe("<span>a</span><span>b</span><span>d</span>");
|
||||||
|
|
||||||
|
parent.state.elems.pop();
|
||||||
|
|
||||||
|
await nextTick();
|
||||||
|
expect(fixture.innerHTML).toBe("<span>a</span><span>b</span>");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("components in a node in a t-for ", async () => {
|
||||||
|
class Child extends Component {
|
||||||
|
static template = xml`<div><t t-esc="props.item"/></div>`;
|
||||||
|
setup() {
|
||||||
|
useLogLifecycle();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Parent extends Component {
|
||||||
|
static template = xml`
|
||||||
|
<div>
|
||||||
|
<ul>
|
||||||
|
<t t-for="item" t-of="items" t-key="'li_'+item">
|
||||||
|
<li>
|
||||||
|
<Child item="item"/>
|
||||||
|
</li>
|
||||||
|
</t>
|
||||||
|
</ul>
|
||||||
|
</div>`;
|
||||||
|
static components = { Child };
|
||||||
|
|
||||||
|
setup() {
|
||||||
|
useLogLifecycle();
|
||||||
|
}
|
||||||
|
|
||||||
|
get items() {
|
||||||
|
return [1, 2];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await mount(Parent, fixture);
|
||||||
|
expect(fixture.innerHTML).toBe(
|
||||||
|
"<div><ul><li><div>1</div></li><li><div>2</div></li></ul></div>"
|
||||||
|
);
|
||||||
|
expect([
|
||||||
|
"Parent:setup",
|
||||||
|
"Parent:willStart",
|
||||||
|
"Parent:willRender",
|
||||||
|
"Child:setup",
|
||||||
|
"Child:willStart",
|
||||||
|
"Child:setup",
|
||||||
|
"Child:willStart",
|
||||||
|
"Parent:rendered",
|
||||||
|
"Child:willRender",
|
||||||
|
"Child:rendered",
|
||||||
|
"Child:willRender",
|
||||||
|
"Child:rendered",
|
||||||
|
"Child:mounted",
|
||||||
|
"Child:mounted",
|
||||||
|
"Parent:mounted",
|
||||||
|
]).toBeLogged();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("reconciliation alg works for t-for in t-for", async () => {
|
||||||
|
class Child extends Component {
|
||||||
|
static template = xml`<div><t t-esc="props.blip"/></div>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
class Parent extends Component {
|
||||||
|
static template = xml`
|
||||||
|
<div>
|
||||||
|
<t t-for="section" t-of="state.s" t-key="section">
|
||||||
|
<t t-for="blip" t-of="section.blips" t-key="blip">
|
||||||
|
<Child blip="blip"/>
|
||||||
|
</t>
|
||||||
|
</t>
|
||||||
|
</div>`;
|
||||||
|
static components = { Child };
|
||||||
|
state = { s: [{ blips: ["a1", "a2"] }, { blips: ["b1"] }] };
|
||||||
|
}
|
||||||
|
|
||||||
|
await mount(Parent, fixture);
|
||||||
|
expect(fixture.innerHTML).toBe("<div><div>a1</div><div>a2</div><div>b1</div></div>");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("reconciliation alg works for t-for in t-for, 2", async () => {
|
||||||
|
class Child extends Component {
|
||||||
|
static template = xml`<div><t t-esc="props.row + '_' + props.col"/></div>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
class Parent extends Component {
|
||||||
|
static template = xml`
|
||||||
|
<div>
|
||||||
|
<p t-for="row" t-of="state.rows" t-key="row">
|
||||||
|
<p t-for="col" t-of="state.cols" t-key="col">
|
||||||
|
<Child row="row" col="col"/>
|
||||||
|
</p>
|
||||||
|
</p>
|
||||||
|
</div>`;
|
||||||
|
static components = { Child };
|
||||||
|
state = useState({ rows: [1, 2], cols: ["a", "b"] });
|
||||||
|
}
|
||||||
|
|
||||||
|
const parent = await mount(Parent, fixture);
|
||||||
|
expect(fixture.innerHTML).toBe(
|
||||||
|
"<div><p><p><div>1_a</div></p><p><div>1_b</div></p></p><p><p><div>2_a</div></p><p><div>2_b</div></p></p></div>"
|
||||||
|
);
|
||||||
|
parent.state.rows = [2, 1];
|
||||||
|
await nextTick();
|
||||||
|
expect(fixture.innerHTML).toBe(
|
||||||
|
"<div><p><p><div>2_a</div></p><p><div>2_b</div></p></p><p><p><div>1_a</div></p><p><div>1_b</div></p></p></div>"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("sub components rendered in a loop", async () => {
|
||||||
|
class Child extends Component {
|
||||||
|
static template = xml`<p><t t-esc="props.n"/></p>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
class Parent extends Component {
|
||||||
|
static template = xml`
|
||||||
|
<div>
|
||||||
|
<t t-for="number" t-of="state.numbers" t-key="number" >
|
||||||
|
<Child n="number"/>
|
||||||
|
</t>
|
||||||
|
</div>`;
|
||||||
|
static components = { Child };
|
||||||
|
|
||||||
|
state = useState({ numbers: [1, 2, 3] });
|
||||||
|
}
|
||||||
|
await mount(Parent, fixture);
|
||||||
|
|
||||||
|
expect(fixture.innerHTML).toBe(`<div><p>1</p><p>2</p><p>3</p></div>`);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("sub components with some state rendered in a loop", async () => {
|
||||||
|
let n = 1;
|
||||||
|
|
||||||
|
class Child extends Component {
|
||||||
|
static template = xml`<p><t t-esc="state.n"/></p>`;
|
||||||
|
state: any;
|
||||||
|
setup() {
|
||||||
|
this.state = useState({ n });
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Parent extends Component {
|
||||||
|
static template = xml`
|
||||||
|
<div>
|
||||||
|
<t t-for="number" t-of="state.numbers" t-key="number">
|
||||||
|
<Child/>
|
||||||
|
</t>
|
||||||
|
</div>`;
|
||||||
|
static components = { Child };
|
||||||
|
|
||||||
|
state = useState({
|
||||||
|
numbers: [1, 2, 3],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const parent = await mount(Parent, fixture);
|
||||||
|
|
||||||
|
parent.state.numbers = [1, 3];
|
||||||
|
await nextTick();
|
||||||
|
expect(fixture.innerHTML).toBe(`<div><p>1</p><p>3</p></div>`);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("list of sub components inside other nodes", async () => {
|
||||||
|
// this confuses the patching algorithm...
|
||||||
|
class SubComponent extends Component {
|
||||||
|
static template = xml`<span>asdf</span>`;
|
||||||
|
}
|
||||||
|
class Parent extends Component {
|
||||||
|
static template = xml`
|
||||||
|
<div>
|
||||||
|
<div t-for="blip" t-of="state.blips" t-key="blip.id">
|
||||||
|
<SubComponent />
|
||||||
|
</div>
|
||||||
|
</div>`;
|
||||||
|
static components = { SubComponent };
|
||||||
|
state = useState({
|
||||||
|
blips: [
|
||||||
|
{ a: "a", id: 1 },
|
||||||
|
{ b: "b", id: 2 },
|
||||||
|
{ c: "c", id: 4 },
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const parent = await mount(Parent, fixture);
|
||||||
|
expect(fixture.innerHTML).toBe(
|
||||||
|
"<div><div><span>asdf</span></div><div><span>asdf</span></div><div><span>asdf</span></div></div>"
|
||||||
|
);
|
||||||
|
parent.state.blips.splice(0, 1);
|
||||||
|
await nextTick();
|
||||||
|
expect(fixture.innerHTML).toBe(
|
||||||
|
"<div><div><span>asdf</span></div><div><span>asdf</span></div></div>"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("t-for with t-component, and update", async () => {
|
||||||
|
class Child extends Component {
|
||||||
|
static template = xml`
|
||||||
|
<span>
|
||||||
|
<t t-esc="state.val"/>
|
||||||
|
<t t-esc="props.val"/>
|
||||||
|
</span>`;
|
||||||
|
state = useState({ val: "A" });
|
||||||
|
setup() {
|
||||||
|
onMounted(() => {
|
||||||
|
this.state.val = "B";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class Parent extends Component {
|
||||||
|
static components = { Child };
|
||||||
|
static template = xml`
|
||||||
|
<div>
|
||||||
|
<t t-for="n" t-of="[0, 1]" t-key="n">
|
||||||
|
<Child val="n"/>
|
||||||
|
</t>
|
||||||
|
</div>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
await mount(Parent, fixture);
|
||||||
|
expect(fixture.innerHTML).toBe("<div><span>A0</span><span>A1</span></div>");
|
||||||
|
|
||||||
|
await nextTick(); // wait for changes triggered in mounted to be applied
|
||||||
|
expect(fixture.innerHTML).toBe("<div><span>B0</span><span>B1</span></div>");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("switch component position", async () => {
|
||||||
|
const childInstances = [];
|
||||||
|
class Child extends Component {
|
||||||
|
static template = xml`<div t-esc="props.key"></div>`;
|
||||||
|
setup() {
|
||||||
|
childInstances.push(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Parent extends Component {
|
||||||
|
static components = { Child };
|
||||||
|
static template = xml`<span>
|
||||||
|
<t t-for="c" t-of="clist" t-key="c">
|
||||||
|
<Child key="c"/>
|
||||||
|
</t>
|
||||||
|
</span>`;
|
||||||
|
|
||||||
|
clist = [1, 2];
|
||||||
|
}
|
||||||
|
|
||||||
|
const parent = await mount(Parent, fixture);
|
||||||
|
expect(fixture.innerHTML).toBe("<span><div>1</div><div>2</div></span>");
|
||||||
|
parent.clist = [2, 1];
|
||||||
|
parent.render();
|
||||||
|
await nextTick();
|
||||||
|
expect(fixture.innerHTML).toBe("<span><div>2</div><div>1</div></span>");
|
||||||
|
expect(childInstances.length).toBe(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("crash on duplicate key in dev mode", async () => {
|
||||||
|
const consoleInfo = console.info;
|
||||||
|
console.info = jest.fn();
|
||||||
|
class Child extends Component {
|
||||||
|
static template = xml``;
|
||||||
|
}
|
||||||
|
|
||||||
|
class Parent extends Component {
|
||||||
|
static template = xml`
|
||||||
|
<t t-for="item" t-of="[1, 2]" t-key="'child'">
|
||||||
|
<Child/>
|
||||||
|
</t>
|
||||||
|
`;
|
||||||
|
static components = { Child };
|
||||||
|
}
|
||||||
|
|
||||||
|
const app = new App(Parent, { test: true });
|
||||||
|
const mountProm = expect(app.mount(fixture)).rejects.toThrow(
|
||||||
|
"Got duplicate key in t-for: child"
|
||||||
|
);
|
||||||
|
await expect(nextAppError(app)).resolves.toThrow("Got duplicate key in t-for: child");
|
||||||
|
await mountProm;
|
||||||
|
console.info = consoleInfo;
|
||||||
|
expect(mockConsoleWarn).toBeCalledTimes(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("crash when using object as keys that serialize to the same string", async () => {
|
||||||
|
const consoleInfo = console.info;
|
||||||
|
console.info = jest.fn();
|
||||||
|
class Child extends Component {
|
||||||
|
static template = xml``;
|
||||||
|
}
|
||||||
|
|
||||||
|
class Parent extends Component {
|
||||||
|
static template = xml`
|
||||||
|
<t t-for="item" t-of="[{}, {}]" t-key="item">
|
||||||
|
<Child/>
|
||||||
|
</t>
|
||||||
|
`;
|
||||||
|
static components = { Child };
|
||||||
|
}
|
||||||
|
|
||||||
|
const app = new App(Parent, { test: true });
|
||||||
|
const mountProm = expect(app.mount(fixture)).rejects.toThrow(
|
||||||
|
"Got duplicate key in t-for: [object Object]"
|
||||||
|
);
|
||||||
|
await expect(nextAppError(app)).resolves.toThrow("Got duplicate key in t-for: [object Object]");
|
||||||
|
await mountProm;
|
||||||
|
console.info = consoleInfo;
|
||||||
|
expect(mockConsoleWarn).toBeCalledTimes(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("order is correct when slots are not of same type", async () => {
|
||||||
|
class Child extends Component {
|
||||||
|
static template = xml`
|
||||||
|
<t t-slot="{{ slotName }}" t-for="slotName" t-of="slotNames" t-key="slotName"/>
|
||||||
|
`;
|
||||||
|
get slotNames() {
|
||||||
|
return Object.entries(this.props.slots)
|
||||||
|
.filter((entry: any) => entry[1].active)
|
||||||
|
.map((entry) => entry[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Parent extends Component {
|
||||||
|
static template = xml`
|
||||||
|
<Child>
|
||||||
|
<t t-set-slot="a" active="!state.active"><div t-if="!state.active">A</div></t>
|
||||||
|
<t t-set-slot="b" active="true">B</t>
|
||||||
|
<t t-set-slot="c" active="state.active">C</t>
|
||||||
|
</Child>
|
||||||
|
`;
|
||||||
|
static components = { Child };
|
||||||
|
state = useState({ active: false });
|
||||||
|
}
|
||||||
|
|
||||||
|
const parent = await mount(Parent, fixture);
|
||||||
|
expect(fixture.textContent).toBe("AB");
|
||||||
|
parent.state.active = true;
|
||||||
|
await nextTick();
|
||||||
|
expect(fixture.textContent).toBe("BC");
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -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 {
|
||||||
|
|||||||
@@ -988,7 +988,7 @@ describe("Portal: Props validation", () => {
|
|||||||
error = e as Error;
|
error = e as Error;
|
||||||
}
|
}
|
||||||
expect(error!).toBeDefined();
|
expect(error!).toBeDefined();
|
||||||
expect(error!.message).toBe(`Unexpected token ','`);
|
expect(error!.message).toContain(`Unexpected token ','`);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("target must be a valid selector", async () => {
|
test("target must be a valid selector", async () => {
|
||||||
|
|||||||
+1
-2
@@ -1,11 +1,10 @@
|
|||||||
const { Component, useRef, useEffect } = owl;
|
const { Component, useRef, useEffect } = owl;
|
||||||
import { useStore } from "../../../store/store";
|
import { useStore } from "../../../store/store";
|
||||||
import { ObjectTreeElement } from "./object_tree_element/object_tree_element";
|
import { ObjectTreeElement } from "./object_tree_element/object_tree_element";
|
||||||
import { Subscriptions } from "./subscriptions/subscriptions";
|
|
||||||
|
|
||||||
export class DetailsWindow extends Component {
|
export class DetailsWindow extends Component {
|
||||||
static template = "devtools.DetailsWindow";
|
static template = "devtools.DetailsWindow";
|
||||||
static components = { ObjectTreeElement, Subscriptions };
|
static components = { ObjectTreeElement };
|
||||||
setup() {
|
setup() {
|
||||||
this.store = useStore();
|
this.store = useStore();
|
||||||
this.contextMenu = useRef("contextmenu");
|
this.contextMenu = useRef("contextmenu");
|
||||||
|
|||||||
+5
-1
@@ -53,7 +53,11 @@
|
|||||||
</div>
|
</div>
|
||||||
<i title="Store observed states as global variable in the console" class="fa fa-bug utility-icon p-1" t-on-click.stop="() => this.store.logObjectInConsole([...this.store.activeComponent.path, {type: 'item', value: 'subscriptions'}])"></i>
|
<i title="Store observed states as global variable in the console" class="fa fa-bug utility-icon p-1" t-on-click.stop="() => this.store.logObjectInConsole([...this.store.activeComponent.path, {type: 'item', value: 'subscriptions'}])"></i>
|
||||||
</div>
|
</div>
|
||||||
<Subscriptions t-if="store.activeComponent.subscriptions.toggled"/>
|
<div t-if="store.activeComponent.subscriptions.toggled" id="subscriptionsPanel">
|
||||||
|
<t t-foreach="store.activeComponent.subscriptions.children" t-as="subscription" t-key="subscription_index">
|
||||||
|
<ObjectTreeElement object="subscription.target"/>
|
||||||
|
</t>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div t-if="store.activeComponent.instance.children.length > 0" id="instance" class="details-panel ps-2 py-1">
|
<div t-if="store.activeComponent.instance.children.length > 0" id="instance" class="details-panel ps-2 py-1">
|
||||||
<div class="d-flex mb-2">
|
<div class="d-flex mb-2">
|
||||||
|
|||||||
+9
-10
@@ -41,23 +41,22 @@ export class ObjectTreeElement extends Component {
|
|||||||
return JSON.stringify(this.props.object.path);
|
return JSON.stringify(this.props.object.path);
|
||||||
}
|
}
|
||||||
|
|
||||||
get objectName() {
|
get keyChanges() {
|
||||||
return this.props.object.name;
|
return this.props.object.keys?.includes("Symbol(Key changes)");
|
||||||
}
|
}
|
||||||
|
|
||||||
get objectLineClass() {
|
classFor(object) {
|
||||||
// Prototype items will be dyed down to appear less important
|
// Prototype items will be dyed down to appear less important
|
||||||
if (this.pathAsString.includes('{"type":"prototype",')) {
|
if (object.path.some((item) => item?.type === "prototype") && !object.keepLit) {
|
||||||
return { attenuate: true };
|
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
|
||||||
if (this.props.object.objectType === "subscription" && this.props.object.depth > 0) {
|
if (object.objectType === "subscription" && object.depth > 0) {
|
||||||
if (this.props.keys.includes(this.props.object.name.toString())) {
|
if (this.props.object.keys?.includes(object.name.toString())) {
|
||||||
return { "fw-bolder": true };
|
return "fw-bolder";
|
||||||
}
|
}
|
||||||
return { attenuate: true };
|
return "attenuate";
|
||||||
}
|
}
|
||||||
return {};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get objectPadding() {
|
get objectPadding() {
|
||||||
|
|||||||
+4
-4
@@ -2,7 +2,7 @@
|
|||||||
<templates xml:space="preserve">
|
<templates xml:space="preserve">
|
||||||
<t t-name="devtools.ObjectTreeElement" owl="1">
|
<t t-name="devtools.ObjectTreeElement" owl="1">
|
||||||
<div class="m-0 p-0 text-nowrap w-100 object-line"
|
<div class="m-0 p-0 text-nowrap w-100 object-line"
|
||||||
t-att-class="objectLineClass"
|
t-att-class="props.class"
|
||||||
t-on-click.stop="() => this.store.toggleObjectTreeElementsDisplay(this.props.object)"
|
t-on-click.stop="() => this.store.toggleObjectTreeElementsDisplay(this.props.object)"
|
||||||
t-on-contextmenu.prevent="openMenu"
|
t-on-contextmenu.prevent="openMenu"
|
||||||
>
|
>
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
t-att-class="{'fa-caret-right': !props.object.toggled, 'fa-caret-down': props.object.toggled}"
|
t-att-class="{'fa-caret-right': !props.object.toggled, 'fa-caret-down': props.object.toggled}"
|
||||||
t-attf-style="visibility: {{props.object.hasChildren ? '' : 'hidden'}};"
|
t-attf-style="visibility: {{props.object.hasChildren ? '' : 'hidden'}};"
|
||||||
/>
|
/>
|
||||||
<t t-esc="objectName"/>
|
<t t-esc="props.object.name"/>
|
||||||
<t t-if="props.object.content.length > 0">: </t>
|
<t t-if="props.object.content.length > 0">: </t>
|
||||||
<t t-if="props.object.contentType == 'getter'">
|
<t t-if="props.object.contentType == 'getter'">
|
||||||
<span class="getter-content object-content" t-att-class="objectLineClass" t-on-click.stop="() => this.store.loadGetterContent(this.props.object)">
|
<span class="getter-content object-content" t-att-class="objectLineClass" t-on-click.stop="() => this.store.loadGetterContent(this.props.object)">
|
||||||
@@ -28,6 +28,7 @@
|
|||||||
</t>
|
</t>
|
||||||
</span>
|
</span>
|
||||||
</t>
|
</t>
|
||||||
|
<span t-if="keyChanges" class="key-changes ms-1 badge p-1" title="Key additions/deletions are observed">+/-</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div t-if="store.contextMenu.activeMenu === contextMenuId" class="custom-menu" t-ref="contextmenu">
|
<div t-if="store.contextMenu.activeMenu === contextMenuId" class="custom-menu" t-ref="contextmenu">
|
||||||
@@ -40,8 +41,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<t t-if="props.object.toggled" t-key="contextMenuId">
|
<t t-if="props.object.toggled" t-key="contextMenuId">
|
||||||
<t t-foreach="props.object.children" t-as="child" t-key="child_index">
|
<t t-foreach="props.object.children" t-as="child" t-key="child_index">
|
||||||
<ObjectTreeElement t-if="props.object.objectType === 'subscription'" object="child" keys="props.keys"/>
|
<ObjectTreeElement object="child" class="this.classFor(child)"/>
|
||||||
<ObjectTreeElement t-else="" object="child"/>
|
|
||||||
</t>
|
</t>
|
||||||
</t>
|
</t>
|
||||||
</t>
|
</t>
|
||||||
|
|||||||
-30
@@ -1,30 +0,0 @@
|
|||||||
const { Component } = owl;
|
|
||||||
import { useStore } from "../../../../store/store";
|
|
||||||
import { ObjectTreeElement } from "../object_tree_element/object_tree_element";
|
|
||||||
|
|
||||||
export class Subscriptions extends Component {
|
|
||||||
static template = "devtools.Subscriptions";
|
|
||||||
|
|
||||||
static components = { ObjectTreeElement };
|
|
||||||
|
|
||||||
setup() {
|
|
||||||
this.store = useStore();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Used to display the keys in a compact way
|
|
||||||
keysContent(index) {
|
|
||||||
const keys = this.store.activeComponent.subscriptions.children[index].keys;
|
|
||||||
let content = JSON.stringify(keys);
|
|
||||||
const maxLength = 50;
|
|
||||||
content = content.replace(/,/g, ", ");
|
|
||||||
if (content.length > maxLength) {
|
|
||||||
content = content.slice(0, content.lastIndexOf(",", maxLength - 5)) + ", ...]";
|
|
||||||
}
|
|
||||||
return content;
|
|
||||||
}
|
|
||||||
|
|
||||||
expandKeys(event, index) {
|
|
||||||
this.store.activeComponent.subscriptions.children[index].keysExpanded =
|
|
||||||
!this.store.activeComponent.subscriptions.children[index].keysExpanded;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-24
@@ -1,24 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
|
||||||
<templates xml:space="preserve">
|
|
||||||
<t t-name="devtools.Subscriptions" owl="1">
|
|
||||||
<div id="subscriptionsPanel">
|
|
||||||
<t t-foreach="store.activeComponent.subscriptions.children" t-as="subscription" t-key="subscription_index">
|
|
||||||
<div class="my-2">
|
|
||||||
<div class="my-0 p-0 object-line" t-on-click.stop="(ev) => this.expandKeys(ev, subscription_index)">
|
|
||||||
<span class="ps-1 text-nowrap">
|
|
||||||
<i class="fa fa-caret-right ms-1" t-attf-style="cursor: pointer;{{subscription.keysExpanded ? 'transform: rotate(90deg);' : ''}}"></i>
|
|
||||||
keys: <span class="key-name"><t t-esc="this.keysContent(subscription_index)"/></span>
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div t-foreach="subscription.keys" t-as="key" t-key="key_index" class="my-0 p-0 object-line" t-attf-style="display: {{subscription.keysExpanded ? 'flex' : 'none'}}">
|
|
||||||
<div style="transform: translateX(calc(1.1rem))" class="key-content">
|
|
||||||
<i class="fa fa-caret-right mx-1" t-attf-style="cursor: pointer; visibility: hidden;"></i>
|
|
||||||
<t t-esc="key"/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<ObjectTreeElement object="subscription.target" keys="subscription.keys"/>
|
|
||||||
</div>
|
|
||||||
</t>
|
|
||||||
</div>
|
|
||||||
</t>
|
|
||||||
</templates>
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<templates xml:space="preserve">
|
<templates xml:space="preserve">
|
||||||
<t t-name="devtools.Event" owl="1">
|
<t t-name="devtools.Event" owl="1">
|
||||||
<div class="event-container">
|
<div class="event-container" t-att-class="{ 'event-last': props.event.isLast }">
|
||||||
<div class="my-0 p-0 object-line" t-on-click.stop="toggleDisplay">
|
<div class="my-0 p-0 object-line" t-on-click.stop="toggleDisplay">
|
||||||
<div class="ps-2 text-nowrap">
|
<div class="ps-2 text-nowrap">
|
||||||
<i class="fa px-1 pointer-icon caret"
|
<i class="fa px-1 pointer-icon caret"
|
||||||
|
|||||||
@@ -102,21 +102,19 @@ 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 = await evalFunctionInWindow(
|
const [apps, details] = await evalFunctionInWindow(
|
||||||
"getComponentsTree",
|
"getComponentsTree",
|
||||||
fromOld && this.activeComponent ? [this.activeComponent.path, this.apps] : [],
|
fromOld && this.activeComponent
|
||||||
|
? [this.activeComponent.path, this.apps, this.activeComponent]
|
||||||
|
: [],
|
||||||
this.activeFrame
|
this.activeFrame
|
||||||
);
|
);
|
||||||
this.apps = apps ? apps : [];
|
this.apps = apps ? apps : [];
|
||||||
if (!fromOld && this.settings.expandByDefault) {
|
if (!fromOld && this.settings.expandByDefault) {
|
||||||
this.apps.forEach((tree) => expandNodes(tree, true));
|
this.apps.forEach((tree) => expandNodes(tree, true));
|
||||||
}
|
}
|
||||||
const component = await evalFunctionInWindow(
|
keepEnvLit(details);
|
||||||
"getComponentDetails",
|
this.activeComponent = details;
|
||||||
fromOld && this.activeComponent ? [this.activeComponent.path, this.activeComponent] : [],
|
|
||||||
this.activeFrame
|
|
||||||
);
|
|
||||||
this.activeComponent = component;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// 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
|
||||||
@@ -153,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");
|
||||||
@@ -413,12 +413,7 @@ export const store = reactive({
|
|||||||
if (!scriptsLoaded) {
|
if (!scriptsLoaded) {
|
||||||
await loadScripts(frame);
|
await loadScripts(frame);
|
||||||
}
|
}
|
||||||
evalInWindow(
|
evalFunctionInWindow("initDevtools", [frame], frame);
|
||||||
`__OWL__DEVTOOLS_GLOBAL_HOOK__.devtoolsId = ${
|
|
||||||
store.devtoolsId
|
|
||||||
}; __OWL__DEVTOOLS_GLOBAL_HOOK__.frame = ${JSON.stringify(frame)};`,
|
|
||||||
frame
|
|
||||||
);
|
|
||||||
if (!this.frameUrls.includes(frame)) {
|
if (!this.frameUrls.includes(frame)) {
|
||||||
this.frameUrls = [...this.frameUrls, frame];
|
this.frameUrls = [...this.frameUrls, frame];
|
||||||
}
|
}
|
||||||
@@ -638,7 +633,7 @@ init();
|
|||||||
async function init() {
|
async function init() {
|
||||||
store.devtoolsId = await getTabURL();
|
store.devtoolsId = await getTabURL();
|
||||||
|
|
||||||
evalInWindow("__OWL__DEVTOOLS_GLOBAL_HOOK__.devtoolsId = " + store.devtoolsId + ";");
|
evalFunctionInWindow("initDevtools", []);
|
||||||
|
|
||||||
await loadSettings();
|
await loadSettings();
|
||||||
|
|
||||||
@@ -671,7 +666,7 @@ async function init() {
|
|||||||
}, 500);
|
}, 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
let flushRendersTimeout = false;
|
let rootRendersTimeout = false;
|
||||||
// Connect to the port to communicate to the background script
|
// Connect to the port to communicate to the background script
|
||||||
browserInstance.runtime.onConnect.addListener((port) => {
|
browserInstance.runtime.onConnect.addListener((port) => {
|
||||||
if (port.name === "OwlDevtoolsPort_" + store.devtoolsId) {
|
if (port.name === "OwlDevtoolsPort_" + store.devtoolsId) {
|
||||||
@@ -680,7 +675,7 @@ browserInstance.runtime.onConnect.addListener((port) => {
|
|||||||
if (msg.type === "Reload") {
|
if (msg.type === "Reload") {
|
||||||
store.owlStatus = await evalInWindow("window.__OWL__DEVTOOLS_GLOBAL_HOOK__ !== undefined;");
|
store.owlStatus = await evalInWindow("window.__OWL__DEVTOOLS_GLOBAL_HOOK__ !== undefined;");
|
||||||
if (store.owlStatus) {
|
if (store.owlStatus) {
|
||||||
evalInWindow("__OWL__DEVTOOLS_GLOBAL_HOOK__.devtoolsId = " + store.devtoolsId + ";");
|
evalFunctionInWindow("initDevtools", []);
|
||||||
await store.resetData();
|
await store.resetData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -694,9 +689,9 @@ browserInstance.runtime.onConnect.addListener((port) => {
|
|||||||
if (msg.type === "RefreshApps") {
|
if (msg.type === "RefreshApps") {
|
||||||
store.loadComponentsTree(true);
|
store.loadComponentsTree(true);
|
||||||
}
|
}
|
||||||
// When message of type Flush is received, overwrite the component tree with the new one from page
|
// When message of type Complete is received, overwrite the component tree with the new one from page
|
||||||
// A flush message is sent everytime a component is rendered on the page
|
// A Complete message is sent everytime a root render is triggered on the page
|
||||||
if (msg.type === "Flush") {
|
if (msg.type === "Complete") {
|
||||||
if (msg.origin.frame !== store.activeFrame) {
|
if (msg.origin.frame !== store.activeFrame) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -705,8 +700,8 @@ browserInstance.runtime.onConnect.addListener((port) => {
|
|||||||
}
|
}
|
||||||
// This determines which components will have a short highlight effect in the tree to indicate they have been rendered
|
// This determines which components will have a short highlight effect in the tree to indicate they have been rendered
|
||||||
store.renderPaths.add(JSON.stringify(msg.data));
|
store.renderPaths.add(JSON.stringify(msg.data));
|
||||||
clearTimeout(flushRendersTimeout);
|
clearTimeout(rootRendersTimeout);
|
||||||
flushRendersTimeout = setTimeout(() => {
|
rootRendersTimeout = setTimeout(() => {
|
||||||
store.renderPaths.clear();
|
store.renderPaths.clear();
|
||||||
}, 100);
|
}, 100);
|
||||||
store.loadComponentsTree(true);
|
store.loadComponentsTree(true);
|
||||||
@@ -787,6 +782,7 @@ function loadEvents(events) {
|
|||||||
}
|
}
|
||||||
event.origin = null;
|
event.origin = null;
|
||||||
event.toggled = false;
|
event.toggled = false;
|
||||||
|
event.isLast = false;
|
||||||
// Logic to retrace the origin of the event if it is not a root render event
|
// Logic to retrace the origin of the event if it is not a root render event
|
||||||
if (!event.type.includes("render")) {
|
if (!event.type.includes("render")) {
|
||||||
for (let i = store.events.length - 1; i >= 0; i--) {
|
for (let i = store.events.length - 1; i >= 0; i--) {
|
||||||
@@ -836,6 +832,7 @@ function loadEvents(events) {
|
|||||||
// Make sure we add the event while keeping the whole list ordered by id
|
// Make sure we add the event while keeping the whole list ordered by id
|
||||||
addEventSorted(event);
|
addEventSorted(event);
|
||||||
}
|
}
|
||||||
|
store.events[store.events.length - 1].isLast = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deselect component and remove highlight on all children
|
// Deselect component and remove highlight on all children
|
||||||
@@ -893,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;
|
||||||
|
|||||||
@@ -126,6 +126,10 @@
|
|||||||
color: var(--prototype-color);
|
color: var(--prototype-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.key-changes {
|
||||||
|
background-color: var(--version-bg);
|
||||||
|
}
|
||||||
|
|
||||||
.event-container {
|
.event-container {
|
||||||
border-bottom: 1px solid rgb(240, 238, 238);
|
border-bottom: 1px solid rgb(240, 238, 238);
|
||||||
padding-top: 2px!important;
|
padding-top: 2px!important;
|
||||||
@@ -133,6 +137,10 @@
|
|||||||
font-size: 11px;
|
font-size: 11px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.event-last {
|
||||||
|
border-bottom: 3px solid rgb(225, 154, 0);
|
||||||
|
}
|
||||||
|
|
||||||
.getter-content:hover {
|
.getter-content:hover {
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,8 +15,6 @@
|
|||||||
// in __OWL_DEVTOOLS__
|
// in __OWL_DEVTOOLS__
|
||||||
this.toRaw = window.__OWL_DEVTOOLS__.toRaw ?? window.owl?.toRaw;
|
this.toRaw = window.__OWL_DEVTOOLS__.toRaw ?? window.owl?.toRaw;
|
||||||
this.reactive = window.__OWL_DEVTOOLS__.reactive ?? window.owl?.reactive;
|
this.reactive = window.__OWL_DEVTOOLS__.reactive ?? window.owl?.reactive;
|
||||||
// Set to keep track of the fibers that are in the flush queue
|
|
||||||
this.queuedFibers = new WeakSet();
|
|
||||||
// Set to keep track of the HTML elements we added to the page
|
// Set to keep track of the HTML elements we added to the page
|
||||||
this.addedElements = [];
|
this.addedElements = [];
|
||||||
// To keep track of the succession order of the render events
|
// To keep track of the succession order of the render events
|
||||||
@@ -24,7 +22,6 @@
|
|||||||
// Set to keep track of the frame on which this script is loaded
|
// Set to keep track of the frame on which this script is loaded
|
||||||
this.frame = "top";
|
this.frame = "top";
|
||||||
// Allows to launch a message each time an iframe html element is added to the page
|
// Allows to launch a message each time an iframe html element is added to the page
|
||||||
const self = this;
|
|
||||||
const iFrameObserver = new MutationObserver(function (mutationsList) {
|
const iFrameObserver = new MutationObserver(function (mutationsList) {
|
||||||
mutationsList.forEach(function (mutation) {
|
mutationsList.forEach(function (mutation) {
|
||||||
mutation.addedNodes.forEach(function (addedNode) {
|
mutation.addedNodes.forEach(function (addedNode) {
|
||||||
@@ -47,12 +44,7 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
iFrameObserver.observe(document.body, { subtree: true, childList: true });
|
iFrameObserver.observe(document.body, { subtree: true, childList: true });
|
||||||
this.appsPatched = false;
|
|
||||||
this.destroyPatched = false;
|
|
||||||
this.patchAppsSetMethods();
|
this.patchAppsSetMethods();
|
||||||
if (this.apps.size > 0) {
|
|
||||||
this.patchAppMethods();
|
|
||||||
}
|
|
||||||
this.recordEvents = false;
|
this.recordEvents = false;
|
||||||
this.traceRenderings = false;
|
this.traceRenderings = false;
|
||||||
this.traceSubscriptions = false;
|
this.traceSubscriptions = false;
|
||||||
@@ -125,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) {
|
||||||
@@ -172,34 +173,40 @@
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
initDevtools(frame = "top") {
|
||||||
|
if (!this.devtoolsInit) {
|
||||||
|
this.frame = frame;
|
||||||
|
const self = this;
|
||||||
|
// Flush the events batcher when a root render is completed
|
||||||
|
const original_Complete = self.RootFiber.prototype.complete;
|
||||||
|
self.RootFiber.prototype.complete = function () {
|
||||||
|
original_Complete.call(this, ...arguments);
|
||||||
|
const path = self.getComponentPath(this.node);
|
||||||
|
//Add a functionnality to the complete function which sends a message to the window every time it is triggered.
|
||||||
|
window.top.postMessage({
|
||||||
|
source: "owl-devtools",
|
||||||
|
type: "Complete",
|
||||||
|
data: path,
|
||||||
|
origin: { frame: self.frame },
|
||||||
|
});
|
||||||
|
if (self.recordEvents) {
|
||||||
|
window.top.postMessage({
|
||||||
|
source: "owl-devtools",
|
||||||
|
type: "Event",
|
||||||
|
data: self.eventsBatch,
|
||||||
|
});
|
||||||
|
self.eventsBatch = [];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this.devtoolsInit = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
// Modify the methods of the apps set in order to send a message each time it is modified.
|
// Modify the methods of the apps set in order to send a message each time it is modified.
|
||||||
patchAppsSetMethods() {
|
patchAppsSetMethods() {
|
||||||
const originalAdd = this.apps.add;
|
const originalAdd = this.apps.add;
|
||||||
const originalDelete = this.apps.delete;
|
const originalDelete = this.apps.delete;
|
||||||
const self = this;
|
|
||||||
this.apps.add = function () {
|
this.apps.add = function () {
|
||||||
originalAdd.call(this, ...arguments);
|
originalAdd.call(this, ...arguments);
|
||||||
if (!self.destroyPatched) {
|
|
||||||
const newApp = arguments[0];
|
|
||||||
// It is not a given that apps have a root node at creation so we need to wait
|
|
||||||
if (newApp.root) {
|
|
||||||
self.patchDestroyMethod(newApp.root);
|
|
||||||
} else {
|
|
||||||
let root = null;
|
|
||||||
Object.defineProperty(newApp, "root", {
|
|
||||||
get() {
|
|
||||||
return root;
|
|
||||||
},
|
|
||||||
set(value) {
|
|
||||||
root = value;
|
|
||||||
if (!self.destroyPatched) {
|
|
||||||
self.patchDestroyMethod(root);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
self.patchAppMethods();
|
|
||||||
window.top.postMessage({
|
window.top.postMessage({
|
||||||
source: "owl-devtools",
|
source: "owl-devtools",
|
||||||
type: "RefreshApps",
|
type: "RefreshApps",
|
||||||
@@ -214,72 +221,24 @@
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
patchDestroyMethod(root) {
|
|
||||||
if (!this.destroyPatched) {
|
|
||||||
// Signals when a component is destroyed
|
|
||||||
const originalDestroy = root.constructor.prototype._destroy;
|
|
||||||
const self = this;
|
|
||||||
root.constructor.prototype._destroy = function () {
|
|
||||||
if (self.recordEvents) {
|
|
||||||
const path = self.getComponentPath(this);
|
|
||||||
const event = {
|
|
||||||
type: "destroy",
|
|
||||||
component: this.name,
|
|
||||||
key: this.parentKey,
|
|
||||||
path: path,
|
|
||||||
time: 0,
|
|
||||||
id: self.eventId++,
|
|
||||||
};
|
|
||||||
self.eventsBatch.push(event);
|
|
||||||
const before = performance.now();
|
|
||||||
originalDestroy.call(this, ...arguments);
|
|
||||||
event.time = performance.now() - before;
|
|
||||||
} else {
|
|
||||||
originalDestroy.call(this, ...arguments);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
this.destroyPatched = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Modify methods of each app so that it triggers messages on each flush and component render
|
// Modify methods of each app so that it triggers messages on each flush and component render
|
||||||
patchAppMethods() {
|
patchAppMethods() {
|
||||||
if (this.appsPatched) {
|
let app;
|
||||||
|
for (const appItem of this.apps) {
|
||||||
|
if (appItem.root) {
|
||||||
|
app = appItem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!app.root) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let app = this.apps.values().next().value;
|
|
||||||
const self = this;
|
const self = this;
|
||||||
if (app.root) {
|
|
||||||
this.patchDestroyMethod(app.root);
|
|
||||||
} else {
|
|
||||||
const originalMount = app.constructor.prototype.mount;
|
|
||||||
app.constructor.prototype.mount = async function (...args) {
|
|
||||||
const result = await originalMount.call(this, ...args);
|
|
||||||
const root = this.root;
|
|
||||||
self.patchDestroyMethod(root);
|
|
||||||
app.constructor.prototype.mount = originalMount;
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
const originalFlush = app.scheduler.constructor.prototype.flush;
|
const originalFlush = app.scheduler.constructor.prototype.flush;
|
||||||
let inFlush = false;
|
let inFlush = false;
|
||||||
let _render = false;
|
let _render = false;
|
||||||
app.scheduler.constructor.prototype.flush = function () {
|
app.scheduler.constructor.prototype.flush = function () {
|
||||||
// Used to know when a render is triggered inside the flush method or not
|
// Used to know when a render is triggered inside the flush method or not
|
||||||
inFlush = true;
|
inFlush = true;
|
||||||
[...this.tasks].map((fiber) => {
|
|
||||||
if (fiber.counter === 0 && !self.queuedFibers.has(fiber)) {
|
|
||||||
self.queuedFibers.add(fiber);
|
|
||||||
const path = self.getComponentPath(fiber.node);
|
|
||||||
//Add a functionnality to the flush function which sends a message to the window every time it is triggered.
|
|
||||||
window.top.postMessage({
|
|
||||||
source: "owl-devtools",
|
|
||||||
type: "Flush",
|
|
||||||
data: path,
|
|
||||||
origin: { frame: self.frame },
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
originalFlush.call(this, ...arguments);
|
originalFlush.call(this, ...arguments);
|
||||||
inFlush = false;
|
inFlush = false;
|
||||||
};
|
};
|
||||||
@@ -376,20 +335,27 @@
|
|||||||
_render = true;
|
_render = true;
|
||||||
original_Render.call(this, ...arguments);
|
original_Render.call(this, ...arguments);
|
||||||
};
|
};
|
||||||
// Flush the events batcher when a root render is completed
|
// Signals when a component is destroyed
|
||||||
const original_Complete = self.RootFiber.prototype.complete;
|
const originalDestroy = app.root.constructor.prototype._destroy;
|
||||||
self.RootFiber.prototype.complete = function () {
|
app.root.constructor.prototype._destroy = function () {
|
||||||
original_Complete.call(this, ...arguments);
|
|
||||||
if (self.recordEvents) {
|
if (self.recordEvents) {
|
||||||
window.top.postMessage({
|
const path = self.getComponentPath(this);
|
||||||
source: "owl-devtools",
|
const event = {
|
||||||
type: "Event",
|
type: "destroy",
|
||||||
data: self.eventsBatch,
|
component: this.name,
|
||||||
});
|
key: this.parentKey,
|
||||||
self.eventsBatch = [];
|
path: path,
|
||||||
|
time: 0,
|
||||||
|
id: self.eventId++,
|
||||||
|
};
|
||||||
|
self.eventsBatch.push(event);
|
||||||
|
const before = performance.now();
|
||||||
|
originalDestroy.call(this, ...arguments);
|
||||||
|
event.time = performance.now() - before;
|
||||||
|
} else {
|
||||||
|
originalDestroy.call(this, ...arguments);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
this.appsPatched = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// patch reactivity system to activate subscription tracing
|
// patch reactivity system to activate subscription tracing
|
||||||
@@ -453,9 +419,14 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
toggleTracing(value) {
|
toggleTracing(value) {
|
||||||
|
if (value) {
|
||||||
|
this.patchAppMethods();
|
||||||
|
this.patchAppMethods = () => {}; // to only patch once
|
||||||
|
}
|
||||||
this.traceRenderings = value;
|
this.traceRenderings = value;
|
||||||
return this.traceRenderings;
|
return this.traceRenderings;
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleSubscriptionTracing(value) {
|
toggleSubscriptionTracing(value) {
|
||||||
if (value) {
|
if (value) {
|
||||||
this.patchReactivity();
|
this.patchReactivity();
|
||||||
@@ -466,6 +437,10 @@
|
|||||||
}
|
}
|
||||||
// Enables/disables the recording of the render/destroy events based on value
|
// Enables/disables the recording of the render/destroy events based on value
|
||||||
toggleEventsRecording(value, index) {
|
toggleEventsRecording(value, index) {
|
||||||
|
if (value) {
|
||||||
|
this.patchAppMethods();
|
||||||
|
this.patchAppMethods = () => {}; // to only patch once
|
||||||
|
}
|
||||||
this.recordEvents = value;
|
this.recordEvents = value;
|
||||||
this.eventId = index;
|
this.eventId = index;
|
||||||
return this.recordEvents;
|
return this.recordEvents;
|
||||||
@@ -773,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":
|
||||||
@@ -819,57 +797,48 @@
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (child.contentType) {
|
if (!child.contentType) {
|
||||||
if (child.toggled) {
|
if (obj === null) {
|
||||||
child.children = this.loadObjectChildren(
|
child.content = "null";
|
||||||
child.path,
|
child.contentType = "object";
|
||||||
child.depth,
|
child.hasChildren = false;
|
||||||
child.contentType,
|
} else if (obj === undefined) {
|
||||||
child.objectType,
|
child.content = "undefined";
|
||||||
oldTree
|
child.contentType = "undefined";
|
||||||
);
|
child.hasChildren = false;
|
||||||
}
|
|
||||||
return child;
|
|
||||||
}
|
|
||||||
if (obj === null) {
|
|
||||||
child.content = "null";
|
|
||||||
child.contentType = "object";
|
|
||||||
child.hasChildren = false;
|
|
||||||
} else if (obj === undefined) {
|
|
||||||
child.content = "undefined";
|
|
||||||
child.contentType = "undefined";
|
|
||||||
child.hasChildren = false;
|
|
||||||
} else {
|
|
||||||
obj = this.toRaw(obj);
|
|
||||||
switch (true) {
|
|
||||||
case obj instanceof Map:
|
|
||||||
child.contentType = "map";
|
|
||||||
child.hasChildren = true;
|
|
||||||
break;
|
|
||||||
case obj instanceof Set:
|
|
||||||
child.contentType = "set";
|
|
||||||
child.hasChildren = true;
|
|
||||||
break;
|
|
||||||
case obj instanceof Array:
|
|
||||||
child.contentType = "array";
|
|
||||||
child.hasChildren = obj.length > 0;
|
|
||||||
break;
|
|
||||||
case typeof obj === "function":
|
|
||||||
child.contentType = "function";
|
|
||||||
child.hasChildren = true;
|
|
||||||
break;
|
|
||||||
case obj instanceof Object:
|
|
||||||
child.contentType = "object";
|
|
||||||
child.hasChildren = Object.keys(obj).length > 0;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
child.contentType = typeof obj;
|
|
||||||
child.hasChildren = false;
|
|
||||||
}
|
|
||||||
if (key.type === "set entry") {
|
|
||||||
child.content = this.serializer.serializeItem(obj, true);
|
|
||||||
} else {
|
} else {
|
||||||
child.content = this.serializer.serializeContent(obj, child.contentType);
|
obj = this.toRaw(obj);
|
||||||
|
switch (true) {
|
||||||
|
case obj instanceof Map:
|
||||||
|
child.contentType = "map";
|
||||||
|
child.hasChildren = true;
|
||||||
|
break;
|
||||||
|
case obj instanceof Set:
|
||||||
|
child.contentType = "set";
|
||||||
|
child.hasChildren = true;
|
||||||
|
break;
|
||||||
|
case obj instanceof Array:
|
||||||
|
child.contentType = "array";
|
||||||
|
child.hasChildren = obj.length > 0;
|
||||||
|
break;
|
||||||
|
case typeof obj === "function":
|
||||||
|
child.contentType = "function";
|
||||||
|
child.hasChildren = true;
|
||||||
|
break;
|
||||||
|
case obj instanceof Object:
|
||||||
|
child.contentType = "object";
|
||||||
|
child.hasChildren =
|
||||||
|
Object.keys(obj).length || Object.getOwnPropertySymbols(obj).length;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
child.contentType = typeof obj;
|
||||||
|
child.hasChildren = false;
|
||||||
|
}
|
||||||
|
if (key.type === "set entry") {
|
||||||
|
child.content = this.serializer.serializeItem(obj, true);
|
||||||
|
} else {
|
||||||
|
child.content = this.serializer.serializeContent(obj, child.contentType);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (child.toggled) {
|
if (child.toggled) {
|
||||||
@@ -881,6 +850,7 @@
|
|||||||
oldTree
|
oldTree
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
this.addHighlightedKeys(child);
|
||||||
return child;
|
return child;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -890,7 +860,10 @@
|
|||||||
let path = completePath.slice(objPathIndex);
|
let path = completePath.slice(objPathIndex);
|
||||||
let obj;
|
let obj;
|
||||||
if (objType === "subscription") {
|
if (objType === "subscription") {
|
||||||
obj = oldTree.subscriptions.children[path[1].value].target;
|
const subscriptionPath = completePath.slice(0, objPathIndex + 3);
|
||||||
|
obj = oldTree.subscriptions.children.find(
|
||||||
|
(child) => JSON.stringify(child.target.path) === JSON.stringify(subscriptionPath)
|
||||||
|
).target;
|
||||||
path = path.slice(3);
|
path = path.slice(3);
|
||||||
} else {
|
} else {
|
||||||
// Everything here is in component if it is not an app so remove this key of the path in the former case
|
// Everything here is in component if it is not an app so remove this key of the path in the former case
|
||||||
@@ -920,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 [];
|
||||||
}
|
}
|
||||||
@@ -935,7 +908,7 @@
|
|||||||
depth,
|
depth,
|
||||||
objType,
|
objType,
|
||||||
path,
|
path,
|
||||||
oldBranch.children[0],
|
oldBranch?.children[0],
|
||||||
oldTree
|
oldTree
|
||||||
);
|
);
|
||||||
children.push(mapKey);
|
children.push(mapKey);
|
||||||
@@ -945,7 +918,7 @@
|
|||||||
depth,
|
depth,
|
||||||
objType,
|
objType,
|
||||||
path,
|
path,
|
||||||
oldBranch.children[1],
|
oldBranch?.children[1],
|
||||||
oldTree
|
oldTree
|
||||||
);
|
);
|
||||||
children.push(mapValue);
|
children.push(mapValue);
|
||||||
@@ -956,7 +929,7 @@
|
|||||||
depth,
|
depth,
|
||||||
objType,
|
objType,
|
||||||
path,
|
path,
|
||||||
oldBranch.children[0],
|
oldBranch?.children[0],
|
||||||
oldTree
|
oldTree
|
||||||
);
|
);
|
||||||
children.push(setValue);
|
children.push(setValue);
|
||||||
@@ -977,7 +950,7 @@
|
|||||||
depth,
|
depth,
|
||||||
objType,
|
objType,
|
||||||
path,
|
path,
|
||||||
oldBranch.children[index],
|
oldBranch?.children[index],
|
||||||
oldTree
|
oldTree
|
||||||
);
|
);
|
||||||
if (child) {
|
if (child) {
|
||||||
@@ -992,7 +965,7 @@
|
|||||||
depth,
|
depth,
|
||||||
objType,
|
objType,
|
||||||
path,
|
path,
|
||||||
oldBranch.children[index],
|
oldBranch?.children[index],
|
||||||
oldTree
|
oldTree
|
||||||
);
|
);
|
||||||
if (child) {
|
if (child) {
|
||||||
@@ -1009,7 +982,7 @@
|
|||||||
depth,
|
depth,
|
||||||
objType,
|
objType,
|
||||||
path,
|
path,
|
||||||
oldBranch.children[index],
|
oldBranch?.children[index],
|
||||||
oldTree
|
oldTree
|
||||||
);
|
);
|
||||||
if (entries) {
|
if (entries) {
|
||||||
@@ -1023,7 +996,7 @@
|
|||||||
depth,
|
depth,
|
||||||
objType,
|
objType,
|
||||||
path,
|
path,
|
||||||
oldBranch.children[index],
|
oldBranch?.children[index],
|
||||||
oldTree
|
oldTree
|
||||||
);
|
);
|
||||||
if (child) {
|
if (child) {
|
||||||
@@ -1058,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);
|
||||||
@@ -1091,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);
|
||||||
@@ -1303,16 +1276,15 @@
|
|||||||
children: [],
|
children: [],
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
const rawSubscriptions = node.subscriptions;
|
const rawSubscriptions = this.topLevelSubscriptions(node);
|
||||||
component.subscriptions = {
|
component.subscriptions = {
|
||||||
toggled: oldTree ? oldTree.subscriptions.toggled : true,
|
toggled: oldTree ? oldTree.subscriptions.toggled : true,
|
||||||
children: [],
|
children: [],
|
||||||
};
|
};
|
||||||
rawSubscriptions.forEach((rawSubscription, index) => {
|
rawSubscriptions.forEach((rawSubscription) => {
|
||||||
let subscription = {
|
let subscription = {
|
||||||
keys: [],
|
|
||||||
target: {
|
target: {
|
||||||
name: "target",
|
name: this.targetName(rawSubscription.target, node),
|
||||||
contentType:
|
contentType:
|
||||||
typeof rawSubscription.target === "object"
|
typeof rawSubscription.target === "object"
|
||||||
? Array.isArray(rawSubscription.target)
|
? Array.isArray(rawSubscription.target)
|
||||||
@@ -1323,28 +1295,20 @@
|
|||||||
path: [
|
path: [
|
||||||
...path,
|
...path,
|
||||||
{ type: "item", value: "subscriptions" },
|
{ type: "item", value: "subscriptions" },
|
||||||
{ type: "item", value: index },
|
{ type: "item", value: rawSubscription.index },
|
||||||
{ type: "item", value: "target" },
|
{ type: "item", value: "target" },
|
||||||
],
|
],
|
||||||
toggled: false,
|
toggled: false,
|
||||||
objectType: "subscription",
|
objectType: "subscription",
|
||||||
},
|
},
|
||||||
keysExpanded: false,
|
|
||||||
};
|
};
|
||||||
if (
|
if (
|
||||||
oldTree &&
|
oldTree &&
|
||||||
oldTree.subscriptions.children[index] &&
|
oldTree.subscriptions.children[rawSubscription.index] &&
|
||||||
oldTree.subscriptions.children[index].target.toggled
|
oldTree.subscriptions.children[rawSubscription.index].target.toggled
|
||||||
) {
|
) {
|
||||||
subscription.target.toggled = true;
|
subscription.target.toggled = true;
|
||||||
}
|
}
|
||||||
rawSubscription.keys.forEach((key) => {
|
|
||||||
if (typeof key === "symbol") {
|
|
||||||
subscription.keys.push(key.toString());
|
|
||||||
} else {
|
|
||||||
subscription.keys.push(key);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (rawSubscription.target == null) {
|
if (rawSubscription.target == null) {
|
||||||
if (subscription.target.contentType === "undefined") {
|
if (subscription.target.contentType === "undefined") {
|
||||||
subscription.target.content = "undefined";
|
subscription.target.content = "undefined";
|
||||||
@@ -1374,6 +1338,7 @@
|
|||||||
oldTree
|
oldTree
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
this.addHighlightedKeys(subscription.target);
|
||||||
component.subscriptions.children.push(subscription);
|
component.subscriptions.children.push(subscription);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -1481,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;
|
||||||
}
|
}
|
||||||
@@ -1551,12 +1519,13 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 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
|
||||||
getComponentsTree(inspectedPath = null, oldTrees = null) {
|
getComponentsTree(inspectedPath = null, oldTrees = null, oldDetails = null) {
|
||||||
const appsArray = [...this.apps];
|
const appsArray = [...this.apps];
|
||||||
const trees = appsArray.map((app, index) => {
|
const trees = appsArray.map((app, index) => {
|
||||||
let oldTree;
|
let oldTree;
|
||||||
@@ -1609,7 +1578,8 @@
|
|||||||
}
|
}
|
||||||
return appNode;
|
return appNode;
|
||||||
});
|
});
|
||||||
return trees ? trees : [];
|
const component = this.getComponentDetails(inspectedPath, oldDetails);
|
||||||
|
return trees ? [trees, component] : [];
|
||||||
}
|
}
|
||||||
// Recursively fills the components tree as a parsed version
|
// Recursively fills the components tree as a parsed version
|
||||||
fillTree(appNode, treeNode, inspectedPathString, oldBranch) {
|
fillTree(appNode, treeNode, inspectedPathString, oldBranch) {
|
||||||
@@ -1705,6 +1675,54 @@
|
|||||||
inspect(obj);
|
inspect(obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
targetName(target, node) {
|
||||||
|
// check on component
|
||||||
|
const { component } = node;
|
||||||
|
for (const [key, value] of Object.entries(component)) {
|
||||||
|
if (target === this.toRaw(value)) {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// check on props
|
||||||
|
for (const [key, value] of Object.entries(component.props)) {
|
||||||
|
if (target === this.toRaw(value)) {
|
||||||
|
return `props.${key}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "[unknown]";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes subscriptions that are a direct child of another subscription:
|
||||||
|
* they will be reachable from the top level by expanding observed keys.
|
||||||
|
*
|
||||||
|
* @param {ComponentNode} node
|
||||||
|
* @returns {{ keys: PropertyKey[], target: unknown}[]} the top level
|
||||||
|
* subscriptions of the node
|
||||||
|
*/
|
||||||
|
topLevelSubscriptions(node) {
|
||||||
|
const subscriptions = node.subscriptions.map((s, index) => ({ ...s, index }));
|
||||||
|
const topLevelValues = new Set(Object.values(node.component).map((o) => this.toRaw(o)));
|
||||||
|
const toOmit = new Set(
|
||||||
|
subscriptions
|
||||||
|
.flatMap(({ keys, target }) => keys.map((k) => this.toRaw(target[k])))
|
||||||
|
.filter((obj) => !topLevelValues.has(obj))
|
||||||
|
);
|
||||||
|
return subscriptions.filter(({ target }) => !toOmit.has(target));
|
||||||
|
}
|
||||||
|
|
||||||
|
addHighlightedKeys(child) {
|
||||||
|
const { path } = child;
|
||||||
|
const subscriptionIndex = path.findIndex((item) => typeof item !== "string");
|
||||||
|
if (path[subscriptionIndex]?.value === "subscriptions") {
|
||||||
|
const node = this.getComponentNode(path.slice(0, subscriptionIndex));
|
||||||
|
// Add observed keys
|
||||||
|
const targetToKeys = new Map(node.subscriptions.map(({ keys, target }) => [target, keys]));
|
||||||
|
const target = this.getObjectProperty(child.path);
|
||||||
|
child.keys = targetToKeys.get(target)?.map((k) => String(k));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkOwlStatus() {
|
function checkOwlStatus() {
|
||||||
|
|||||||
+6
-7
@@ -82,6 +82,12 @@ async function startRelease() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
log(`Step ${step++}/${STEPS}: updating package.json...`);
|
||||||
|
await writeFile("package.json", JSON.stringify({...package, version: next}, null, 2) + "\n");
|
||||||
|
await writeFile("package-lock.json", JSON.stringify({...packageLock, version: next}, null, 2) + "\n");
|
||||||
|
await writeFile("./src/version.ts", `// do not modify manually. This file is generated by the release script.\nexport const version = "${next}";\n`);
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
log(`Step ${step++}/${STEPS}: building owl...`);
|
log(`Step ${step++}/${STEPS}: building owl...`);
|
||||||
await execCommand("rm -rf dist/");
|
await execCommand("rm -rf dist/");
|
||||||
@@ -108,13 +114,6 @@ async function startRelease() {
|
|||||||
await execCommand("cd dist && zip -r owl-devtools.zip devtools-chrome devtools-firefox && cd ..");
|
await execCommand("cd dist && zip -r owl-devtools.zip devtools-chrome devtools-firefox && cd ..");
|
||||||
await execCommand("rm -r dist/devtools-chrome dist/devtools-firefox && rm dist/compiler.js");
|
await execCommand("rm -r dist/devtools-chrome dist/devtools-firefox && rm dist/compiler.js");
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
log(`Step ${step++}/${STEPS}: updating package.json...`);
|
|
||||||
await writeFile("package.json", JSON.stringify({...package, version: next}, null, 2) + "\n");
|
|
||||||
await writeFile("package-lock.json", JSON.stringify({...packageLock, version: next}, null, 2) + "\n");
|
|
||||||
await writeFile("./src/version.ts", `// do not modify manually. This file is generated by the release script.\nexport const version = "${next}";\n`);
|
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
log(`Step ${step++}/${STEPS}: updating owl on github page...`);
|
log(`Step ${step++}/${STEPS}: updating owl on github page...`);
|
||||||
await fs.copyFileSync("dist/owl.es.js", "docs/owl.js");
|
await fs.copyFileSync("dist/owl.es.js", "docs/owl.js");
|
||||||
|
|||||||
Reference in New Issue
Block a user