mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 71a9b21472 | |||
| 5cbf43110f | |||
| e00be61b8e |
@@ -24,4 +24,4 @@ jobs:
|
|||||||
node-version: ${{ matrix.node-version }}
|
node-version: ${{ matrix.node-version }}
|
||||||
- run: npm install
|
- run: npm install
|
||||||
- run: npm run test
|
- run: npm run test
|
||||||
- run: npm run check-formatting
|
- run: npm run prettier
|
||||||
|
|||||||
@@ -30,5 +30,4 @@ release-notes.md
|
|||||||
|
|
||||||
.rpt2_cache
|
.rpt2_cache
|
||||||
|
|
||||||
# useful in some cases
|
|
||||||
/temp
|
/temp
|
||||||
-588
@@ -1,588 +0,0 @@
|
|||||||
# ChangeLog
|
|
||||||
|
|
||||||
This document contains an overview of all changes between Owl 1.x and
|
|
||||||
Owl 2.x, with some pointers on how to update the code.
|
|
||||||
|
|
||||||
Note that some of these changes can be magically implemented (for example, by
|
|
||||||
patching the `setup` method of `Component` to auto register all the lifecycle
|
|
||||||
methods as hooks). This will be done for the transition period, but will be
|
|
||||||
removed after.
|
|
||||||
|
|
||||||
## Changes
|
|
||||||
|
|
||||||
**Components**
|
|
||||||
|
|
||||||
- components can now have empty content or multiple root nodes (htmlelement or text) ([details](#31-components-can-now-have-arbitrary-content))
|
|
||||||
- new `useEffect` hook
|
|
||||||
- new `onDestroyed`, `onWillRender` and `onRendered` hooks
|
|
||||||
- breaking: lifecycle methods are removed ([details](#1-component-lifecycle-methods-are-removed))
|
|
||||||
- breaking: can no longer be mounted on detached DOM ([details](#2-components-can-no-longer-be-mounted-in-a-detached-dom-element))
|
|
||||||
- breaking: standalone `mount` method API is simpler ([details](#4-mount-method-api-is-simpler))
|
|
||||||
- breaking: components can no longer be instantiated and mounted by hand ([details](#5-components-can-no-longer-be-instantiated-and-mounted-by-hand))
|
|
||||||
- breaking: components can no longer be unmounted/remounted ([details](#6-components-can-no-longer-be-unmountedremounted))
|
|
||||||
- breaking: template name is no longer inferred from the class name ([details](#7-template-name-is-no-longer-inferred-from-the-class-name))
|
|
||||||
- breaking: components no longer have a `shouldUpdate` method ([details](#8-components-no-longer-have-a-shouldupdate-method))
|
|
||||||
- breaking: component.el may be a text node, and is no longer `null` ([details](#9-componentel-may-be-a-text-node-and-is-no-longer-null))
|
|
||||||
- breaking: style/class on components are now regular props ([details](#10-styleclass-on-components-are-now-regular-props))
|
|
||||||
- breaking: components can no longer be mounted with position=self ([details](#11-components-can-no-longer-be-mounted-with-positionself))
|
|
||||||
- breaking: `t-on` does not work on components any more ([details](#12-t-on-does-not-work-on-components-any-more))
|
|
||||||
- breaking: `t-component` no longer accepts strings ([details](#17-t-component-no-longer-accepts-strings))
|
|
||||||
|
|
||||||
**Portal**
|
|
||||||
|
|
||||||
- portals can now have arbitrary content (no longer restricted to one single child)
|
|
||||||
- breaking: does no longer transfer dom events ([details](#13-portal-does-no-longer-transfer-dom-events))
|
|
||||||
- breaking: does render as an empty text node instead of `<portal/>` ([details](#14-portal-does-render-as-an-empty-text-node-instead-of-portal))
|
|
||||||
|
|
||||||
**Slots**
|
|
||||||
|
|
||||||
- breaking: `t-set` does not define a slot any more ([details](#3-t-set-will-no-longer-work-to-define-a-slot))
|
|
||||||
|
|
||||||
**Miscellaneous**
|
|
||||||
|
|
||||||
- improved performance
|
|
||||||
- much simpler code
|
|
||||||
- finer grained reactivity: owl 2 tracks change per key/component
|
|
||||||
- finer grained reactivity: sub components can reobserve state
|
|
||||||
- new App class to encapsulate a root Owl component (with the config for that application)
|
|
||||||
- new `Memo` component
|
|
||||||
- breaking: `Context` is removed ([details](#15-context-is-removed))
|
|
||||||
- breaking: `env` is now totally empty ([details](#16-env-is-now-totally-empty))
|
|
||||||
- breaking: most exports are exported at top level ([details](#18-most-exports-are-exported-at-top-level))
|
|
||||||
- breaking: properties are no longer set as attributes ([details](#19-properties-are-no-longer-set-as-attributes))
|
|
||||||
- breaking: `t-foreach` should always have a corresponding `t-key` ([details](#20-t-foreach-should-always-have-a-corresponding-t-key))
|
|
||||||
- breaking: `EventBus` api changed: it is now an `EventTarget` ([details](#21-eventbus-api-changed-it-is-now-an-eventtarget))
|
|
||||||
- breaking: `Store` is removed ([details](#22-store-is-removed))
|
|
||||||
- breaking: `Router` is removed ([details](#23-router-is-removed))
|
|
||||||
- breaking: transition system is removed ([details](#24-transition-system-is-removed))
|
|
||||||
- breaking: no more global components or templates ([details](#25-no-more-global-components-or-templates))
|
|
||||||
- breaking: `AsyncRoot` utility component is removed ([details](#26-asyncroot-utility-component-is-removed))
|
|
||||||
- breaking: `useSubEnv` only applies to child components ([details](#27-usesubenv-only-applies-to-child-components))
|
|
||||||
- breaking: `env` is now frozen ([details](#28-env-is-now-frozen))
|
|
||||||
- breaking: `t-ref` does not work on components ([details](#29-t-ref-does-not-work-on-component))
|
|
||||||
- breaking: `t-on` does not accept expressions, only functions ([details](#30-t-on-does-not-accept-expressions-only-functions))
|
|
||||||
|
|
||||||
|
|
||||||
## Details/Rationale/Migration
|
|
||||||
|
|
||||||
All changes are listed in no particular order.
|
|
||||||
|
|
||||||
### 1. component lifecycle methods are removed
|
|
||||||
|
|
||||||
There was two ways to define hooks: the component methods (`willStart`, `mounted`, ...) and the hooks (`onWillStart`, `onMounted`, ...). In Owl 2, the component methods have been removed.
|
|
||||||
|
|
||||||
Rationale: it makes the implementation simpler and slightly faster. Hooks are more composable
|
|
||||||
than component methods. It enforces a single entry point to check all the useful lifecycle
|
|
||||||
calls (instead of it being scattered in the component definition). It feels more "modern".
|
|
||||||
|
|
||||||
Migration: lifecycle methods should be defined in the `setup`:
|
|
||||||
|
|
||||||
```js
|
|
||||||
class MyComponent extends Component {
|
|
||||||
mounted() {
|
|
||||||
// do something
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
should become:
|
|
||||||
```js
|
|
||||||
class MyComponent extends Component {
|
|
||||||
setup() {
|
|
||||||
onMounted(() => {
|
|
||||||
// do something
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 2. components can no longer be mounted in a detached dom element
|
|
||||||
|
|
||||||
Nor document fragment.
|
|
||||||
|
|
||||||
Rationale: it is actually very difficult to do it: this implies that a component
|
|
||||||
can be mounted more than once, that we need to check every time different status,
|
|
||||||
that some elements is in the dom, and was a cause for bugs. Also, we don't use it
|
|
||||||
in practice. Removing this means that we have a much simpler mental model of what
|
|
||||||
happens.
|
|
||||||
|
|
||||||
Migration: well, not really easy. The code needs to be refactored in a different way.
|
|
||||||
|
|
||||||
|
|
||||||
### 3. **`t-set` will no longer work to define a slot**
|
|
||||||
|
|
||||||
The `t-set` directive cannot define a slot anymore. Only the `t-set-slot` directive
|
|
||||||
can do it.
|
|
||||||
|
|
||||||
Rationale: it was left for compatibility reason, but was deprecated anyway.
|
|
||||||
|
|
||||||
Migration: `t-set` should be changed to `t-set-slot` (when defining a slot)
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```xml
|
|
||||||
<SideBar><t t-set="content">content</t></SideBar>
|
|
||||||
```
|
|
||||||
should become:
|
|
||||||
```xml
|
|
||||||
<SideBar><t t-set-slot="content">content</t></SideBar>
|
|
||||||
```
|
|
||||||
|
|
||||||
### 4. `mount` method API is simpler
|
|
||||||
|
|
||||||
Before, the `mount` method was used like this:
|
|
||||||
|
|
||||||
```js
|
|
||||||
await mount(Root, { target: document.body });
|
|
||||||
```
|
|
||||||
|
|
||||||
It is now simpler and takes the root component and a target argument:
|
|
||||||
|
|
||||||
```js
|
|
||||||
await mount(Root, document.body);
|
|
||||||
```
|
|
||||||
|
|
||||||
Rationale: the `mount` method is only useful anyway for small toy examples,
|
|
||||||
because real applications will need to configure the templates, the translations,
|
|
||||||
and other stuff. All complex usecases need to go through the new `App` class,
|
|
||||||
that encapsulates the root of an owl application.
|
|
||||||
|
|
||||||
### 5. components can no longer be instantiated and mounted by hand
|
|
||||||
|
|
||||||
In Owl 1, it was possible to instantiate a component by hand:
|
|
||||||
|
|
||||||
```js
|
|
||||||
const root = new Root();
|
|
||||||
await root.mount(document.body);
|
|
||||||
```
|
|
||||||
|
|
||||||
Now, it is no longer possible. All component instantiations should be done by
|
|
||||||
the owl framework itself.
|
|
||||||
|
|
||||||
Rationale: the `mount` method does not make sense for all non root components.
|
|
||||||
Also, the fact that it was possible for a component to be sometimes root,
|
|
||||||
sometimes a child made for a weird constructor signature. This changes makes it
|
|
||||||
simpler.
|
|
||||||
|
|
||||||
Migration: all code doing that should use either the `mount` method (if the use
|
|
||||||
case is simple enough, or the `App` class):
|
|
||||||
|
|
||||||
```js
|
|
||||||
const app = new App(Root);
|
|
||||||
app.configure({ templates: ..., ...});
|
|
||||||
await app.mount(document.body);
|
|
||||||
```
|
|
||||||
|
|
||||||
### 6. components can no longer be unmounted/remounted
|
|
||||||
|
|
||||||
Rationale: this is a very difficult feature to implement (it adds a lot of possible
|
|
||||||
state transitions), compared to its benefit.
|
|
||||||
|
|
||||||
Migration: all code using it should find a way to export and reimport the state
|
|
||||||
|
|
||||||
### 7. template name is no longer inferred from the class name
|
|
||||||
|
|
||||||
Before, it was possible to define a component without specifying its template:
|
|
||||||
|
|
||||||
```js
|
|
||||||
class Blabla extends Component {
|
|
||||||
// no static template here!
|
|
||||||
}
|
|
||||||
```
|
|
||||||
with the `Blabla` template. It also worked with subclasses. But then, this means
|
|
||||||
that the code had to look up all the super classes names to find the correct
|
|
||||||
template.
|
|
||||||
|
|
||||||
Rationale: in practice, it is not really useful, since all templates are usually
|
|
||||||
namespaced: `web.SomeComponent` anyway. All the trouble to do that was just not
|
|
||||||
worth it.
|
|
||||||
|
|
||||||
Migration: simply explicitely defines the template key everytime:
|
|
||||||
|
|
||||||
```js
|
|
||||||
class Blabla extends Component {}
|
|
||||||
Blabla.template = "Blabla";
|
|
||||||
```
|
|
||||||
|
|
||||||
### 8. components no longer have a `shouldUpdate` method
|
|
||||||
|
|
||||||
Rationale: `shouldUpdate` is a dangerous method to use, that may cause a lot of
|
|
||||||
issues. Vue does not have such a mechanism (see https://github.com/vuejs/vue/issues/4255),
|
|
||||||
because the reactivity system in Vue is smart enough to only rerender the minimal
|
|
||||||
subset of components that is subscribed to a piece of state. Now, Owl 2 features
|
|
||||||
a much more powerful reactivity system.
|
|
||||||
|
|
||||||
Migration code: remove the `shouldUpdate` methods. Then, maybe the following
|
|
||||||
ideas may help:
|
|
||||||
|
|
||||||
- try to organize the state/architecture to minimize the number of state updates
|
|
||||||
- take advantage of the finer reactivity system. For example, if we have a list
|
|
||||||
of items, with a component for each item, we can write this:
|
|
||||||
|
|
||||||
```js
|
|
||||||
class Item extends Component {
|
|
||||||
setup() {
|
|
||||||
this.item = useState(this.props.item); // and only use this, not props.item
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
Doing so will make it that each `Item` component will register itself as an
|
|
||||||
observer of its own item, and will be the only component being rerendered when
|
|
||||||
its item object is updated.
|
|
||||||
- use the `Memo` component to wrap some piece of template. `Memo` memoize its
|
|
||||||
content, and only update itself if its props are different (shallow comparison):
|
|
||||||
|
|
||||||
```xml
|
|
||||||
<Memo a="state.a" b="state.b">
|
|
||||||
<t t-esc="state.a"/>
|
|
||||||
<t t-esc="state.b"/>
|
|
||||||
<t t-esc="state.c"/>
|
|
||||||
</Memo>
|
|
||||||
```
|
|
||||||
|
|
||||||
### 9. component.el may be a text node, and is no longer `null`
|
|
||||||
|
|
||||||
This comes from the fact that Owl 2 supports fragments (arbitrary content). When
|
|
||||||
it is not defined, it was `null` in Owl 1 and is `undefined` in owl 2.
|
|
||||||
|
|
||||||
### 10. style/class on components are now regular props
|
|
||||||
|
|
||||||
Before, it was possible to do this in a template:
|
|
||||||
|
|
||||||
```xml
|
|
||||||
<Child style="..." class="..."/>
|
|
||||||
```
|
|
||||||
(or with `t-att-style` and `t-att-class`). This does no longer work, as they are
|
|
||||||
now considered normal props.
|
|
||||||
|
|
||||||
Rationale: with the move to fragments, the semantics of where the style/class
|
|
||||||
attribute should be set is unclear. Also, it is actually very hard to implement
|
|
||||||
properly, in particular with higher order components. And another issue is that
|
|
||||||
it (slightly) breaks the encapsulation of behaviour from the `Child` component
|
|
||||||
perspective.
|
|
||||||
|
|
||||||
Migration: each component that wishes to be customized should explicitely add
|
|
||||||
the `class` and `style` attributes in its template. Also, the parent component
|
|
||||||
should be aware that since we are talking about props, it should be a javascript expression:
|
|
||||||
|
|
||||||
In parent:
|
|
||||||
|
|
||||||
```xml
|
|
||||||
<Child class="'o_my_god'"/>
|
|
||||||
```
|
|
||||||
and in child:
|
|
||||||
|
|
||||||
```xml
|
|
||||||
<div t-att-class="props.class">
|
|
||||||
...
|
|
||||||
</div>
|
|
||||||
```
|
|
||||||
|
|
||||||
### 11. components can no longer be mounted with position=self
|
|
||||||
|
|
||||||
Rationale: this is due to the implementation of owl 2 virtual dom. The hack
|
|
||||||
necessary to support position=self does not work. This position also is not
|
|
||||||
compatible with the fact that a component can have a root `<div>` then later,
|
|
||||||
change it to something else, or even a text node.
|
|
||||||
|
|
||||||
Migration: no real way to do the same. Owl application needs to be appended or
|
|
||||||
prepended in something, maybe a `div`.
|
|
||||||
|
|
||||||
### 12. `t-on` does not work on components any more
|
|
||||||
|
|
||||||
In owl 1, it was possible to bind an event listener on a component tag in a
|
|
||||||
template:
|
|
||||||
|
|
||||||
```xml
|
|
||||||
<SomeComponent t-on-some-event="doSomething"/>
|
|
||||||
```
|
|
||||||
|
|
||||||
This does not work any more.
|
|
||||||
|
|
||||||
Rationale: with the support of fragments, there is no longer a canonical html
|
|
||||||
element that we can refer. So, this makes it difficult to implement correctly
|
|
||||||
and efficiently. Also, we noticed in practice that the event system was an issue
|
|
||||||
in some cases, when components need to communicate before they are mounted. In
|
|
||||||
those cases, the better solution is to directly use a callback. Also, another
|
|
||||||
conceptual issue with this is that it kind of breaks the component encapsulation.
|
|
||||||
The child component kind of leak its own implementation to the outside world.
|
|
||||||
|
|
||||||
Migration: a quick fix that may work in some cases is to simply bind the event
|
|
||||||
handler on a parent htmlelement. A better way to do it, if possible, is to change
|
|
||||||
the component API to accept explicitely a callback as props.
|
|
||||||
|
|
||||||
```xml
|
|
||||||
<SomeComponent onSomeEvent="doSomething"/>
|
|
||||||
```
|
|
||||||
|
|
||||||
### 13. Portal does no longer transfer DOM events
|
|
||||||
|
|
||||||
In Owl 1, a Portal component would listen to events emitted on its portalled
|
|
||||||
child, and redispatch them on itself. It no longer works.
|
|
||||||
|
|
||||||
Rationale: Portal now supports an arbitrary content (so, more than one child,
|
|
||||||
and potentially no html element), so it is already unclear what it should listen
|
|
||||||
to. Also, redispatching events was an hack. And this changes allows the portal
|
|
||||||
to render itself as a text node, which is nice. This is also in line with the
|
|
||||||
fact that modern Owl moves toward using callback instead of `t-on` for communication.
|
|
||||||
|
|
||||||
Migration: use callback if possible to communicate. Otherwise, use a sub env.
|
|
||||||
|
|
||||||
### 14. Portal does render as an empty text node instead of `<portal/>`
|
|
||||||
|
|
||||||
That is pretty nice. No real migration needed.
|
|
||||||
|
|
||||||
### 15. Context is removed
|
|
||||||
|
|
||||||
Context was an abstraction in Owl that was used to define some reactive state
|
|
||||||
and to let some components subscribe to it, then only them would be rerendered
|
|
||||||
if the context was updated. This has been removed.
|
|
||||||
|
|
||||||
Rationale: first, the Context api and code was kind of awkward, which is a sign
|
|
||||||
that the abstraction is not well thought. But the good news is that it is actually
|
|
||||||
completely replaced by the new reactivity system, which is even more powerful,
|
|
||||||
since it can tracks changes key by key.
|
|
||||||
|
|
||||||
Migration: replace all uses of Context with the new reactivity system.
|
|
||||||
|
|
||||||
```js
|
|
||||||
// somewhere, maybe in a service, or in the global env
|
|
||||||
const context = observe({some: "state"})
|
|
||||||
|
|
||||||
// in a component that would previously get a reference to the context:
|
|
||||||
|
|
||||||
setup() {
|
|
||||||
this.context = useState(context);
|
|
||||||
// now the component is subscribed to the context and will react to any
|
|
||||||
// change for any key read by the component, and only those changes
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 16. `env` is now totally empty
|
|
||||||
|
|
||||||
In Owl 1, the `env` object had to contain a QWeb instance. This was the way
|
|
||||||
components would get a reference to their template function. It no longer works
|
|
||||||
that way: the `env` object is now totally empty (from the perspective of Owl).
|
|
||||||
It is now a user space concept, useful for the application.
|
|
||||||
|
|
||||||
Rationale: first, there is no longer a QWeb class. Also, this changes simplifies
|
|
||||||
the way components works internally.
|
|
||||||
|
|
||||||
Migration: there is no proper way to get an equivalent. The closest is to get
|
|
||||||
a reference to the root App using `this.__owl__.app`. If you need to do this,
|
|
||||||
let us know. If this is a legitimate usecase, we may add a `useApp` hook.
|
|
||||||
|
|
||||||
### 17. `t-component` no longer accepts strings
|
|
||||||
|
|
||||||
In owl 1, we could write this:
|
|
||||||
|
|
||||||
```xml
|
|
||||||
<t t-component="Coucou"/>
|
|
||||||
```
|
|
||||||
|
|
||||||
This meant that Owl would look for the component class like this: `components["Coucou"]`,
|
|
||||||
so, essentially equivalent to `<Coucou/>`. In Owl 2, the `t-component` directive
|
|
||||||
is assumed to be an expression evaluating to a component class:
|
|
||||||
|
|
||||||
```js
|
|
||||||
class Parent extends Component {
|
|
||||||
static template = xml`<t t-component="Child"/>`;
|
|
||||||
Child = Child;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Rationale: it simply seems more consistent with the way directive works. Also,
|
|
||||||
the implementation is slightly simpler.
|
|
||||||
|
|
||||||
Migration: simply using `constructor.components.Coucou` instead of `Coucou` will
|
|
||||||
do the trick.
|
|
||||||
|
|
||||||
### 18. most exports are exported at top level
|
|
||||||
|
|
||||||
Most exports are flattened: for ex, `onMounted` is in owl, not in `owl.hooks`.
|
|
||||||
|
|
||||||
Rationale: this makes it easier to work with, instead of importing stuff from
|
|
||||||
`owl`, then `owl.hooks` and `owl.tags` for example.
|
|
||||||
|
|
||||||
Migration: all import code simply need to be slightly adapted.
|
|
||||||
|
|
||||||
### 19. Properties are no longer set as attributes
|
|
||||||
|
|
||||||
Formerly, html properties `<input type="checkbox" t-att-checked="blah"/>` were
|
|
||||||
set as property and as attribute, so, they would be visible in the DOM:
|
|
||||||
`<input type="checkbox" checked="blah"/>`. Now, they are treated as property only:
|
|
||||||
`<input type="checkbox"/>`.
|
|
||||||
|
|
||||||
Rationale: this is actually simple to do, is faster, and makes more sense to me.
|
|
||||||
|
|
||||||
### 20. `t-foreach` should always have a corresponding `t-key`
|
|
||||||
|
|
||||||
It was possible in Owl 1 to write a `t-foreach` without a `t-key`. In that case,
|
|
||||||
the index was used as key. Since it was clearly a possible bug, Owl 1 had a
|
|
||||||
warning in some cases, when it could detect that there was definitely not a `t-key`.
|
|
||||||
However, this was imperfect, and in some cases no warning was displayed. In Owl 2,
|
|
||||||
the tag with a `t-foreach` has to have a corresponding `t-key`.
|
|
||||||
|
|
||||||
Rationale: this makes it easier to avoid bugs.
|
|
||||||
|
|
||||||
Migration: simply move the `t-key` to the tag with the `t-foreach`. If this is
|
|
||||||
a situation where there is really not a need for a `t-key`, you can still add
|
|
||||||
it with the `_index` suffix:
|
|
||||||
|
|
||||||
```xml
|
|
||||||
<div t-foreach="items" t-as="item" t-key="item_index">
|
|
||||||
...
|
|
||||||
</div>
|
|
||||||
```
|
|
||||||
|
|
||||||
### 21. `EventBus` api changed: it is now an `EventTarget`
|
|
||||||
|
|
||||||
In Owl 1, the `EventBus` class was done manually, with a custom API. In Owl 2,
|
|
||||||
it simply extends `EventTarget` (the native Dom class), so its implementation
|
|
||||||
is basically only 5 lines long. This means that it has now the usual DOM interface:
|
|
||||||
|
|
||||||
```js
|
|
||||||
bus.addEventListener('event-name', callback);
|
|
||||||
```
|
|
||||||
|
|
||||||
Rationale: it makes it easier to have just one interface to remember, it makes
|
|
||||||
the code simpler
|
|
||||||
|
|
||||||
Migration: most bus methods need to be adapted. So, `bus.on("event-type", owner, (info) => {...})` has to be
|
|
||||||
rewritten like this: `bus.addEventListener("event-type", (({detail: info}) => {...}).bind(owner))`.
|
|
||||||
|
|
||||||
Do not forget to similarly replace `bus.off(...)` by `bus.removeEventListener(...)`
|
|
||||||
|
|
||||||
### 22. `Store` is removed
|
|
||||||
|
|
||||||
The Store system had been abandoned in owl 2.
|
|
||||||
|
|
||||||
Rationale: first, it was complicated to maintain. Second, it was not really
|
|
||||||
used in Odoo. Finally, the new reactivity system seems to be a pretty good basis
|
|
||||||
to write a store, and it should not take much work. Also, this can be done in
|
|
||||||
user space (so, not necessarily at the framework level). Another point is that
|
|
||||||
the store API was invented before the hooks, then was still a little awkward.
|
|
||||||
|
|
||||||
Migration:
|
|
||||||
- rewrite the code not to use a store
|
|
||||||
- probably use the reactivity system instead and build a store class and a few
|
|
||||||
hooks on top of it.
|
|
||||||
|
|
||||||
### 23. `Router` is removed
|
|
||||||
|
|
||||||
Rationale: Router was not used that much, and it felt like it did not fit in Owl 2.
|
|
||||||
Its API needs to be reworked, and we are not confident that it is a good
|
|
||||||
experience to use it. Also, it can be done in userspace (it does not need specific
|
|
||||||
integration at the framework level)
|
|
||||||
|
|
||||||
Migration: reimport all missing piece from the code in Owl 1.
|
|
||||||
|
|
||||||
### 24. transition system is removed
|
|
||||||
|
|
||||||
Rationale: this was a high ratio cost/value, with a lot of potential for bugs.
|
|
||||||
We feel like there should be a way to reimplement in userspace the simple cases.
|
|
||||||
|
|
||||||
Maybe something like: add a `t-ref` in the template, and define a hook `useFadeOut`
|
|
||||||
that takes the ref, and add a fadeout class at initial render, then in mounted,
|
|
||||||
wait for a micro tick and remove it.
|
|
||||||
|
|
||||||
Migration: try to reimplement it manually.
|
|
||||||
|
|
||||||
### 25. no more global components or templates
|
|
||||||
|
|
||||||
It was possible in Owl 1 to register globally a component or a template. This is
|
|
||||||
no longer the case in Owl 2.
|
|
||||||
|
|
||||||
Rationale: first, this was a tradeoff: ease of use was gained, but at the cost
|
|
||||||
of a higher complexity. Users had to know that there was a magic mechanism. Also,
|
|
||||||
it was not used much in practice, and the cost of having to import manually components
|
|
||||||
is low. Finally, this can be mostly done in user space (for example, by subclassing
|
|
||||||
`Component`).
|
|
||||||
|
|
||||||
Migration: import manually all required global components, or find a way to organize
|
|
||||||
the code to do it.
|
|
||||||
|
|
||||||
### 26. `AsyncRoot` utility component is removed
|
|
||||||
|
|
||||||
Rationale: it was difficult to understand, never used, and not really useful.
|
|
||||||
It seems better to control the asynchrony of an application by simply controlling
|
|
||||||
how/when the state is updated, and how each component is loading/updating itself.
|
|
||||||
|
|
||||||
Migration: remove the `AsyncRoot` component, then possibly, reorganize the code
|
|
||||||
to fetch data in a higher order component, and using a `t-if/t-else` to display
|
|
||||||
either a fallback when the data is not ready, or the actual component with data
|
|
||||||
as props. If there is no escape, and `AsyncRoot` is needed, please reach out to
|
|
||||||
us so we can study this usecase.
|
|
||||||
|
|
||||||
### 27. `useSubEnv` only applies to child components
|
|
||||||
|
|
||||||
In Owl 1, a call to `useSubEnv` would define a new environment for the children
|
|
||||||
AND the component. It now only defines an environment for the children.
|
|
||||||
|
|
||||||
Rationale: This was a subtle cause for bugs: some code had to be rrun
|
|
||||||
before the call to `useSubEnv`, otherwise it could interfere with the sub environment.
|
|
||||||
|
|
||||||
|
|
||||||
### 28. `env` is now frozen
|
|
||||||
|
|
||||||
In Owl 2, the `env` object is frozen. It can no longer be modified (structurally)
|
|
||||||
arbitrarily.
|
|
||||||
|
|
||||||
Rationale: it seems like the `env` object purpose is to have a global channel of
|
|
||||||
communication between components. It is however scary if anyone can add something
|
|
||||||
to it. The usual use case is to add something to the environment for some child
|
|
||||||
components. This use case still works with `useSubEnv`.
|
|
||||||
|
|
||||||
Migration: use `useSubEnv` instead of writing directly to the env. Also, note
|
|
||||||
that the environment given to the App can initially contain anything.
|
|
||||||
|
|
||||||
### 29. `t-ref` does not work on component
|
|
||||||
|
|
||||||
Before, `t-ref` could be used to get a reference to a child component. It no
|
|
||||||
longer works.
|
|
||||||
|
|
||||||
Rationale: the possibility of having a ref to a child component breaks the
|
|
||||||
encapsulation provided by Owl components: a child component now has a private
|
|
||||||
and a public interface. Another issue is that it may be unclear when the ref
|
|
||||||
should be set: is the component active on setup, or on mounted? Also, it is
|
|
||||||
kind of awkward to implement.
|
|
||||||
|
|
||||||
Migration: the `env` and `props` should provide a communication channel wide enough:
|
|
||||||
the sub component can expose its public API by calling a callback at the proper
|
|
||||||
timing, or by triggering an event.
|
|
||||||
|
|
||||||
### 30. `t-on` does not accept expressions, only functions
|
|
||||||
|
|
||||||
In Owl 1, it was possible to define simple expressions inline, in a template:
|
|
||||||
|
|
||||||
```xml
|
|
||||||
<button t-on-click="state.value = state.value + 1">blabla</button>
|
|
||||||
<button t-on-click="someFunction(someVar)">blabla</button>
|
|
||||||
```
|
|
||||||
|
|
||||||
This does not work anymore. Now, the `t-on` directive assumes that what it get is
|
|
||||||
a function.
|
|
||||||
|
|
||||||
Rationale: the fact that owl 1 had to support expressions meant that it was not
|
|
||||||
possible to properly inject the event in general. With this restriction, Owl 2
|
|
||||||
can support more general use cases. Also, the examples above can simply be
|
|
||||||
wrapped in a lambda function.
|
|
||||||
|
|
||||||
Migration: use lambda functions. For example, the two examples above can be
|
|
||||||
adapted like this:
|
|
||||||
|
|
||||||
```xml
|
|
||||||
<button t-on-click="() => state.value = state.value + 1">blabla</button>
|
|
||||||
<button t-on-click="() => this.someFunction(someVar)">blabla</button>
|
|
||||||
```
|
|
||||||
|
|
||||||
### 31. components can now have arbitrary content
|
|
||||||
|
|
||||||
Before Owl 2, components had to limit themselves to one single htmlelement as
|
|
||||||
root. Now, the content is arbitrary: it can be empty, or multiple html elements.
|
|
||||||
So, the following template works for components:
|
|
||||||
|
|
||||||
```xml
|
|
||||||
<div>1</div>
|
|
||||||
<div>2</div>
|
|
||||||
hello
|
|
||||||
```
|
|
||||||
@@ -16,6 +16,7 @@ simple and consistent way. Owl's main features are:
|
|||||||
- a declarative component system,
|
- a declarative component system,
|
||||||
- a reactivity system based on hooks,
|
- a reactivity system based on hooks,
|
||||||
- concurrent mode by default,
|
- concurrent mode by default,
|
||||||
|
- a store and a frontend router
|
||||||
|
|
||||||
Owl components are defined with ES6 classes, they use QWeb templates, an
|
Owl components are defined with ES6 classes, they use QWeb templates, an
|
||||||
underlying virtual DOM, integrates beautifully with hooks, and the rendering is
|
underlying virtual DOM, integrates beautifully with hooks, and the rendering is
|
||||||
@@ -44,7 +45,7 @@ find some more additional information [here](doc/miscellaneous/comparison.md).
|
|||||||
Here is a short example to illustrate interactive components:
|
Here is a short example to illustrate interactive components:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const { Component, useState, mount } = owl;
|
const { Component, useState } = owl;
|
||||||
const { xml } = owl.tags;
|
const { xml } = owl.tags;
|
||||||
|
|
||||||
class Counter extends Component {
|
class Counter extends Component {
|
||||||
@@ -66,7 +67,8 @@ class App extends Component {
|
|||||||
static components = { Counter };
|
static components = { Counter };
|
||||||
}
|
}
|
||||||
|
|
||||||
mount(App, { target: document.body });
|
const app = new App();
|
||||||
|
app.mount(document.body);
|
||||||
```
|
```
|
||||||
|
|
||||||
Note that the counter component is made reactive with the [`useState` hook](doc/reference/hooks.md#usestate).
|
Note that the counter component is made reactive with the [`useState` hook](doc/reference/hooks.md#usestate).
|
||||||
@@ -123,7 +125,7 @@ npm install @odoo/owl
|
|||||||
|
|
||||||
If you want to use a simple `<script>` tag, the last release can be downloaded here:
|
If you want to use a simple `<script>` tag, the last release can be downloaded here:
|
||||||
|
|
||||||
- [owl-1.4.7](https://github.com/odoo/owl/releases/tag/v1.4.7)
|
- [owl-1.0.13](https://github.com/odoo/owl/releases/tag/v1.0.13)
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
# 🦉 How to debug Owl applications 🦉
|
||||||
|
|
||||||
|
Non trivial applications become quickly more difficult to understand. It is then
|
||||||
|
useful to have a solid understanding of what is going on. To help with that,
|
||||||
|
logging useful information is extremely valuable. There is a [javascript file](../../tools/debug.js) which can be evaluated in an application.
|
||||||
|
|
||||||
|
Once it is executed, it will log a lot of information on each component main hooks. The following code is a minified version to make it easier to copy/paste:
|
||||||
|
|
||||||
|
```
|
||||||
|
function debugOwl(t,e){let n,o="[OWL_DEBUG]";function r(t){let e;try{e=JSON.stringify(t||{})}catch(t){e="<JSON error>"}return e.length>200&&(e=e.slice(0,200)+"..."),e}if(Object.defineProperty(t.Component,"current",{get:()=>n,set(s){n=s;const i=s.constructor.name;if(e.componentBlackList&&e.componentBlackList.test(i))return;if(e.componentWhiteList&&!e.componentWhiteList.test(i))return;let l;Object.defineProperty(n,"__owl__",{get:()=>l,set(n){!function(n,s,i){let l=`${s}<id=${i}>`,c=t=>console.log(`${o} ${l} ${t}`),u=t=>(!e.methodBlackList||!e.methodBlackList.includes(t))&&!(e.methodWhiteList&&!e.methodWhiteList.includes(t));u("constructor")&&c(`constructor, props=${r(n.props)}`);u("willStart")&&t.hooks.onWillStart(()=>{c("willStart")});u("mounted")&&t.hooks.onMounted(()=>{c("mounted")});u("willUpdateProps")&&t.hooks.onWillUpdateProps(t=>{c(`willUpdateProps, nextprops=${r(t)}`)});u("willPatch")&&t.hooks.onWillPatch(()=>{c("willPatch")});u("patched")&&t.hooks.onPatched(()=>{c("patched")});u("willUnmount")&&t.hooks.onWillUnmount(()=>{c("willUnmount")});const d=n.__render.bind(n);n.__render=function(...t){c("rendering template"),d(...t)};const h=n.render.bind(n);n.render=function(...t){const e=n.__owl__;let o="render";return e.isMounted||e.currentFiber||(o+=" (warning: component is not mounted, this render has no effect)"),c(o),h(...t)};const p=n.mount.bind(n);n.mount=function(...t){return c("mount"),p(...t)}}(s,i,(l=n).id)}})}}),e.logScheduler){let e=t.Component.scheduler.start,n=t.Component.scheduler.stop;t.Component.scheduler.start=function(){this.isRunning||console.log(`${o} scheduler: start running tasks queue`),e.call(this)},t.Component.scheduler.stop=function(){this.isRunning&&console.log(`${o} scheduler: stop running tasks queue`),n.call(this)}}if(e.logStore){let e=t.Store.prototype.dispatch;t.Store.prototype.dispatch=function(t,...n){return console.log(`${o} store: action '${t}' dispatched. Payload: '${r(n)}'`),e.call(this,t,...n)}}}
|
||||||
|
debugOwl(owl, {
|
||||||
|
// componentBlackList: /App/, // regexp
|
||||||
|
// componentWhiteList: /SomeComponent/, // regexp
|
||||||
|
// methodBlackList: ["mounted"], // list of method names
|
||||||
|
// methodWhiteList: ["willStart"], // list of method names
|
||||||
|
logScheduler: false, // display/mute scheduler logs
|
||||||
|
logStore: true, // display/mute store logs
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
The above code, once pasted somewhere in the main javascript file of an owl
|
||||||
|
application, will log information looking like this:
|
||||||
|
|
||||||
|
```
|
||||||
|
[OWL_DEBUG] TodoApp<id=1> constructor, props={}
|
||||||
|
[OWL_DEBUG] TodoApp<id=1> mount
|
||||||
|
[OWL_DEBUG] TodoApp<id=1> willStart
|
||||||
|
[OWL_DEBUG] TodoApp<id=1> rendering template
|
||||||
|
[OWL_DEBUG] TodoItem<id=2> constructor, props={"id":2,"completed":false,"title":"hey"}
|
||||||
|
[OWL_DEBUG] TodoItem<id=2> willStart
|
||||||
|
[OWL_DEBUG] TodoItem<id=3> constructor, props={"id":4,"completed":false,"title":"aaa"}
|
||||||
|
[OWL_DEBUG] TodoItem<id=3> willStart
|
||||||
|
[OWL_DEBUG] TodoItem<id=2> rendering template
|
||||||
|
[OWL_DEBUG] TodoItem<id=3> rendering template
|
||||||
|
[OWL_DEBUG] TodoItem<id=3> mounted
|
||||||
|
[OWL_DEBUG] TodoItem<id=2> mounted
|
||||||
|
[OWL_DEBUG] TodoApp<id=1> mounted
|
||||||
|
```
|
||||||
|
|
||||||
|
Each component has an internal `id`, which is very useful when debugging.
|
||||||
|
|
||||||
|
Note that it is certainly useful to run this code at some point in an application,
|
||||||
|
just to get a feel of what each user action implies, for the framework.
|
||||||
@@ -85,7 +85,8 @@ afterEach(() => {
|
|||||||
describe("SomeComponent", () => {
|
describe("SomeComponent", () => {
|
||||||
test("component behaves as expected", async () => {
|
test("component behaves as expected", async () => {
|
||||||
const props = {...}; // depends on the component
|
const props = {...}; // depends on the component
|
||||||
const comp = await mount(SomeComponent, { target: fixture, props });
|
const comp = new SomeComponent(null, props);
|
||||||
|
await comp.mount(fixture);
|
||||||
|
|
||||||
// do some assertions
|
// do some assertions
|
||||||
expect(...).toBe(...);
|
expect(...).toBe(...);
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ class OrderLine extends Component {
|
|||||||
</div>`;
|
</div>`;
|
||||||
|
|
||||||
add() {
|
add() {
|
||||||
this.trigger("add-to-order", { line: this.props.line });
|
this.trigger("add-to-order", { line: props.line });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ Now, `index.html` should contain the following:
|
|||||||
And `app.js` should look like this:
|
And `app.js` should look like this:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const { Component, mount } = owl;
|
const { Component } = owl;
|
||||||
const { xml } = owl.tags;
|
const { xml } = owl.tags;
|
||||||
const { whenReady } = owl.utils;
|
const { whenReady } = owl.utils;
|
||||||
|
|
||||||
@@ -65,7 +65,8 @@ class App extends Component {
|
|||||||
|
|
||||||
// Setup code
|
// Setup code
|
||||||
function setup() {
|
function setup() {
|
||||||
mount(App, target: { document.body })
|
const app = new App();
|
||||||
|
app.mount(document.body);
|
||||||
}
|
}
|
||||||
|
|
||||||
whenReady(setup);
|
whenReady(setup);
|
||||||
@@ -123,7 +124,7 @@ Here is the content of `app.js` and `main.js`:
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
// app.js ----------------------------------------------------------------------
|
// app.js ----------------------------------------------------------------------
|
||||||
const { Component, mount } = owl;
|
const { Component } = owl;
|
||||||
const { xml } = owl.tags;
|
const { xml } = owl.tags;
|
||||||
|
|
||||||
export class App extends Component {
|
export class App extends Component {
|
||||||
@@ -134,7 +135,8 @@ export class App extends Component {
|
|||||||
import { App } from "./app.js";
|
import { App } from "./app.js";
|
||||||
|
|
||||||
function setup() {
|
function setup() {
|
||||||
mount(App, { target: document.body });
|
const app = new App();
|
||||||
|
app.mount(document.body);
|
||||||
}
|
}
|
||||||
|
|
||||||
owl.utils.whenReady(setup);
|
owl.utils.whenReady(setup);
|
||||||
@@ -238,11 +240,12 @@ export class App extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// src/main.js -----------------------------------------------------------------
|
// src/main.js -----------------------------------------------------------------
|
||||||
import { utils, mount } from "@odoo/owl";
|
import { utils } from "@odoo/owl";
|
||||||
import { App } from "./components/App";
|
import { App } from "./components/App";
|
||||||
|
|
||||||
function setup() {
|
function setup() {
|
||||||
mount(App, { target: document.body });
|
const app = new App();
|
||||||
|
app.mount(document.body);
|
||||||
}
|
}
|
||||||
|
|
||||||
utils.whenReady(setup);
|
utils.whenReady(setup);
|
||||||
@@ -250,7 +253,6 @@ utils.whenReady(setup);
|
|||||||
// tests/components/App.test.js ------------------------------------------------
|
// tests/components/App.test.js ------------------------------------------------
|
||||||
import { App } from "../../src/components/App";
|
import { App } from "../../src/components/App";
|
||||||
import { makeTestFixture, nextTick, click } from "../helpers";
|
import { makeTestFixture, nextTick, click } from "../helpers";
|
||||||
import { mount } from "@odoo/owl";
|
|
||||||
|
|
||||||
let fixture;
|
let fixture;
|
||||||
|
|
||||||
@@ -264,7 +266,8 @@ afterEach(() => {
|
|||||||
|
|
||||||
describe("App", () => {
|
describe("App", () => {
|
||||||
test("Works as expected...", async () => {
|
test("Works as expected...", async () => {
|
||||||
await mount(App, { target: fixture });
|
const app = new App();
|
||||||
|
await app.mount(fixture);
|
||||||
expect(fixture.innerHTML).toBe("<div>Hello Owl</div>");
|
expect(fixture.innerHTML).toBe("<div>Hello Owl</div>");
|
||||||
|
|
||||||
click(fixture, "div");
|
click(fixture, "div");
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ a single root component. Let us start by defining an `App` component. Replace th
|
|||||||
content of the function in `app.js` by the following code:
|
content of the function in `app.js` by the following code:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const { Component, mount } = owl;
|
const { Component } = owl;
|
||||||
const { xml } = owl.tags;
|
const { xml } = owl.tags;
|
||||||
const { whenReady } = owl.utils;
|
const { whenReady } = owl.utils;
|
||||||
|
|
||||||
@@ -96,7 +96,8 @@ class App extends Component {
|
|||||||
|
|
||||||
// Setup code
|
// Setup code
|
||||||
function setup() {
|
function setup() {
|
||||||
mount(App, { target: document.body });
|
const app = new App();
|
||||||
|
app.mount(document.body);
|
||||||
}
|
}
|
||||||
|
|
||||||
whenReady(setup);
|
whenReady(setup);
|
||||||
@@ -280,7 +281,8 @@ class App extends Component {
|
|||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
function setup() {
|
function setup() {
|
||||||
owl.config.mode = "dev";
|
owl.config.mode = "dev";
|
||||||
mount(App, { target: document.body });
|
const app = new App();
|
||||||
|
app.mount(document.body);
|
||||||
}
|
}
|
||||||
|
|
||||||
whenReady(setup);
|
whenReady(setup);
|
||||||
@@ -547,7 +549,7 @@ application), since it involves extracting all task related code out of the
|
|||||||
components. Here is the new content of the `app.js` file:
|
components. Here is the new content of the `app.js` file:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const { Component, Store, mount } = owl;
|
const { Component, Store } = owl;
|
||||||
const { xml } = owl.tags;
|
const { xml } = owl.tags;
|
||||||
const { whenReady } = owl.utils;
|
const { whenReady } = owl.utils;
|
||||||
const { useRef, useDispatch, useStore } = owl.hooks;
|
const { useRef, useDispatch, useStore } = owl.hooks;
|
||||||
@@ -639,7 +641,8 @@ function setup() {
|
|||||||
owl.config.mode = "dev";
|
owl.config.mode = "dev";
|
||||||
const store = new Store({ actions, state: initialState });
|
const store = new Store({ actions, state: initialState });
|
||||||
App.env.store = store;
|
App.env.store = store;
|
||||||
mount(App, { target: document.body });
|
const app = new App();
|
||||||
|
app.mount(document.body);
|
||||||
}
|
}
|
||||||
|
|
||||||
whenReady(setup);
|
whenReady(setup);
|
||||||
@@ -665,8 +668,9 @@ function makeStore() {
|
|||||||
|
|
||||||
function setup() {
|
function setup() {
|
||||||
owl.config.mode = "dev";
|
owl.config.mode = "dev";
|
||||||
const env = { store: makeStore() };
|
App.env.store = makeStore();
|
||||||
mount(App, { target: document.body, env });
|
const app = new App();
|
||||||
|
app.mount(document.body);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -810,7 +814,7 @@ For reference, here is the final code:
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
(function () {
|
(function () {
|
||||||
const { Component, Store, mount } = owl;
|
const { Component, Store } = owl;
|
||||||
const { xml } = owl.tags;
|
const { xml } = owl.tags;
|
||||||
const { whenReady } = owl.utils;
|
const { whenReady } = owl.utils;
|
||||||
const { useRef, useDispatch, useState, useStore } = owl.hooks;
|
const { useRef, useDispatch, useState, useStore } = owl.hooks;
|
||||||
@@ -941,8 +945,9 @@ For reference, here is the final code:
|
|||||||
|
|
||||||
function setup() {
|
function setup() {
|
||||||
owl.config.mode = "dev";
|
owl.config.mode = "dev";
|
||||||
const env = { store: makeStore() };
|
App.env.store = makeStore();
|
||||||
mount(App, { target: document.body, env });
|
const app = new App();
|
||||||
|
app.mount(document.body);
|
||||||
}
|
}
|
||||||
|
|
||||||
whenReady(setup);
|
whenReady(setup);
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ OWL, React and Vue have the same main feature: they allow developers to build
|
|||||||
declarative user interfaces. To do that, all these frameworks uses a virtual dom. However, there are still obviously many differences.
|
declarative user interfaces. To do that, all these frameworks uses a virtual dom. However, there are still obviously many differences.
|
||||||
|
|
||||||
In this page, we try to highlight some of these differences. Obviously, a lot of
|
In this page, we try to highlight some of these differences. Obviously, a lot of
|
||||||
effort was put to be fair. However, if you disagree with some of the points
|
effort was done to be fair. However, if you disagree with some of the points
|
||||||
discussed, feel free to open an issue/submit a PR to correct this text.
|
discussed, feel free to open an issue/submit a PR to correct this text.
|
||||||
|
|
||||||
## Content
|
## Content
|
||||||
@@ -47,7 +47,7 @@ components are fast enough for all our usecases, and making it as simple as
|
|||||||
possible for developers is more valuable (for us).
|
possible for developers is more valuable (for us).
|
||||||
|
|
||||||
Also, functions or class based components are more than just syntax. Functions
|
Also, functions or class based components are more than just syntax. Functions
|
||||||
come with a mindset of composition and class are about inheritance. Clearly,
|
comes with a mindset of composition and class are about inheritance. Clearly,
|
||||||
both of these are important mechanisms for reusing code. Also, one does not
|
both of these are important mechanisms for reusing code. Also, one does not
|
||||||
exclude the other.
|
exclude the other.
|
||||||
|
|
||||||
@@ -189,6 +189,95 @@ with a `Proxy`, which means that it is totally transparent to the developers.
|
|||||||
Adding new keys is supported. Once any part of the state has been changed, a
|
Adding new keys is supported. Once any part of the state has been changed, a
|
||||||
rendering is scheduled in the next microtask tick (promise queue).
|
rendering is scheduled in the next microtask tick (promise queue).
|
||||||
|
|
||||||
|
## State Management
|
||||||
|
|
||||||
|
Managing the state of an application is a tricky issue. Many solutions have
|
||||||
|
been proposed these last few years. It also depends on the kind of application we
|
||||||
|
are talking about. A small application may not need much more than a simple
|
||||||
|
object to contain its state.
|
||||||
|
|
||||||
|
However, there are some common solutions for React and Vue: redux and vuex.
|
||||||
|
Both of them are a centralized store that own the state, and they dictate how
|
||||||
|
the state can be mutated.
|
||||||
|
|
||||||
|
**Redux**
|
||||||
|
|
||||||
|
In Redux, the state is mutated by reducers. Reducers are functions
|
||||||
|
that modify the state by returning a different object:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
...
|
||||||
|
switch (action.type) {
|
||||||
|
case ADD_TODO: {
|
||||||
|
const { id, content } = action.payload;
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
allIds: [...state.allIds, id],
|
||||||
|
byIds: {
|
||||||
|
...state.byIds,
|
||||||
|
[id]: {
|
||||||
|
content,
|
||||||
|
completed: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
This is a little bit awkward to write, but this allows the component system to
|
||||||
|
check if a part of the state was changed. This is exactly what is done by the
|
||||||
|
`connect` function: it create a _connected_ component, which is subscribed to
|
||||||
|
the state and triggers a rerender if some part of the state was modified.
|
||||||
|
|
||||||
|
**VueX**
|
||||||
|
|
||||||
|
VueX is based on a different principle: the state is mutated through
|
||||||
|
some special functions (the mutations), which modify the state in place:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
function ({state}, payload) {
|
||||||
|
const { id, content } = payload;
|
||||||
|
const message = {id, content, completed: false};
|
||||||
|
state.messages.push(message)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
This is simpler, but there is a little bit more happening behind the scene:
|
||||||
|
each key from the state is silently replaced by getters and setters, and VueX
|
||||||
|
keeps track of who get data, and retrigger a render when it was changed.
|
||||||
|
|
||||||
|
**Owl**
|
||||||
|
|
||||||
|
Owl store is a little bit like a mix of redux and vuex: it has actions (but not
|
||||||
|
mutations), and like VueX, it keeps track of the state changes. However, it does
|
||||||
|
not notify a component when the state changes. Instead, components need to connect
|
||||||
|
to the store like in redux, with the `useStore` hook (see the [store documentation](../reference/store.md#connecting-a-component)).
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const actions = {
|
||||||
|
increment({ state }, val) {
|
||||||
|
state.counter.value += val;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const state = {
|
||||||
|
counter: { value: 0 },
|
||||||
|
};
|
||||||
|
const store = new owl.Store({ state, actions });
|
||||||
|
|
||||||
|
class Counter extends Component {
|
||||||
|
static template = xml`
|
||||||
|
<button t-name="Counter" t-on-click="dispatch('increment')">
|
||||||
|
Click Me! [<t t-esc="counter.value"/>]
|
||||||
|
</button>`;
|
||||||
|
counter = useStore((state) => state.counter);
|
||||||
|
dispatch = useDispatch();
|
||||||
|
}
|
||||||
|
|
||||||
|
Counter.env.store = store;
|
||||||
|
const counter = new Counter();
|
||||||
|
```
|
||||||
|
|
||||||
## Hooks
|
## Hooks
|
||||||
|
|
||||||
[Hooks](https://reactjs.org/docs/hooks-intro.html#motivation) recently took over
|
[Hooks](https://reactjs.org/docs/hooks-intro.html#motivation) recently took over
|
||||||
@@ -253,4 +342,4 @@ class Example extends Component {
|
|||||||
|
|
||||||
Since the Owl framework had hooks from early in its life, its main APIs
|
Since the Owl framework had hooks from early in its life, its main APIs
|
||||||
are designed to be interacted with hooks from the start. For example, the
|
are designed to be interacted with hooks from the start. For example, the
|
||||||
`Context` abstraction.
|
`Context` and `Store` abstractions.
|
||||||
|
|||||||
@@ -61,14 +61,14 @@ because a lot of the state is hidden in their internals.
|
|||||||
|
|
||||||
React or Vue have a huge community, and a lot of effort have been made into their
|
React or Vue have a huge community, and a lot of effort have been made into their
|
||||||
tooling. This is wonderful, but at the same time, a pretty big issue for Odoo:
|
tooling. This is wonderful, but at the same time, a pretty big issue for Odoo:
|
||||||
since the assets are totally dynamic (and could change whenever the user installs
|
since the assets are totally dynamic (and could change whenever the user install
|
||||||
or removes an addon), we need to have all that kind of tooling on the production
|
or remove an addon), we need to have all that kind of tooling on the production
|
||||||
servers. This is certainly not ideal.
|
servers. This is certainly not ideal.
|
||||||
|
|
||||||
Also, this makes it very complicated to setup Vue or React tools: Odoo code is
|
Also, this makes it very complicated to setup Vue or React tools: Odoo code is
|
||||||
not a simple file that import other files. It changes all the time, assets
|
not a simple file that import other files. It changes all the time, assets
|
||||||
are bundled differently in different contexts. This is the reason why Odoo has
|
are bundled differently in different contexts. This is the reason why Odoo has
|
||||||
its own module system, which are resolved at runtime, by the browser. The
|
its own module system, which are resolve at runtime, by the browser. The
|
||||||
dynamic nature of Odoo means that we often need to delay work as late as possible
|
dynamic nature of Odoo means that we often need to delay work as late as possible
|
||||||
(in other word, we want a JIT user interface!)
|
(in other word, we want a JIT user interface!)
|
||||||
|
|
||||||
@@ -78,12 +78,12 @@ deploy. Using React without JSX, or Vue without vue file is not very appealing.
|
|||||||
At the same time, Owl is designed to solve this issue: it compiles templates
|
At the same time, Owl is designed to solve this issue: it compiles templates
|
||||||
by the browser, it doesn't need much code for that, since we use the XML parser
|
by the browser, it doesn't need much code for that, since we use the XML parser
|
||||||
built into each browser. Owl works with or without any additional tooling. It
|
built into each browser. Owl works with or without any additional tooling. It
|
||||||
can use template strings to write single file components, and is easy to integrate
|
can use template strings to write single file component, and is easy to integrate
|
||||||
in any html page, with a simple `<script>` tag.
|
in any html page, with a simple `<script>` tag.
|
||||||
|
|
||||||
## Template based
|
## Template based
|
||||||
|
|
||||||
Odoo stores templates as XML documents in a database. This is very powerful, since
|
Odoo stores template as XML document in a database. This is very powerful, since
|
||||||
this allow the use of xpaths to customize other templates. This is a very
|
this allow the use of xpaths to customize other templates. This is a very
|
||||||
important feature of odoo, and one of the key to Odoo modularity.
|
important feature of odoo, and one of the key to Odoo modularity.
|
||||||
|
|
||||||
@@ -104,12 +104,12 @@ awkward, and very confusing.
|
|||||||
## Developer Experience
|
## Developer Experience
|
||||||
|
|
||||||
This brings us to the following point: developer experience. We see this choice
|
This brings us to the following point: developer experience. We see this choice
|
||||||
as an investment for the future, and we want to make onboarding developers as
|
as an investment for the future, and we want to make onboarding developer as
|
||||||
easy as possible.
|
easy as possible.
|
||||||
|
|
||||||
While many javascript professionals clearly think that react/vue is not difficult
|
While many javascript professionals clearly think that react/vue is not difficult
|
||||||
(which is true to some extent), it is alsy true that many non js specialists are
|
(which is true to some extent), it is alsy true that many non js specialists are
|
||||||
overwhelmed with the frontend world: functional components, hooks, and many other
|
overwhelmed with the frontend world: functional component, hooks, and many other
|
||||||
fancy words. Also, what is available in the compilation context may be difficult,
|
fancy words. Also, what is available in the compilation context may be difficult,
|
||||||
there is a lot of black magic going on in pretty much every framework. Vue
|
there is a lot of black magic going on in pretty much every framework. Vue
|
||||||
somehow join various namespaces into one, under the hood, and add various internal
|
somehow join various namespaces into one, under the hood, and add various internal
|
||||||
@@ -135,7 +135,7 @@ needs: Odoo will fetch templates from the database and need to compile them only
|
|||||||
at the last possible moment, so we can apply all necessary xpaths.
|
at the last possible moment, so we can apply all necessary xpaths.
|
||||||
|
|
||||||
Even more: Odoo needs to be able to generate (and compile) templates at runtime.
|
Even more: Odoo needs to be able to generate (and compile) templates at runtime.
|
||||||
Currently, Odoo form views interpret an xml description. But the form view code
|
Currently, Odoo form views interpret a xml description. But the form view code
|
||||||
then needs to do a lot of complicated operations. With Owl, we will be able to
|
then needs to do a lot of complicated operations. With Owl, we will be able to
|
||||||
transform a view description into a QWeb template, then compile that and use it
|
transform a view description into a QWeb template, then compile that and use it
|
||||||
immediately.
|
immediately.
|
||||||
@@ -147,16 +147,16 @@ For example, the reactivity system. We like the way Vue did it, but it has a
|
|||||||
flaw: it is not really optional. There is actually a way to opt out of the reactivity
|
flaw: it is not really optional. There is actually a way to opt out of the reactivity
|
||||||
system by freezing the state, but then, it is freezed.
|
system by freezing the state, but then, it is freezed.
|
||||||
|
|
||||||
And there certainly are situations where we need a state, which is not read-only,
|
And there certainly are situations where we need a state, which is not readonly,
|
||||||
and not observed. For example, imagine a spreadsheet component. It may have a
|
and not observed. For example, imagine a spreadsheet component. It may have a
|
||||||
very large internal state, and it knows exactly when it needs to be rendered
|
very large internal state, and it knows exactly when it needs to be rendered
|
||||||
(basically, whenever the user performs some action). Then, observing its state
|
(basically, whenever the user perform some action). Then, observing its state
|
||||||
is a net performance loss, both for the CPU and the memory.
|
is a net performance loss, both for the CPU and the memory.
|
||||||
|
|
||||||
## Concurrency
|
## Concurrency
|
||||||
|
|
||||||
Many applications are happy to simply display a spinner whenever a new asynchronous
|
Many applications are happy to simply display a spinner whenever a new asynchronous
|
||||||
action is performed, but Odoo wants a different user experience: most asynchronous
|
action is performed, but Odoo want a different user experience: most asynchronous
|
||||||
state changes are not displayed until ready. This is sometimes called a concurrent
|
state changes are not displayed until ready. This is sometimes called a concurrent
|
||||||
mode: the UI is rendered in memory, and displayed only when it is ready (and
|
mode: the UI is rendered in memory, and displayed only when it is ready (and
|
||||||
only if it has not been cancelled by subsequent user actions).
|
only if it has not been cancelled by subsequent user actions).
|
||||||
@@ -175,6 +175,6 @@ that current standard frameworks are not tailored to our needs. It is perfectly
|
|||||||
fine, because they each chose a different set of tradeoffs.
|
fine, because they each chose a different set of tradeoffs.
|
||||||
|
|
||||||
However, we feel that there is still room in the framework world for something
|
However, we feel that there is still room in the framework world for something
|
||||||
that is different. For a framework that makes choices compatible with Odoo.
|
that is different. For a framework that make choices compatible with Odoo.
|
||||||
|
|
||||||
And that is why we built Owl 🦉.
|
And that is why we built Owl 🦉.
|
||||||
|
|||||||
+3
-2
@@ -9,6 +9,7 @@ Are you new to Owl? This is the place to start!
|
|||||||
- [How to start an Owl project](learning/quick_start.md)
|
- [How to start an Owl project](learning/quick_start.md)
|
||||||
- [How to test Components](learning/how_to_test.md)
|
- [How to test Components](learning/how_to_test.md)
|
||||||
- [How to write Single File Components](learning/how_to_write_sfc.md)
|
- [How to write Single File Components](learning/how_to_write_sfc.md)
|
||||||
|
- [How to write debug Owl applications](learning/how_to_debug.md)
|
||||||
|
|
||||||
## Reference
|
## Reference
|
||||||
|
|
||||||
@@ -16,7 +17,6 @@ You will find here a complete reference of every feature, class or object
|
|||||||
provided by Owl.
|
provided by Owl.
|
||||||
|
|
||||||
- [Animations](reference/animations.md)
|
- [Animations](reference/animations.md)
|
||||||
- [Browser](reference/browser.md)
|
|
||||||
- [Component](reference/component.md)
|
- [Component](reference/component.md)
|
||||||
- [Content](reference/content.md)
|
- [Content](reference/content.md)
|
||||||
- [Concurrency Model](reference/concurrency_model.md)
|
- [Concurrency Model](reference/concurrency_model.md)
|
||||||
@@ -27,13 +27,14 @@ provided by Owl.
|
|||||||
- [Event Handling](reference/event_handling.md)
|
- [Event Handling](reference/event_handling.md)
|
||||||
- [Error Handling](reference/error_handling.md)
|
- [Error Handling](reference/error_handling.md)
|
||||||
- [Hooks](reference/hooks.md)
|
- [Hooks](reference/hooks.md)
|
||||||
- [Mounting a component](reference/mounting.md)
|
|
||||||
- [Miscellaneous Components](reference/misc.md)
|
- [Miscellaneous Components](reference/misc.md)
|
||||||
- [Observer](reference/observer.md)
|
- [Observer](reference/observer.md)
|
||||||
- [Props](reference/props.md)
|
- [Props](reference/props.md)
|
||||||
- [Props Validation](reference/props_validation.md)
|
- [Props Validation](reference/props_validation.md)
|
||||||
- [QWeb Templating Language](reference/qweb_templating_language.md)
|
- [QWeb Templating Language](reference/qweb_templating_language.md)
|
||||||
- [QWeb Engine](reference/qweb_engine.md)
|
- [QWeb Engine](reference/qweb_engine.md)
|
||||||
|
- [Router](reference/router.md)
|
||||||
|
- [Store](reference/store.md)
|
||||||
- [Slots](reference/slots.md)
|
- [Slots](reference/slots.md)
|
||||||
- [Tags](reference/tags.md)
|
- [Tags](reference/tags.md)
|
||||||
- [Utils](reference/utils.md)
|
- [Utils](reference/utils.md)
|
||||||
|
|||||||
@@ -52,20 +52,21 @@ sequence of events will happen:
|
|||||||
At node insertion:
|
At node insertion:
|
||||||
|
|
||||||
- the css classes `name-enter` and `name-enter-active` will be added directly
|
- the css classes `name-enter` and `name-enter-active` will be added directly
|
||||||
when the node is inserted into the DOM.
|
when the node is inserted into the DOM,
|
||||||
- on the next animation frame: the css class `name-enter` will be removed and the
|
- on the next animation frame: the css class `name-enter` will be removed and the
|
||||||
class `name-enter-to` will be added (so they can be used to trigger css
|
class `name-enter-to` will be added (so they can be used to trigger css
|
||||||
transition effects).
|
transition effects),
|
||||||
- at the end of the transition, `name-enter-to` and `name-enter-active` will be removed.
|
- the css class `name-enter-active` will be removed whenever a css transition
|
||||||
|
ends.
|
||||||
|
|
||||||
At node destruction:
|
At node destruction:
|
||||||
|
|
||||||
- the css classes `name-leave` and `name-leave-active` will be added before the
|
- the css classes `name-leave` and `name-leave-active` will be added before the
|
||||||
node is removed to the DOM.
|
node is removed to the DOM,
|
||||||
- on the next animation frame: the css class `name-leave` will be removed and the
|
- the css class `name-leave` will be removed on the next animation frame (so it
|
||||||
class `name-leave-to` will be added (so they can be used to trigger css
|
can be used to trigger css transition effects),
|
||||||
transition effects).
|
- the css class `name-leave-active` will be removed whenever a css transition
|
||||||
- at the end of the transition, `name-leave-to` and `name-leave-active` will be removed.
|
ends. Only then will the element be removed from the DOM.
|
||||||
|
|
||||||
For example, a simple fade in/out effect can be done with this:
|
For example, a simple fade in/out effect can be done with this:
|
||||||
|
|
||||||
@@ -92,36 +93,3 @@ Notes:
|
|||||||
|
|
||||||
Owl does not support more than one transition on a single node, so the
|
Owl does not support more than one transition on a single node, so the
|
||||||
`t-transition` expression must be a single value (i.e. no space allowed).
|
`t-transition` expression must be a single value (i.e. no space allowed).
|
||||||
|
|
||||||
## SCSS Mixins
|
|
||||||
|
|
||||||
If you use SCSS, you can use mixins to make generic animations. Here is an exemple with a fade in / fade out animation:
|
|
||||||
|
|
||||||
```scss
|
|
||||||
@mixin animation-fade($time, $name) {
|
|
||||||
.#{$name}_fade-enter-active,
|
|
||||||
.#{$name}_fade-active {
|
|
||||||
transition: all $time;
|
|
||||||
}
|
|
||||||
|
|
||||||
.#{$name}_fade-enter {
|
|
||||||
opacity: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.#{$name}_fade-leave-to {
|
|
||||||
opacity: 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Usage:
|
|
||||||
|
|
||||||
```scss
|
|
||||||
@include animation-fade(0.5s, "o_notification");
|
|
||||||
```
|
|
||||||
|
|
||||||
You can now have in your template:
|
|
||||||
|
|
||||||
```xml
|
|
||||||
<SomeTag t-transition="o_notification_fade"/>
|
|
||||||
```
|
|
||||||
|
|||||||
@@ -1,33 +0,0 @@
|
|||||||
# 🦉 Browser 🦉
|
|
||||||
|
|
||||||
## Content
|
|
||||||
|
|
||||||
- [Overview](#overview)
|
|
||||||
- [Browser Content](#browser-content)
|
|
||||||
|
|
||||||
## Overview
|
|
||||||
|
|
||||||
The browser object contains some browser native APIs, such as `setTimeout`, that
|
|
||||||
are used by Owl and its utility functions. They are exposed with the intent of
|
|
||||||
making them mockable if necessary.
|
|
||||||
|
|
||||||
```js
|
|
||||||
owl.browser.setTimeout === window.setTimeout; // return true
|
|
||||||
```
|
|
||||||
|
|
||||||
For now, this object contains some functions that are not used by Owl. They
|
|
||||||
will eventually be removed in Owl 2.0.
|
|
||||||
|
|
||||||
## Browser Content
|
|
||||||
|
|
||||||
More specifically, the `browser` object contains the following methods and objects:
|
|
||||||
|
|
||||||
- `setTimeout`
|
|
||||||
- `clearTimeout`
|
|
||||||
- `setInterval`
|
|
||||||
- `clearInterval`
|
|
||||||
- `requestAnimationFrame`
|
|
||||||
- `random`
|
|
||||||
- `Date`
|
|
||||||
- `fetch`
|
|
||||||
- `localStorage`
|
|
||||||
@@ -10,22 +10,13 @@
|
|||||||
- [Static Properties](#static-properties)
|
- [Static Properties](#static-properties)
|
||||||
- [Methods](#methods)
|
- [Methods](#methods)
|
||||||
- [Lifecycle](#lifecycle)
|
- [Lifecycle](#lifecycle)
|
||||||
- [`constructor(parent, props)`](#constructorparent-props)
|
|
||||||
- [`setup()`](#setup)
|
|
||||||
- [`willStart()`](#willstart)
|
|
||||||
- [`mounted()`](#mounted)
|
|
||||||
- [`willUpdateProps(nextProps)`](#willupdatepropsnextprops)
|
|
||||||
- [`willPatch()`](#willpatch)
|
|
||||||
- [`patched(snapshot)`](#patchedsnapshot)
|
|
||||||
- [`willUnmount()`](#willunmount)
|
|
||||||
- [`catchError(error)`](#catcherrorerror)
|
|
||||||
- [Root Component](#root-component)
|
- [Root Component](#root-component)
|
||||||
- [Composition](#composition)
|
- [Composition](#composition)
|
||||||
- [Form Input Bindings](#form-input-bindings)
|
- [Form Input Bindings](#form-input-bindings)
|
||||||
- [References](#references)
|
- [References](#references)
|
||||||
- [Dynamic sub components](#dynamic-sub-components)
|
- [Dynamic sub components](#dynamic-sub-components)
|
||||||
- [Functional Components](#functional-components)
|
- [Functional Components](#functional-components)
|
||||||
- [SVG Components](#svg-components)
|
- [SVG components](#svg-components)
|
||||||
|
|
||||||
## Overview
|
## Overview
|
||||||
|
|
||||||
@@ -263,7 +254,7 @@ We explain here all the public methods of the `Component` class.
|
|||||||
|
|
||||||
Note that if a component is mounted, unmounted and remounted, it will be
|
Note that if a component is mounted, unmounted and remounted, it will be
|
||||||
automatically re-rendered to ensure that changes in its state (or something
|
automatically re-rendered to ensure that changes in its state (or something
|
||||||
in the environment) will be taken into account.
|
in the environment, or in the store, or ...) will be taken into account.
|
||||||
|
|
||||||
If a component is mounted inside an element or a fragment which is not in the
|
If a component is mounted inside an element or a fragment which is not in the
|
||||||
DOM, then it will be rendered fully, but not active: the `mounted` hooks will
|
DOM, then it will be rendered fully, but not active: the `mounted` hooks will
|
||||||
@@ -279,10 +270,6 @@ We explain here all the public methods of the `Component` class.
|
|||||||
// app is now visible
|
// app is now visible
|
||||||
```
|
```
|
||||||
|
|
||||||
Note that the normal way of mounting an application is by using the `mount`
|
|
||||||
method on a component class, not by creating the instance by hand. See the
|
|
||||||
documentation on [mounting applications](mounting.md).
|
|
||||||
|
|
||||||
* **`unmount()`**: in case a component needs to be detached/removed from the DOM, this
|
* **`unmount()`**: in case a component needs to be detached/removed from the DOM, this
|
||||||
method can be used. Most applications should not call `unmount`, this is more
|
method can be used. Most applications should not call `unmount`, this is more
|
||||||
useful to the underlying component system.
|
useful to the underlying component system.
|
||||||
@@ -298,13 +285,8 @@ We explain here all the public methods of the `Component` class.
|
|||||||
are updated. It returns a boolean, which indicates if the component should
|
are updated. It returns a boolean, which indicates if the component should
|
||||||
ignore a props update. If it returns false, then `willUpdateProps` will not
|
ignore a props update. If it returns false, then `willUpdateProps` will not
|
||||||
be called, and no rendering will occur. Its default implementation is to
|
be called, and no rendering will occur. Its default implementation is to
|
||||||
always return true. Note that this is an optimization, similar to React's `shouldComponentUpdate`. Most of the time, this should not be used, but it
|
always return true. This is an optimization, similar to React's `shouldComponentUpdate`. Most of the time, this should not be used, but it
|
||||||
can be useful if we are handling large number of components. Since this is an
|
can be useful if we are handling large number of components.
|
||||||
optimization, Owl has the freedom to ignore the result of `shouldUpdate` in
|
|
||||||
some cases (for example, if a component is remounted, or if we want to force
|
|
||||||
a full rerender of the UI). However, if `shouldUpdate` returns true, then Owl
|
|
||||||
provides the guarantee that the component will be rendered at some point in
|
|
||||||
the future (except if the component is destroyed or if some part of the UI crashes).
|
|
||||||
|
|
||||||
* **`destroy()`**. As its name suggests, this method will remove the component,
|
* **`destroy()`**. As its name suggests, this method will remove the component,
|
||||||
and perform all necessary cleanup, such as unmounting the component, its children,
|
and perform all necessary cleanup, such as unmounting the component, its children,
|
||||||
@@ -325,7 +307,7 @@ a owl component:
|
|||||||
|
|
||||||
| Method | Description |
|
| Method | Description |
|
||||||
| ------------------------------------------------ | ----------------------------------------------------------- |
|
| ------------------------------------------------ | ----------------------------------------------------------- |
|
||||||
| **[setup](#setup)** | setup |
|
| **[constructor](#constructorparent-props)** | constructor |
|
||||||
| **[willStart](#willstart)** | async, before first rendering |
|
| **[willStart](#willstart)** | async, before first rendering |
|
||||||
| **[mounted](#mounted)** | just after component is rendered and added to the DOM |
|
| **[mounted](#mounted)** | just after component is rendered and added to the DOM |
|
||||||
| **[willUpdateProps](#willupdatepropsnextprops)** | async, before props update |
|
| **[willUpdateProps](#willupdatepropsnextprops)** | async, before props update |
|
||||||
@@ -370,23 +352,6 @@ class ClickCounter extends owl.Component {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Hook functions can be called in the constructor.
|
|
||||||
|
|
||||||
#### `setup()`
|
|
||||||
|
|
||||||
_setup_ is run just after the component is constructed. It is a lifecycle method,
|
|
||||||
very similar to the _constructor_, except that it does not receive any argument.
|
|
||||||
|
|
||||||
It is a valid method to call hook functions. Note that one of the main reason to
|
|
||||||
have the `setup` hook in the component lifecycle is to make it possible to
|
|
||||||
monkey patch it. It is a common need in the Odoo ecosystem.
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
setup() {
|
|
||||||
useSetupAutofocus();
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### `willStart()`
|
#### `willStart()`
|
||||||
|
|
||||||
willStart is an asynchronous hook that can be implemented to
|
willStart is an asynchronous hook that can be implemented to
|
||||||
@@ -789,7 +754,7 @@ template rendered with `props`. In Owl, this can be done by
|
|||||||
simply defining a template, that will access the `props` object:
|
simply defining a template, that will access the `props` object:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const Welcome = xml`<h1>Hello, <t t-esc="props.name"/></h1>`;
|
const Welcome = xml`<h1>Hello, {props.name}</h1>`;
|
||||||
|
|
||||||
class MyComponent extends Component {
|
class MyComponent extends Component {
|
||||||
static template = xml`
|
static template = xml`
|
||||||
|
|||||||
@@ -158,10 +158,12 @@ There are two different common problems with Owl asynchronous rendering model:
|
|||||||
Here are a few tips on how to work with asynchronous components:
|
Here are a few tips on how to work with asynchronous components:
|
||||||
|
|
||||||
1. Minimize the use of asynchronous components!
|
1. Minimize the use of asynchronous components!
|
||||||
2. Lazy loading external libraries is a good use case for async rendering. This
|
2. Maybe move the asynchronous logic in a store, which then triggers (mostly)
|
||||||
|
synchronous renderings
|
||||||
|
3. Lazy loading external libraries is a good use case for async rendering. This
|
||||||
is mostly fine, because we can assume that it will only takes a fraction of a
|
is mostly fine, because we can assume that it will only takes a fraction of a
|
||||||
second, and only once (see [`owl.utils.loadJS`](utils.md#loadjs))
|
second, and only once (see [`owl.utils.loadJS`](utils.md#loadjs))
|
||||||
3. For all the other cases, the [`AsyncRoot`](misc.md#asyncroot) component is there to help you. When
|
4. For all the other cases, the [`AsyncRoot`](misc.md#asyncroot) component is there to help you. When
|
||||||
this component is met, a new rendering
|
this component is met, a new rendering
|
||||||
sub tree is created, such that the rendering of that component (and its
|
sub tree is created, such that the rendering of that component (and its
|
||||||
children) is not tied to the rendering of the rest of the interface. It can
|
children) is not tied to the rendering of the rest of the interface. It can
|
||||||
|
|||||||
+17
-17
@@ -7,30 +7,30 @@ For example, `Component` is available at `owl.Component` and `EventBus` is
|
|||||||
exported as `owl.core.EventBus`.
|
exported as `owl.core.EventBus`.
|
||||||
|
|
||||||
```
|
```
|
||||||
browser
|
|
||||||
Component misc
|
Component misc
|
||||||
Context AsyncRoot
|
Context AsyncRoot
|
||||||
QWeb Portal
|
QWeb Portal
|
||||||
mount
|
Store router
|
||||||
useState tags
|
useState Link
|
||||||
config css
|
config RouteComponent
|
||||||
mode xml
|
mode Router
|
||||||
core utils
|
core tags
|
||||||
EventBus debounce
|
EventBus css
|
||||||
Observer escape
|
Observer xml
|
||||||
hooks loadJS
|
hooks utils
|
||||||
onWillStart loadFile
|
onWillStart debounce
|
||||||
onMounted shallowEqual
|
onMounted escape
|
||||||
onWillUpdateProps whenReady
|
onWillUpdateProps loadJS
|
||||||
onWillPatch
|
onWillPatch loadFile
|
||||||
onPatched
|
onPatched shallowEqual
|
||||||
onWillUnmount
|
onWillUnmount whenReady
|
||||||
useContext
|
useContext
|
||||||
useState
|
useState
|
||||||
useRef
|
useRef
|
||||||
useComponent
|
|
||||||
useEnv
|
|
||||||
useSubEnv
|
useSubEnv
|
||||||
|
useStore
|
||||||
|
useDispatch
|
||||||
|
useGetters
|
||||||
```
|
```
|
||||||
|
|
||||||
Note that for convenience, the `useState` hook is also exported at the root of the `owl` object.
|
Note that for convenience, the `useState` hook is also exported at the root of the `owl` object.
|
||||||
|
|||||||
@@ -49,14 +49,15 @@ The correct way to customize an environment is to simply set it up on the root
|
|||||||
component class, before the first component is created:
|
component class, before the first component is created:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const env = {
|
App.env = {
|
||||||
_t: myTranslateFunction,
|
_t: myTranslateFunction,
|
||||||
user: {...},
|
user: {...},
|
||||||
services: {
|
services: {
|
||||||
...
|
...
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
mount(App, { target: document.body, env });
|
const app = new App();
|
||||||
|
app.mount(document.body);
|
||||||
```
|
```
|
||||||
|
|
||||||
It is also possible to simply share an environment between all root components,
|
It is also possible to simply share an environment between all root components,
|
||||||
@@ -120,8 +121,9 @@ async function myEnv() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function start() {
|
async function start() {
|
||||||
const env = await myEnv();
|
App.env = await myEnv();
|
||||||
mount(App, { target: document.body, env });
|
const app = new App();
|
||||||
|
await app.mount(document.body);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -133,4 +135,17 @@ the `QWeb` instance and a `browser` object:
|
|||||||
- `qweb` will be set to an empty `QWeb` instance. This is absolutely necessary
|
- `qweb` will be set to an empty `QWeb` instance. This is absolutely necessary
|
||||||
for Owl to be able to render anything
|
for Owl to be able to render anything
|
||||||
- `browser`: this is an object that contains some common access points to the
|
- `browser`: this is an object that contains some common access points to the
|
||||||
browser methods with a side effect. See [browser](browser.md) for more information. Note that the browser object will be removed from the environment in Owl 2.0.
|
browser methods with a side effect. This is particularly useful when one want
|
||||||
|
to test more advanced components, and be able to mock those methods.
|
||||||
|
|
||||||
|
More specifically, the `browser` object contains the following methods and objects:
|
||||||
|
|
||||||
|
- `setTimeout`
|
||||||
|
- `clearTimeout`
|
||||||
|
- `setInterval`
|
||||||
|
- `clearInterval`
|
||||||
|
- `requestAnimationFrame`
|
||||||
|
- `random`
|
||||||
|
- `Date`
|
||||||
|
- `fetch`
|
||||||
|
- `localStorage`
|
||||||
|
|||||||
@@ -23,3 +23,5 @@ Its API is:
|
|||||||
| `off(eventType, owner)` | remove all listeners for an owner |
|
| `off(eventType, owner)` | remove all listeners for an owner |
|
||||||
| `trigger(eventType, ...args)` | trigger an event |
|
| `trigger(eventType, ...args)` | trigger an event |
|
||||||
| `clear` | remove all subscriptions |
|
| `clear` | remove all subscriptions |
|
||||||
|
|
||||||
|
Note that the [`Store`](store.md) is an example of an `EventBus`.
|
||||||
|
|||||||
+23
-12
@@ -18,8 +18,9 @@
|
|||||||
- [`useRef`](#useref)
|
- [`useRef`](#useref)
|
||||||
- [`useSubEnv`](#usesubenv)
|
- [`useSubEnv`](#usesubenv)
|
||||||
- [`useExternalListener`](#useexternallistener)
|
- [`useExternalListener`](#useexternallistener)
|
||||||
- [`useComponent`](#usecomponent)
|
- [`useStore`](#usestore)
|
||||||
- [`useEnv`](#useenv)
|
- [`useDispatch`](#usedispatch)
|
||||||
|
- [`useGetters`](#usegetters)
|
||||||
- [Making customized hooks](#making-customized-hooks)
|
- [Making customized hooks](#making-customized-hooks)
|
||||||
|
|
||||||
## Overview
|
## Overview
|
||||||
@@ -128,7 +129,7 @@ class SomeComponent extends Component {
|
|||||||
### One rule
|
### One rule
|
||||||
|
|
||||||
There is only one rule: every hook for a component has to be called in the
|
There is only one rule: every hook for a component has to be called in the
|
||||||
constructor, in the _setup_ method, or in class fields:
|
constructor (or in class fields):
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// ok
|
// ok
|
||||||
@@ -144,13 +145,6 @@ class SomeComponent extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// also ok
|
|
||||||
class SomeComponent extends Component {
|
|
||||||
setup() {
|
|
||||||
this.state = useState({ value: 0 });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// not ok: this is executed after the constructor is called
|
// not ok: this is executed after the constructor is called
|
||||||
class SomeComponent extends Component {
|
class SomeComponent extends Component {
|
||||||
async willStart() {
|
async willStart() {
|
||||||
@@ -372,6 +366,21 @@ to be closed:
|
|||||||
useExternalListener(window, "click", this.closeMenu);
|
useExternalListener(window, "click", this.closeMenu);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### `useStore`
|
||||||
|
|
||||||
|
The `useStore` hook is the entry point for a component to connect to the store.
|
||||||
|
See the [store documentation](store.md) for more information.
|
||||||
|
|
||||||
|
### `useDispatch`
|
||||||
|
|
||||||
|
The `useDispatch` hook is the way for components to get a reference to the store
|
||||||
|
`dispatch` function. See the [store documentation](store.md) for more information.
|
||||||
|
|
||||||
|
### `useGetters`
|
||||||
|
|
||||||
|
The `useGetters` hook is the way for components to get a reference to the store
|
||||||
|
getters. See the [store documentation](store.md) for more information.
|
||||||
|
|
||||||
### Making customized hooks
|
### Making customized hooks
|
||||||
|
|
||||||
Hooks are a wonderful way to organize the code of a complex component by feature
|
Hooks are a wonderful way to organize the code of a complex component by feature
|
||||||
@@ -426,11 +435,13 @@ not the solution to every problem.
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
function useRouter() {
|
function useRouter() {
|
||||||
const env = useEnv();
|
return Component.current.env.router;
|
||||||
return env.router;
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
This means that we give control to the application developer to create the
|
This means that we give control to the application developer to create the
|
||||||
router, which is good, so they can set it up, subclass it, ... And then, to
|
router, which is good, so they can set it up, subclass it, ... And then, to
|
||||||
test our components, we can just add a mock router in the environment.
|
test our components, we can just add a mock router in the environment.
|
||||||
|
|
||||||
|
Note: the code above makes use of the `Component.current` property. This is the
|
||||||
|
way hooks are able to get a reference to the component currently being created.
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ workflow to help the user put in some data, which it could use later on.
|
|||||||
JavaScript:
|
JavaScript:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const { Component, mount } = owl;
|
const { Component } = owl;
|
||||||
const { Portal } = owl.misc;
|
const { Portal } = owl.misc;
|
||||||
|
|
||||||
class TeleportedComponent extends Component {}
|
class TeleportedComponent extends Component {}
|
||||||
@@ -51,7 +51,8 @@ class App extends Component {
|
|||||||
static components = { Portal, TeleportedComponent };
|
static components = { Portal, TeleportedComponent };
|
||||||
}
|
}
|
||||||
|
|
||||||
mount(App, { target: document.body });
|
const app = new App();
|
||||||
|
app.mount(document.body);
|
||||||
```
|
```
|
||||||
|
|
||||||
XML:
|
XML:
|
||||||
|
|||||||
@@ -1,60 +0,0 @@
|
|||||||
# 🦉 Mounting an application 🦉
|
|
||||||
|
|
||||||
## Content
|
|
||||||
|
|
||||||
- [Overview](#overview)
|
|
||||||
- [API](#api)
|
|
||||||
|
|
||||||
## Overview
|
|
||||||
|
|
||||||
Mounting an Owl application is done by using the `mount` method (available in
|
|
||||||
`owl.mount` if you are using the iife build, or it can be directly imported
|
|
||||||
from `owl` if you are using a module system):
|
|
||||||
|
|
||||||
```js
|
|
||||||
const mount = { owl }; // if owl is available as an object
|
|
||||||
|
|
||||||
const env = { ... };
|
|
||||||
const app = await mount(MyComponent, { target: document.body, env });
|
|
||||||
```
|
|
||||||
|
|
||||||
Another example:
|
|
||||||
|
|
||||||
```js
|
|
||||||
const config = {
|
|
||||||
env: ...,
|
|
||||||
props: ...,
|
|
||||||
target: document.body,
|
|
||||||
position: "self",
|
|
||||||
};
|
|
||||||
const app = await mount(App, config);
|
|
||||||
```
|
|
||||||
|
|
||||||
A common way to initialize an application is to first setup an environment,
|
|
||||||
then to call the `mount` method.
|
|
||||||
|
|
||||||
## API
|
|
||||||
|
|
||||||
Mount takes two parameters:
|
|
||||||
|
|
||||||
- `C`, which should be a component class (NOT instance),
|
|
||||||
- `params`, which is an object with the following keys:
|
|
||||||
- `target (HTMLElement | DocumentFragment)`: the target of the mount operation
|
|
||||||
- `env (optional, Env)` an environment
|
|
||||||
- `position (optional, "first-child" | "last-child" | "self")` the position
|
|
||||||
where it should be mounted (see below for more informations)
|
|
||||||
- `props (optional, any)`: some initial values that are given as props. Useful
|
|
||||||
when the root component is configurable, or when testing sub components
|
|
||||||
|
|
||||||
Here are the various positions supported by Owl:
|
|
||||||
|
|
||||||
- `first-child`: with this option, the component will be prepended inside the target,
|
|
||||||
- `last-child` (default value): with this option, the component will be
|
|
||||||
appended in the target element,
|
|
||||||
- `self`: the target will be used as the root element for the component. This
|
|
||||||
means that the target has to be an HTMLElement (and not a document fragment).
|
|
||||||
In this situation, it is possible that the component cannot be unmounted. For
|
|
||||||
example, if its target is `document.body`.
|
|
||||||
|
|
||||||
The `mount` method returns a promise that resolves to the instance of the created
|
|
||||||
component.
|
|
||||||
@@ -15,7 +15,7 @@ use cases, there is no need to directly instantiate an observer.
|
|||||||
For example, this code will display `update` in the console:
|
For example, this code will display `update` in the console:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const observer = new owl.core.Observer();
|
const observer = new owl.Observer();
|
||||||
observer.notifyCB = () => console.log("update");
|
observer.notifyCB = () => console.log("update");
|
||||||
const obj = observer.observe({ a: { b: 1 } });
|
const obj = observer.observe({ a: { b: 1 } });
|
||||||
|
|
||||||
@@ -39,14 +39,14 @@ is incremented every time the value is observed. Sometimes, it can be useful
|
|||||||
to obtain that number:
|
to obtain that number:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const observer = new owl.core.Observer();
|
const observer = new owl.Observer();
|
||||||
const obj = observer.observe({ a: { b: 1 } });
|
const obj = observer.observe({ a: { b: 1 } });
|
||||||
|
|
||||||
observer.revNumber(obj.a); // 1
|
observer.deepRevNumber(obj.a); // 1
|
||||||
obj.a.b = 2;
|
obj.a.b = 2;
|
||||||
|
|
||||||
observer.revNumber(obj.a); // 2
|
observer.deepRevNumber(obj.a); // 2
|
||||||
```
|
```
|
||||||
|
|
||||||
The `revNumber` can also return 0, which indicates that the value is not
|
The `deepRevNumber` can also return 0, which indicates that the value is not
|
||||||
observed.
|
observed.
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ class Child extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class Parent extends Component {
|
class Parent extends Component {
|
||||||
static template = xml`<div><Child a="state.a" b="'string'"/></div>`;
|
static template = xml`<div><ComponentA a="state.a" b="'string'"/></div>`;
|
||||||
static components = { Child };
|
static components = { Child };
|
||||||
state = useState({ a: "fromparent" });
|
state = useState({ a: "fromparent" });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,8 +13,6 @@
|
|||||||
- [Setting Variables](#setting-variables)
|
- [Setting Variables](#setting-variables)
|
||||||
- [Conditionals](#conditionals)
|
- [Conditionals](#conditionals)
|
||||||
- [Dynamic Attributes](#dynamic-attributes)
|
- [Dynamic Attributes](#dynamic-attributes)
|
||||||
- [Dynamic Class Attribute](#dynamic-class-attribute)
|
|
||||||
- [Dynamic Tag Names](#dynamic-tag-names)
|
|
||||||
- [Loops](#loops)
|
- [Loops](#loops)
|
||||||
- [Rendering Sub Templates](#rendering-sub-templates)
|
- [Rendering Sub Templates](#rendering-sub-templates)
|
||||||
- [Dynamic Sub Templates](#dynamic-sub-templates)
|
- [Dynamic Sub Templates](#dynamic-sub-templates)
|
||||||
@@ -78,7 +76,6 @@ needs. Here is a list of all Owl specific directives:
|
|||||||
| `t-transition` | [Defining an animation](animations.md#css-transitions) |
|
| `t-transition` | [Defining an animation](animations.md#css-transitions) |
|
||||||
| `t-slot` | [Rendering a slot](slots.md) |
|
| `t-slot` | [Rendering a slot](slots.md) |
|
||||||
| `t-model` | [Form input bindings](component.md#form-input-bindings) |
|
| `t-model` | [Form input bindings](component.md#form-input-bindings) |
|
||||||
| `t-tag` | [Rendering nodes with dynamic tag name](#dynamic-tag-names) |
|
|
||||||
|
|
||||||
## Reference
|
## Reference
|
||||||
|
|
||||||
@@ -327,40 +324,6 @@ values) or a pair `[key, value]`. For example:
|
|||||||
<div t-att="['a', 'b']"/> <!-- <div a="b"></div> -->
|
<div t-att="['a', 'b']"/> <!-- <div a="b"></div> -->
|
||||||
```
|
```
|
||||||
|
|
||||||
### Dynamic class attribute
|
|
||||||
|
|
||||||
For convenience, Owl supports a special case for the `t-att-class` case: one can
|
|
||||||
use an object with keys describing the classes, and values boolean value denoting
|
|
||||||
if the class is or is not present:
|
|
||||||
|
|
||||||
```xml
|
|
||||||
<div t-att-class="{'a': true, 'b': true}"/> <!-- result: <div class="a b"></div> -->
|
|
||||||
|
|
||||||
<div t-att-class="{'a b': true, 'c': true}"/> <!-- result: <div class="a b c"></div> -->
|
|
||||||
```
|
|
||||||
|
|
||||||
Note that it can be combined with normal class attribute:
|
|
||||||
|
|
||||||
```xml
|
|
||||||
<div class="a" t-att-class="{'b': true}"/> <!-- result: <div class="a b"></div> -->
|
|
||||||
```
|
|
||||||
|
|
||||||
### Dynamic tag names
|
|
||||||
|
|
||||||
When writing generic components or templates, the specific concrete tag for an
|
|
||||||
HTML element is not known yet. In those situations, the `t-tag` directive is
|
|
||||||
useful. It simply evaluates dynamically an expression to use as a tag name. The
|
|
||||||
template:
|
|
||||||
|
|
||||||
```xml
|
|
||||||
<t t-tag="tag">
|
|
||||||
<span>content</span>
|
|
||||||
</t>
|
|
||||||
```
|
|
||||||
|
|
||||||
will be rendered as `<div><span>content</span></div>` if the `tag` context key
|
|
||||||
is set to `div`.
|
|
||||||
|
|
||||||
### Loops
|
### Loops
|
||||||
|
|
||||||
QWeb has an iteration directive `t-foreach` which take an expression returning the
|
QWeb has an iteration directive `t-foreach` which take an expression returning the
|
||||||
|
|||||||
@@ -0,0 +1,183 @@
|
|||||||
|
# 🦉 Router 🦉
|
||||||
|
|
||||||
|
Remove?
|
||||||
|
|
||||||
|
## Content
|
||||||
|
|
||||||
|
- [Overview](#overview)
|
||||||
|
- [Example](#example)
|
||||||
|
- [Reference](#reference)
|
||||||
|
- [Route Definition](#route-definition)
|
||||||
|
- [Router](#router)
|
||||||
|
- [Navigation Guards](#navigation-guards)
|
||||||
|
- [RouteComponent](#routecomponent)
|
||||||
|
- [Link](#link)
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
|
||||||
|
It is often useful to organize an application around urls. If the application is
|
||||||
|
a single page application, then we need a way to manage those urls in the browser.
|
||||||
|
This is why there are many different routers for different frameworks. A generic
|
||||||
|
router can do the job just fine, but a specialized router for Owl can give a
|
||||||
|
better developer experience.
|
||||||
|
|
||||||
|
The Owl router support the following features:
|
||||||
|
|
||||||
|
- `history` or `hash` mode
|
||||||
|
- declarative routes
|
||||||
|
- route redirection
|
||||||
|
- navigation guards
|
||||||
|
- parameterized routes
|
||||||
|
- a `<Link/>` component
|
||||||
|
- a `<RouteComponent/>` component
|
||||||
|
|
||||||
|
Note that it is still in early stage of developments, and there are probably
|
||||||
|
still some issues.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
To use the Owl router, there are some steps that needs to be done:
|
||||||
|
|
||||||
|
- declare some routes
|
||||||
|
- create a router
|
||||||
|
- add it to the environment
|
||||||
|
|
||||||
|
```js
|
||||||
|
async function protectRoute({ env, to }) {
|
||||||
|
if (!env.session.authUser) {
|
||||||
|
env.session.setNextRoute(to.name);
|
||||||
|
return { to: "SIGN_IN" };
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const ROUTES = [
|
||||||
|
{ name: "LANDING", path: "/", component: Landing },
|
||||||
|
{ name: "TASK", path: "/tasks/{{id}}", component: Task },
|
||||||
|
{ name: "SIGN_UP", path: "/signup", component: SignUp },
|
||||||
|
{ name: "SIGN_IN", path: "/signin", component: SignIn },
|
||||||
|
{ name: "ADMIN", path: "/admin", component: Admin, beforeRouteEnter: protectRoute },
|
||||||
|
{ name: "ACCOUNT", path: "/account", component: Account, beforeRouteEnter: protectRoute },
|
||||||
|
{ name: "UNKNOWN", path: "*", redirect: { to: "LANDING" } }
|
||||||
|
];
|
||||||
|
|
||||||
|
function makeEnvironment() {
|
||||||
|
...
|
||||||
|
const env = { qweb };
|
||||||
|
env.session = new Session(env);
|
||||||
|
env.router = new owl.router.Router(env, ROUTES);
|
||||||
|
await env.router.start();
|
||||||
|
return env;
|
||||||
|
}
|
||||||
|
|
||||||
|
App.env = makeEnvironment();
|
||||||
|
// create root component here
|
||||||
|
```
|
||||||
|
|
||||||
|
Notice that the router needs to be started. This is an asynchronous operation
|
||||||
|
because it needs to apply the potential navigation guards on the current route
|
||||||
|
(which may or may not mean that the application is redirected to another route).
|
||||||
|
|
||||||
|
## Reference
|
||||||
|
|
||||||
|
### Route definition
|
||||||
|
|
||||||
|
A route need to be defined as an object with the following keys:
|
||||||
|
|
||||||
|
- `name` (optional): a (unique) string useful to identify the current route. If not
|
||||||
|
given, it will be assigned an automatic name,
|
||||||
|
- `path`: a string describing the url. It can be static: `/admin` or dynamic: `/users/{{id}}`.
|
||||||
|
It also can be `*`, to catch all remaining routes.
|
||||||
|
- `component` (optional): an Owl component that will be used by the `t-routecomponent`
|
||||||
|
directive if the route is active
|
||||||
|
- `redirect` (optional): should be destination object (with optional keys `path`, `to` and `params`) if given, the application will be redirected to the destination whenever we match this route
|
||||||
|
- `beforeRouteEnter`: defines a [navigation guard](#navigation-guards).
|
||||||
|
|
||||||
|
### `Router`
|
||||||
|
|
||||||
|
The `Router` constructor takes three arguments:
|
||||||
|
|
||||||
|
- `env`: a valid environment,
|
||||||
|
- a list of routes,
|
||||||
|
- an optional object (with the only key `mode` which can be `history` (default
|
||||||
|
value) or `hash`).
|
||||||
|
|
||||||
|
`history` will use the browser [History API](https://developer.mozilla.org/en-US/docs/Web/API/History_API) as the mechanism to manage URL.\
|
||||||
|
Example: `https://yourdomain.tld/my_custom_route`.\
|
||||||
|
For this mechanism to work, you need a way to configure your web server accordingly.
|
||||||
|
|
||||||
|
`hash` will manipulate the hash of the URL.\
|
||||||
|
Example: `https://yourdomain.tld/index.html#/my_custom_route`.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const ROUTES = [...];
|
||||||
|
const router = new owl.router.Router(env, ROUTES, {mode: 'history'});
|
||||||
|
```
|
||||||
|
|
||||||
|
Note that the route are defined in a list, and the order matters: the router
|
||||||
|
tries to find a match by going down the list.
|
||||||
|
|
||||||
|
The router needs to be added to the environment in the `router` sub key.
|
||||||
|
|
||||||
|
Once a router is created, it needs to be started. This is necessary to initialize
|
||||||
|
its current state to the current URL (and also, to potentially apply any
|
||||||
|
navigation guards and/or redirecting).
|
||||||
|
|
||||||
|
```js
|
||||||
|
await router.start();
|
||||||
|
```
|
||||||
|
|
||||||
|
Once started, the router will keep track of the current url and reflect its
|
||||||
|
value in two keys:
|
||||||
|
|
||||||
|
- `router.currentRoute`
|
||||||
|
- `router.currentParams`
|
||||||
|
|
||||||
|
The router also has a `navigate` method, useful to programmatically change the
|
||||||
|
application to another state (and the url):
|
||||||
|
|
||||||
|
```js
|
||||||
|
router.navigate({ to: "USER", params: { id: 51 } });
|
||||||
|
```
|
||||||
|
|
||||||
|
### Navigation Guards
|
||||||
|
|
||||||
|
Navigation guards are very useful to be able to execute some business logic/
|
||||||
|
perform some actions or redirect to other routes whenever the application is
|
||||||
|
entering a new route. For example, the following guard checks if there is an
|
||||||
|
authenticated user, and if it is not the case, redirect to the sign in route.
|
||||||
|
|
||||||
|
```js
|
||||||
|
async function protectRoute({ env, to }) {
|
||||||
|
if (!env.session.authUser) {
|
||||||
|
env.session.setNextRoute(to.name);
|
||||||
|
return { to: "SIGN_IN" };
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
A navigation guard is a function that returns a promise, which either resolves
|
||||||
|
to `true` (the navigation is accepted), or to another destination object.
|
||||||
|
|
||||||
|
### `RouteComponent`
|
||||||
|
|
||||||
|
The `RouteComponent` component directs Owl to render the component associated
|
||||||
|
to the currently active route (if any):
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<div t-name="App">
|
||||||
|
<NavBar />
|
||||||
|
<RouteComponent />
|
||||||
|
</div>
|
||||||
|
```
|
||||||
|
|
||||||
|
### `Link`
|
||||||
|
|
||||||
|
The `Link` component is a Owl component which render as a `<a>` tag with any
|
||||||
|
content. It will compute the proper href from its props, and allow Owl to
|
||||||
|
properly navigate to a given url if clicked on it.
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<Link to="'HOME'">Home</Link>
|
||||||
|
```
|
||||||
+3
-18
@@ -25,8 +25,6 @@ some sub template, but still be the owner. For example, a generic dialog compone
|
|||||||
will need to render some content, some footer, but with the parent as the
|
will need to render some content, some footer, but with the parent as the
|
||||||
rendering context.
|
rendering context.
|
||||||
|
|
||||||
Slots are inserted with the `t-slot` directive:
|
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
<div t-name="Dialog" class="modal">
|
<div t-name="Dialog" class="modal">
|
||||||
<div class="modal-title"><t t-esc="props.title"/></div>
|
<div class="modal-title"><t t-esc="props.title"/></div>
|
||||||
@@ -44,7 +42,7 @@ Slots are defined by the caller, with the `t-set-slot` directive:
|
|||||||
```xml
|
```xml
|
||||||
<div t-name="SomeComponent">
|
<div t-name="SomeComponent">
|
||||||
<div>some component</div>
|
<div>some component</div>
|
||||||
<Dialog title="'Some Dialog'">
|
<Dialog title="Some Dialog">
|
||||||
<t t-set-slot="content">
|
<t t-set-slot="content">
|
||||||
<div>hey</div>
|
<div>hey</div>
|
||||||
</t>
|
</t>
|
||||||
@@ -64,9 +62,7 @@ This is deprecated and should no longer be used in new code.
|
|||||||
|
|
||||||
## Reference
|
## Reference
|
||||||
|
|
||||||
### Default Slot
|
Default slot: the first element inside the component which is not a named slot will
|
||||||
|
|
||||||
The first element inside the component which is not a named slot will
|
|
||||||
be considered the `default` slot. For example:
|
be considered the `default` slot. For example:
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
@@ -81,9 +77,7 @@ be considered the `default` slot. For example:
|
|||||||
</div>
|
</div>
|
||||||
```
|
```
|
||||||
|
|
||||||
### Default content
|
Default content: slots can define a default content, in case the parent did not define them:
|
||||||
|
|
||||||
Slots can define a default content, in case the parent did not define them:
|
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
<div t-name="Parent">
|
<div t-name="Parent">
|
||||||
@@ -100,12 +94,3 @@ Rendering context: the content of the slots is actually rendered with the
|
|||||||
rendering context corresponding to where it was defined, not where it is
|
rendering context corresponding to where it was defined, not where it is
|
||||||
positioned. This allows the user to define event handlers that will be bound
|
positioned. This allows the user to define event handlers that will be bound
|
||||||
to the correct component (usually, the grandparent of the slot content).
|
to the correct component (usually, the grandparent of the slot content).
|
||||||
|
|
||||||
### Dynamic Slots
|
|
||||||
|
|
||||||
The `t-slot` directive is actually able to use any expressions, using string
|
|
||||||
interplolation:
|
|
||||||
|
|
||||||
```xml
|
|
||||||
<t t-slot="{{current}}" />
|
|
||||||
```
|
|
||||||
|
|||||||
@@ -0,0 +1,349 @@
|
|||||||
|
# 🦉 Store 🦉
|
||||||
|
|
||||||
|
## Content
|
||||||
|
|
||||||
|
- [Overview](#overview)
|
||||||
|
- [Example](#example)
|
||||||
|
- [Reference](#reference)
|
||||||
|
- [Store](#store)
|
||||||
|
- [Actions](#actions)
|
||||||
|
- [Getters](#getters)
|
||||||
|
- [Connecting a Component](#connecting-a-component)
|
||||||
|
- [`useStore`](#usestore)
|
||||||
|
- [`useDispatch`](#usedispatch)
|
||||||
|
- [`useGetters`](#usegetters)
|
||||||
|
- [Semantics](#semantics)
|
||||||
|
- [Good Practices](#good-practices)
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
|
||||||
|
Managing the state in an application is not an easy task. In some cases, the
|
||||||
|
state of an application can be part of the component tree, in a natural way.
|
||||||
|
However, there are situations where some parts of the state need to be displayed
|
||||||
|
in various parts of the user interface, and then, it is not obvious which
|
||||||
|
component should own which part of the state.
|
||||||
|
|
||||||
|
Owl's solution to this issue is a centralized store. It is a class that owns
|
||||||
|
some (or all) state, and lets the developer update it in a structured way, with
|
||||||
|
`actions`. Owl components can then connect to the store to read their relevant
|
||||||
|
state, and they will be rerendered if the state is updated.
|
||||||
|
|
||||||
|
Note: Owl store is inspired by React Redux and VueX.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
Here is what a simple store looks like:
|
||||||
|
|
||||||
|
```js
|
||||||
|
const actions = {
|
||||||
|
addTodo({ state }, message) {
|
||||||
|
state.todos.push({
|
||||||
|
id: state.nextId++,
|
||||||
|
message,
|
||||||
|
isCompleted: false,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const state = {
|
||||||
|
todos: [],
|
||||||
|
nextId: 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
const store = new owl.Store({ state, actions });
|
||||||
|
store.on("update", null, () => console.log(store.state));
|
||||||
|
|
||||||
|
// updating the state
|
||||||
|
store.dispatch("addTodo", "fix all bugs");
|
||||||
|
```
|
||||||
|
|
||||||
|
This example shows how a store can be defined and used. Note that in most cases,
|
||||||
|
actions will be dispatched by connected components.
|
||||||
|
|
||||||
|
## Reference
|
||||||
|
|
||||||
|
### `Store`
|
||||||
|
|
||||||
|
The store is a simple [`owl.EventBus`](event_bus.md) that triggers `update` events
|
||||||
|
whenever its state is changed. Note that these events are triggered only after a
|
||||||
|
microtask tick, so only one event will be triggered for any number of state changes in a
|
||||||
|
call stack.
|
||||||
|
|
||||||
|
Also, it is important to mention that the state is observed (with an `owl.Observer`),
|
||||||
|
which is the reason why it is able to know if it was changed. See the
|
||||||
|
[Observer](observer.md)'s documentation for more details.
|
||||||
|
|
||||||
|
The `Store` class is quite small. It has two public methods:
|
||||||
|
|
||||||
|
- its constructor
|
||||||
|
- `dispatch`
|
||||||
|
|
||||||
|
The constructor takes a configuration object with four (optional) keys:
|
||||||
|
|
||||||
|
- the initial state
|
||||||
|
- the actions
|
||||||
|
- the getters
|
||||||
|
- the environment
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const config = {
|
||||||
|
state,
|
||||||
|
actions,
|
||||||
|
getters,
|
||||||
|
env,
|
||||||
|
};
|
||||||
|
const store = new Store(config);
|
||||||
|
```
|
||||||
|
|
||||||
|
### Actions
|
||||||
|
|
||||||
|
Actions are used to coordinate state changes. It can be used for both synchronous
|
||||||
|
and asynchronous logic.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const actions = {
|
||||||
|
async login({ state }, info) {
|
||||||
|
state.loginState = "pending";
|
||||||
|
try {
|
||||||
|
const loginInfo = await doSomeRPC("/login/", info);
|
||||||
|
state.loginState = loginInfo;
|
||||||
|
} catch (e) {
|
||||||
|
state.loginState = "error";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
The first argument to an action method is an object with four keys:
|
||||||
|
|
||||||
|
- `state`: the current state of the store content,
|
||||||
|
- `dispatch`: a function that can be used to dispatch other actions,
|
||||||
|
- `getters`: an object containing all getters defined in the store,
|
||||||
|
- `env`: the current environment. This is useful sometimes, in particular if
|
||||||
|
an action needs to apply some side effects (such as performing an rpc), and
|
||||||
|
the `rpc` method is located in the environment.
|
||||||
|
|
||||||
|
Actions are called with the `dispatch` method on the store, and can receive an
|
||||||
|
arbitrary number of arguments.
|
||||||
|
|
||||||
|
```js
|
||||||
|
store.dispatch("login", someInfo);
|
||||||
|
```
|
||||||
|
|
||||||
|
Note that anything returned by an action will also be returned by the `dispatch`
|
||||||
|
call.
|
||||||
|
|
||||||
|
Also, it is important to be aware that we need to be careful with asynchronous
|
||||||
|
logic. Each state change will potentially trigger a rerendering, so we need to
|
||||||
|
make sure that we do not have a partially corrupted state. Here is an example that
|
||||||
|
is likely not a good idea:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const actions = {
|
||||||
|
async fetchSomeData({ state }, recordId) {
|
||||||
|
state.recordId = recordId;
|
||||||
|
const data = await doSomeRPC("/read/", recordId);
|
||||||
|
state.recordData = data;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
In the previous example, there is a period of time in which the state has a
|
||||||
|
`recordId` which does not correspond to the `recordData`. It is more likely that
|
||||||
|
we want an atomic update: updating the `recordId` at the same time as the `recordData`
|
||||||
|
values:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const actions = {
|
||||||
|
async fetchSomeData({ state }, recordId) {
|
||||||
|
const data = await doSomeRPC("/read/", recordId);
|
||||||
|
state.recordId = recordId;
|
||||||
|
state.recordData = data;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
### Getters
|
||||||
|
|
||||||
|
Usually, data contained in the store will be stored in a normalized way. For
|
||||||
|
example,
|
||||||
|
|
||||||
|
```js
|
||||||
|
{
|
||||||
|
posts: [{id: 11, authorId: 4, content: 'Greetings'}],
|
||||||
|
authors: [{id: 4, name: 'John'}]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
However, the user interface will probably need some denormalized data like
|
||||||
|
|
||||||
|
```js
|
||||||
|
{id: 11, author: {id: 4, name: 'John'}, content: 'Greetings'}
|
||||||
|
```
|
||||||
|
|
||||||
|
This is what `getters` are for: they give a centralized way to process and
|
||||||
|
transform the data contained in the store.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const getters = {
|
||||||
|
getPost({ state }, id) {
|
||||||
|
const post = state.posts.find((p) => p.id === id);
|
||||||
|
const author = state.authors.find((a) => a.id === post.id);
|
||||||
|
return {
|
||||||
|
id,
|
||||||
|
author,
|
||||||
|
content: post.content,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// somewhere else
|
||||||
|
const post = store.getters.getPost(id);
|
||||||
|
```
|
||||||
|
|
||||||
|
Getters take _at most_ one argument.
|
||||||
|
|
||||||
|
Note that getters are not cached.
|
||||||
|
|
||||||
|
### Connecting a Component
|
||||||
|
|
||||||
|
At some point, we need a way to interact with the store from a component. This
|
||||||
|
means that the component needs a reference to the store. By default, it looks
|
||||||
|
for it in the `env.store` key. However, this can be configured with the `useStore`
|
||||||
|
hook.
|
||||||
|
|
||||||
|
Every component-store interactions are done with the help of the three store hooks:
|
||||||
|
|
||||||
|
- [`useStore`](#usestore) to subscribe a component to some part of the store state,
|
||||||
|
- [`useDispatch`](#usedispatch) to get a reference to a dispatch function,
|
||||||
|
- [`useGetters`](#usegetters) to get a reference to the getters defined in the store.
|
||||||
|
|
||||||
|
Assume we have this store:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const actions = {
|
||||||
|
increment({ state }, val) {
|
||||||
|
state.counter.value += val;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const state = {
|
||||||
|
counter: { value: 0 },
|
||||||
|
};
|
||||||
|
const store = new owl.Store({ state, actions });
|
||||||
|
```
|
||||||
|
|
||||||
|
To make it accessible to the complete application, we will put it in the
|
||||||
|
environment:
|
||||||
|
|
||||||
|
```js
|
||||||
|
// in this example, the root component is App
|
||||||
|
App.env.store = store;
|
||||||
|
```
|
||||||
|
|
||||||
|
A counter component can then select this value and dispatch an action like this:
|
||||||
|
|
||||||
|
```js
|
||||||
|
class Counter extends Component {
|
||||||
|
counter = useStore((state) => state.counter);
|
||||||
|
dispatch = useDispatch();
|
||||||
|
}
|
||||||
|
|
||||||
|
const counter = new Counter({ store, qweb });
|
||||||
|
```
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<button t-name="Counter" t-on-click="dispatch('increment')">
|
||||||
|
Click Me! [<t t-esc="counter.value"/>]
|
||||||
|
</button>
|
||||||
|
```
|
||||||
|
|
||||||
|
### `useStore`
|
||||||
|
|
||||||
|
The `useStore` hook is used to select some part of the store state. It accepts
|
||||||
|
two arguments:
|
||||||
|
|
||||||
|
- a selector function, which takes the store state as first argument (and the
|
||||||
|
component props as second argument) and which must return the part of the
|
||||||
|
store state that will be made available and observed for changes,
|
||||||
|
- optionally, an object which can have the following optional keys:
|
||||||
|
- a `store` key containing a store object if we want to use another store than
|
||||||
|
the default store,
|
||||||
|
- an `isEqual` key containing an equality function if we want to specialize
|
||||||
|
the comparison (the function must accept two arguments: the previous result
|
||||||
|
and the new result, and must return whether they are equal),
|
||||||
|
- and an `onUpdate` key containing an update function if we want to execute an
|
||||||
|
arbitrary code every time the selected state changes (the function will
|
||||||
|
receive one argument, the new result, and can execute arbitrary code).
|
||||||
|
|
||||||
|
If the `useStore` selector returns a sub part of the store state, the component
|
||||||
|
will only be rerendered whenever this part of the state changes. Otherwise, it
|
||||||
|
will perform a strict equality check (unless the `isEqual` option is defined,
|
||||||
|
then it will call it) and will update the component every time this check fails.
|
||||||
|
|
||||||
|
Note that if the selector function returns a primitive type, the result of
|
||||||
|
`useStore` will be immutable and it will not react to changes. In this case, it
|
||||||
|
is important to define the `onUpdate` option to properly update the value
|
||||||
|
manually when it changes.
|
||||||
|
|
||||||
|
Also, the return value from `useStore` is not supposed to be modified. The store
|
||||||
|
state should only be updated with actions.
|
||||||
|
|
||||||
|
### `useDispatch`
|
||||||
|
|
||||||
|
The `useDispatch` hook is useful when a component needs to be able to dispatch
|
||||||
|
actions. It takes an optional argument, which is a store. If not given, it will
|
||||||
|
use the store in the environment.
|
||||||
|
|
||||||
|
Note that a component does not need to be connected in any other way to the store.
|
||||||
|
For example:
|
||||||
|
|
||||||
|
```js
|
||||||
|
class DoSomethingButton extends Component {
|
||||||
|
static template = xml`<button t-on-click="dispatch('something')">Click</button>`;
|
||||||
|
dispatch = useDispatch();
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### `useGetters`
|
||||||
|
|
||||||
|
The `useGetters` hook is useful when a component needs to be able to use the
|
||||||
|
getters defined in a store. It takes an optional argument, which is a store. If
|
||||||
|
not given, it will use the store in the environment.
|
||||||
|
|
||||||
|
Note that a component does not need to be connected in any other way to the store.
|
||||||
|
For example:
|
||||||
|
|
||||||
|
```js
|
||||||
|
class InfoButton extends Component {
|
||||||
|
static template = xml`<span><t t-esc="getters.somevalue()"></span>`;
|
||||||
|
getters = useGetters();
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Semantics
|
||||||
|
|
||||||
|
The `Store` class and the `useStore` hook try to be smart and to optimize as much
|
||||||
|
as possible the rendering and update process. What is important to know is:
|
||||||
|
|
||||||
|
- components are always updated in the order of their creation (so, parent
|
||||||
|
before children),
|
||||||
|
- they are updated only if they are in the DOM,
|
||||||
|
- if a parent is asynchronous, the system will wait for it to complete its
|
||||||
|
update before updating other components,
|
||||||
|
- in general, updates are not coordinated. This is not a problem for synchronous
|
||||||
|
components, but if there are many asynchronous components, this could lead to
|
||||||
|
a situation where some part of the UI is updated and some other part of the UI is
|
||||||
|
not updated.
|
||||||
|
|
||||||
|
### Good Practices
|
||||||
|
|
||||||
|
- avoid asynchronous components as much as possible. Asynchronous components
|
||||||
|
lead to situations where parts of the UI is not updated immediately,
|
||||||
|
- do not be afraid to connect many components, parent or children if needed. For
|
||||||
|
example, a `MessageList` component could get a list of ids in its `useStore`
|
||||||
|
call and a `Message` component could get the data of its own
|
||||||
|
message,
|
||||||
|
- since the `useStore` function is called for each connected component,
|
||||||
|
for each state update, it is important to make sure that these functions are
|
||||||
|
as fast as possible.
|
||||||
@@ -62,14 +62,14 @@ The CSS tag is useful to define a css stylesheet in the javascript file:
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
class MyComponent extends Component {
|
class MyComponent extends Component {
|
||||||
static template = xml`
|
static template = xml`
|
||||||
<div class="my-component">some template</div>
|
<div class="my-component">some template</div>
|
||||||
`;
|
`;
|
||||||
static style = css`
|
static css`
|
||||||
.my-component {
|
.my-component {
|
||||||
color: red;
|
color: red;
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ argument, it executes it as soon as the DOM ready (or directly).
|
|||||||
```js
|
```js
|
||||||
Promise.all([loadFile("templates.xml"), owl.utils.whenReady()]).then(function ([templates]) {
|
Promise.all([loadFile("templates.xml"), owl.utils.whenReady()]).then(function ([templates]) {
|
||||||
const qweb = new owl.QWeb({ templates });
|
const qweb = new owl.QWeb({ templates });
|
||||||
const env = { qweb };
|
const app = new App({ qweb });
|
||||||
await mount(App, { env, target: document.body });
|
app.mount(document.body);
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -31,8 +31,8 @@ or alternatively:
|
|||||||
```js
|
```js
|
||||||
owl.utils.whenReady(function () {
|
owl.utils.whenReady(function () {
|
||||||
const qweb = new owl.QWeb();
|
const qweb = new owl.QWeb();
|
||||||
const env = { qweb };
|
const app = new App({ qweb });
|
||||||
await mount(App, { env, target: document.body });
|
app.mount(document.body);
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
+10
-15
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@odoo/owl",
|
"name": "@odoo/owl",
|
||||||
"version": "2.0.0-alpha1",
|
"version": "1.0.13",
|
||||||
"description": "Odoo Web Library (OWL)",
|
"description": "Odoo Web Library (OWL)",
|
||||||
"main": "dist/owl.cjs.js",
|
"main": "dist/owl.cjs.js",
|
||||||
"browser": "dist/owl.iife.js",
|
"browser": "dist/owl.iife.js",
|
||||||
@@ -10,20 +10,18 @@
|
|||||||
"dist"
|
"dist"
|
||||||
],
|
],
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=12.18.3"
|
"node": ">=10.15.3"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build:bundle": "rollup -c",
|
"build:bundle": "rollup -c",
|
||||||
"build": "npm run build:bundle",
|
"build": "npm run build:bundle",
|
||||||
"test": "jest",
|
"test": "jest",
|
||||||
"test:debug": "node --inspect-brk node_modules/.bin/jest --runInBand --watch",
|
|
||||||
"test:watch": "jest --watch",
|
"test:watch": "jest --watch",
|
||||||
"playground:serve": "python3 tools/server.py || python tools/server.py",
|
"tools:serve": "python3 tools/server.py || python tools/server.py",
|
||||||
"playground": "npm run build && npm run playground:serve",
|
"tools": "npm run build && npm run tools:serve",
|
||||||
"preplayground:watch": "npm run build",
|
"pretools:watch": "npm run build",
|
||||||
"playground:watch": "npm-run-all --parallel playground:serve \"build:* -- --watch\"",
|
"tools:watch": "npm-run-all --parallel tools:serve \"build:* -- --watch\"",
|
||||||
"prettier": "prettier {src/*.ts,src/**/*.ts,tests/*.ts,tests/**/*.ts,doc/*.md,doc/**/*.md} --write",
|
"prettier": "prettier {src/*.ts,src/**/*.ts,tests/*.ts,tests/**/*.ts,doc/*.md,doc/**/*.md} --write",
|
||||||
"check-formatting": "prettier {src/*.ts,src/**/*.ts,tests/*.ts,tests/**/*.ts,doc/*.md,doc/**/*.md} --check",
|
|
||||||
"publish": "npm run build && npm publish",
|
"publish": "npm run build && npm publish",
|
||||||
"release": "node tools/release.js"
|
"release": "node tools/release.js"
|
||||||
},
|
},
|
||||||
@@ -42,21 +40,20 @@
|
|||||||
"@types/node": "^14.11.8",
|
"@types/node": "^14.11.8",
|
||||||
"chalk": "^3.0.0",
|
"chalk": "^3.0.0",
|
||||||
"cpx": "^1.5.0",
|
"cpx": "^1.5.0",
|
||||||
"current-git-branch": "^1.1.0",
|
|
||||||
"git-rev-sync": "^1.12.0",
|
"git-rev-sync": "^1.12.0",
|
||||||
"github-api": "^3.3.0",
|
"github-api": "^3.3.0",
|
||||||
"jest": "^27.1.0",
|
"jest": "^27.1.0",
|
||||||
"jest-environment-jsdom": "^27.1.0",
|
"jest-environment-jsdom": "^27.1.0",
|
||||||
"live-server": "^1.2.1",
|
"live-server": "^1.2.1",
|
||||||
"npm-run-all": "^4.1.5",
|
"npm-run-all": "^4.1.5",
|
||||||
"prettier": "2.4.1",
|
"prettier": "^2.0.4",
|
||||||
"rollup": "^2.56.3",
|
"rollup": "^2.56.3",
|
||||||
"rollup-plugin-terser": "^7.0.2",
|
"rollup-plugin-terser": "^7.0.2",
|
||||||
"rollup-plugin-typescript2": "^0.31.1",
|
"rollup-plugin-typescript2": "^0.30.0",
|
||||||
"sass": "^1.16.1",
|
"sass": "^1.16.1",
|
||||||
"source-map-support": "^0.5.10",
|
"source-map-support": "^0.5.10",
|
||||||
"ts-jest": "^27.0.5",
|
"ts-jest": "^27.0.5",
|
||||||
"typescript": "4.5.2",
|
"typescript": "3.9.6",
|
||||||
"uglify-es": "^3.3.9"
|
"uglify-es": "^3.3.9"
|
||||||
},
|
},
|
||||||
"jest": {
|
"jest": {
|
||||||
@@ -65,9 +62,7 @@
|
|||||||
"<rootDir>/src",
|
"<rootDir>/src",
|
||||||
"<rootDir>/tests"
|
"<rootDir>/tests"
|
||||||
],
|
],
|
||||||
"setupFiles": [
|
"setupFiles": ["./tests/mocks/mockEventTarget.js"],
|
||||||
"./tests/mocks/mockEventTarget.js"
|
|
||||||
],
|
|
||||||
"transform": {
|
"transform": {
|
||||||
"^.+\\.ts?$": "ts-jest"
|
"^.+\\.ts?$": "ts-jest"
|
||||||
},
|
},
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
# 🦉 OWL Roadmap 🦉
|
# 🦉 OWL Roadmap 🦉
|
||||||
|
|
||||||
- Current version: 1.4.7
|
- Current version: 1.0.13
|
||||||
- Status: stable
|
- Status: stable
|
||||||
|
|
||||||
This roadmap is only an attempt at predicting Owl's future. Everything may
|
This roadmap is only an attempt at predicting Owl's future. Everything may
|
||||||
|
|||||||
+45
@@ -0,0 +1,45 @@
|
|||||||
|
import { Component } from "./component/component";
|
||||||
|
import { ComponentNode } from "./component/component_node";
|
||||||
|
import { Scheduler } from "./component/scheduler";
|
||||||
|
import { TemplateSet } from "./qweb/template_helpers";
|
||||||
|
|
||||||
|
// reimplement dev mode stuff see last change in 0f7a8289a6fb8387c3c1af41c6664b2a8448758f
|
||||||
|
|
||||||
|
export class App<T extends typeof Component = any> extends TemplateSet {
|
||||||
|
Root: T;
|
||||||
|
props: any;
|
||||||
|
env: any = {};
|
||||||
|
scheduler = new Scheduler(window.requestAnimationFrame.bind(window));
|
||||||
|
root: ComponentNode | null = null;
|
||||||
|
dev: boolean = true;
|
||||||
|
|
||||||
|
constructor(Root: T, props?: any) {
|
||||||
|
super();
|
||||||
|
this.Root = Root;
|
||||||
|
this.props = props;
|
||||||
|
}
|
||||||
|
|
||||||
|
configure(params: any) {
|
||||||
|
if (params.env) {
|
||||||
|
this.env = params.env;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mount(target: HTMLElement): Promise<InstanceType<T>> {
|
||||||
|
if (!(target instanceof HTMLElement)) {
|
||||||
|
throw new Error("Cannot mount component: the target is not a valid DOM element");
|
||||||
|
}
|
||||||
|
if (!document.body.contains(target)) {
|
||||||
|
throw new Error("Cannot mount a component on a detached dom node");
|
||||||
|
}
|
||||||
|
const node = new ComponentNode(this.Root, this.props, this);
|
||||||
|
this.root = node;
|
||||||
|
return node.mountComponent(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
destroy() {
|
||||||
|
if (this.root) {
|
||||||
|
this.root.destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,76 +0,0 @@
|
|||||||
import { Component } from "../component/component";
|
|
||||||
import { ComponentNode } from "../component/component_node";
|
|
||||||
import { MountOptions } from "../component/fibers";
|
|
||||||
import { Scheduler } from "../component/scheduler";
|
|
||||||
import { TemplateSet } from "./template_set";
|
|
||||||
|
|
||||||
// reimplement dev mode stuff see last change in 0f7a8289a6fb8387c3c1af41c6664b2a8448758f
|
|
||||||
|
|
||||||
export interface Env {
|
|
||||||
[key: string]: any;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface AppConfig {
|
|
||||||
dev?: boolean;
|
|
||||||
env?: Env;
|
|
||||||
translatableAttributes?: string[];
|
|
||||||
translateFn?: (s: string) => string;
|
|
||||||
templates?: string | Document;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const DEV_MSG = `Owl is running in 'dev' mode.
|
|
||||||
|
|
||||||
This is not suitable for production use.
|
|
||||||
See https://github.com/odoo/owl/blob/master/doc/reference/config.md#mode for more information.`;
|
|
||||||
|
|
||||||
export class App<T extends typeof Component = any> extends TemplateSet {
|
|
||||||
Root: T;
|
|
||||||
props: any;
|
|
||||||
env: Env = Object.freeze({});
|
|
||||||
scheduler = new Scheduler(window.requestAnimationFrame.bind(window));
|
|
||||||
root: ComponentNode | null = null;
|
|
||||||
|
|
||||||
constructor(Root: T, props?: any) {
|
|
||||||
super();
|
|
||||||
this.Root = Root;
|
|
||||||
this.props = props;
|
|
||||||
}
|
|
||||||
|
|
||||||
configure(config: AppConfig): App<T> {
|
|
||||||
if (config.dev) {
|
|
||||||
this.dev = config.dev;
|
|
||||||
console.info(DEV_MSG);
|
|
||||||
}
|
|
||||||
if (config.env) {
|
|
||||||
this.env = Object.freeze(Object.assign({}, config.env));
|
|
||||||
}
|
|
||||||
if (config.translateFn) {
|
|
||||||
this.translateFn = config.translateFn;
|
|
||||||
}
|
|
||||||
if (config.translatableAttributes) {
|
|
||||||
this.translatableAttributes = config.translatableAttributes;
|
|
||||||
}
|
|
||||||
if (config.templates) {
|
|
||||||
this.addTemplates(config.templates);
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
mount(target: HTMLElement, options?: MountOptions): Promise<InstanceType<T>> {
|
|
||||||
if (!(target instanceof HTMLElement)) {
|
|
||||||
throw new Error("Cannot mount component: the target is not a valid DOM element");
|
|
||||||
}
|
|
||||||
if (!document.body.contains(target)) {
|
|
||||||
throw new Error("Cannot mount a component on a detached dom node");
|
|
||||||
}
|
|
||||||
const node = new ComponentNode(this.Root, this.props, this);
|
|
||||||
this.root = node;
|
|
||||||
return node.mountComponent(target, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
destroy() {
|
|
||||||
if (this.root) {
|
|
||||||
this.root.destroy();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,140 +0,0 @@
|
|||||||
import { BDom, multi, text, toggler } from "../blockdom";
|
|
||||||
import { validateProps } from "../component/props_validation";
|
|
||||||
import { Markup } from "../utils";
|
|
||||||
import { html } from "../blockdom/index";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This file contains utility functions that will be injected in each template,
|
|
||||||
* to perform various useful tasks in the compiled code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
function withDefault(value: any, defaultValue: any): any {
|
|
||||||
return value === undefined || value === null || value === false ? defaultValue : value;
|
|
||||||
}
|
|
||||||
|
|
||||||
function callSlot(
|
|
||||||
ctx: any,
|
|
||||||
parent: any,
|
|
||||||
key: string,
|
|
||||||
name: string,
|
|
||||||
dynamic: boolean,
|
|
||||||
extra: any,
|
|
||||||
defaultContent?: (ctx: any, node: any, key: string) => BDom
|
|
||||||
): BDom {
|
|
||||||
const slots = (ctx.props && ctx.props.slots) || {};
|
|
||||||
const { __render, __ctx, __scope } = slots[name] || {};
|
|
||||||
const slotScope = Object.create(__ctx || {});
|
|
||||||
if (__scope) {
|
|
||||||
slotScope[__scope] = extra || {};
|
|
||||||
}
|
|
||||||
const slotBDom = __render ? __render.call(__ctx.__owl__.component, slotScope, parent, key) : null;
|
|
||||||
if (defaultContent) {
|
|
||||||
let child1: BDom | undefined = undefined;
|
|
||||||
let child2: BDom | undefined = undefined;
|
|
||||||
if (slotBDom) {
|
|
||||||
child1 = dynamic ? toggler(name, slotBDom) : slotBDom;
|
|
||||||
} else {
|
|
||||||
child2 = defaultContent.call(ctx.__owl__.component, ctx, parent, key);
|
|
||||||
}
|
|
||||||
return multi([child1, child2]);
|
|
||||||
}
|
|
||||||
return slotBDom || text("");
|
|
||||||
}
|
|
||||||
|
|
||||||
function capture(ctx: any): any {
|
|
||||||
const component = ctx.__owl__.component;
|
|
||||||
const result = Object.create(component);
|
|
||||||
for (let k in ctx) {
|
|
||||||
result[k] = ctx[k];
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
function withKey(elem: any, k: string) {
|
|
||||||
elem.key = k;
|
|
||||||
return elem;
|
|
||||||
}
|
|
||||||
|
|
||||||
function prepareList(collection: any): [any[], any[], number, any[]] {
|
|
||||||
let keys: any[];
|
|
||||||
let values: any[];
|
|
||||||
|
|
||||||
if (Array.isArray(collection)) {
|
|
||||||
keys = collection;
|
|
||||||
values = collection;
|
|
||||||
} else if (collection) {
|
|
||||||
values = Object.keys(collection);
|
|
||||||
keys = Object.values(collection);
|
|
||||||
} else {
|
|
||||||
throw new Error("Invalid loop expression");
|
|
||||||
}
|
|
||||||
const n = values.length;
|
|
||||||
return [keys, values, n, new Array(n)];
|
|
||||||
}
|
|
||||||
|
|
||||||
const isBoundary = Symbol("isBoundary");
|
|
||||||
|
|
||||||
function setContextValue(ctx: { [key: string]: any }, key: string, value: any): void {
|
|
||||||
const ctx0 = ctx;
|
|
||||||
while (!ctx.hasOwnProperty(key) && !ctx.hasOwnProperty(isBoundary)) {
|
|
||||||
const newCtx = ctx.__proto__;
|
|
||||||
if (!newCtx) {
|
|
||||||
ctx = ctx0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
ctx = newCtx;
|
|
||||||
}
|
|
||||||
ctx[key] = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
function toNumber(val: string): number | string {
|
|
||||||
const n = parseFloat(val);
|
|
||||||
return isNaN(n) ? val : n;
|
|
||||||
}
|
|
||||||
|
|
||||||
function shallowEqual(l1: any[], l2: any[]): boolean {
|
|
||||||
for (let i = 0, l = l1.length; i < l; i++) {
|
|
||||||
if (l1[i] !== l2[i]) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Safely outputs `value` as a block depending on the nature of `value`
|
|
||||||
*/
|
|
||||||
export function safeOutput(value: any): ReturnType<typeof toggler> {
|
|
||||||
if (!value) {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
let safeKey;
|
|
||||||
let block;
|
|
||||||
if (value instanceof Markup) {
|
|
||||||
safeKey = `string_safe`;
|
|
||||||
block = html(value as string);
|
|
||||||
} else if (typeof value === "string") {
|
|
||||||
safeKey = "string_unsafe";
|
|
||||||
block = text(value);
|
|
||||||
} else {
|
|
||||||
// Assuming it is a block
|
|
||||||
safeKey = "block_safe";
|
|
||||||
block = value;
|
|
||||||
}
|
|
||||||
return toggler(safeKey, block);
|
|
||||||
}
|
|
||||||
|
|
||||||
export const UTILS = {
|
|
||||||
withDefault,
|
|
||||||
zero: Symbol("zero"),
|
|
||||||
isBoundary,
|
|
||||||
callSlot,
|
|
||||||
capture,
|
|
||||||
withKey,
|
|
||||||
prepareList,
|
|
||||||
setContextValue,
|
|
||||||
shallowEqual,
|
|
||||||
toNumber,
|
|
||||||
validateProps,
|
|
||||||
safeOutput,
|
|
||||||
};
|
|
||||||
@@ -1,99 +0,0 @@
|
|||||||
import { createBlock, html, list, multi, text, toggler } from "../blockdom";
|
|
||||||
import { compile, Template } from "../compiler";
|
|
||||||
import { component } from "../component/component_node";
|
|
||||||
import { UTILS } from "./template_helpers";
|
|
||||||
|
|
||||||
const bdom = { text, createBlock, list, multi, html, toggler, component };
|
|
||||||
|
|
||||||
export const globalTemplates: { [key: string]: string | Node } = {};
|
|
||||||
|
|
||||||
function parseXML(xml: string): Document {
|
|
||||||
const parser = new DOMParser();
|
|
||||||
|
|
||||||
const doc = parser.parseFromString(xml, "text/xml");
|
|
||||||
if (doc.getElementsByTagName("parsererror").length) {
|
|
||||||
let msg = "Invalid XML in template.";
|
|
||||||
const parsererrorText = doc.getElementsByTagName("parsererror")[0].textContent;
|
|
||||||
if (parsererrorText) {
|
|
||||||
msg += "\nThe parser has produced the following error message:\n" + parsererrorText;
|
|
||||||
const re = /\d+/g;
|
|
||||||
const firstMatch = re.exec(parsererrorText);
|
|
||||||
if (firstMatch) {
|
|
||||||
const lineNumber = Number(firstMatch[0]);
|
|
||||||
const line = xml.split("\n")[lineNumber - 1];
|
|
||||||
const secondMatch = re.exec(parsererrorText);
|
|
||||||
if (line && secondMatch) {
|
|
||||||
const columnIndex = Number(secondMatch[0]) - 1;
|
|
||||||
if (line[columnIndex]) {
|
|
||||||
msg +=
|
|
||||||
`\nThe error might be located at xml line ${lineNumber} column ${columnIndex}\n` +
|
|
||||||
`${line}\n${"-".repeat(columnIndex - 1)}^`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new Error(msg);
|
|
||||||
}
|
|
||||||
return doc;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class TemplateSet {
|
|
||||||
rawTemplates: typeof globalTemplates = Object.create(globalTemplates);
|
|
||||||
templates: { [name: string]: Template } = {};
|
|
||||||
translateFn?: (s: string) => string;
|
|
||||||
translatableAttributes?: string[];
|
|
||||||
utils: typeof UTILS;
|
|
||||||
dev?: boolean;
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
const call = (subTemplate: string, ctx: any, parent: any) => {
|
|
||||||
const template = this.getTemplate(subTemplate);
|
|
||||||
return toggler(subTemplate, template(ctx, parent));
|
|
||||||
};
|
|
||||||
|
|
||||||
const getTemplate = (name: string) => this.getTemplate(name);
|
|
||||||
this.utils = Object.assign({}, UTILS, { getTemplate, call });
|
|
||||||
}
|
|
||||||
|
|
||||||
addTemplate(name: string, template: string | Node, options: { allowDuplicate?: boolean } = {}) {
|
|
||||||
if (name in this.rawTemplates && !options.allowDuplicate) {
|
|
||||||
throw new Error(`Template ${name} already defined`);
|
|
||||||
}
|
|
||||||
this.rawTemplates[name] = template;
|
|
||||||
}
|
|
||||||
|
|
||||||
addTemplates(xml: string | Document, options: { allowDuplicate?: boolean } = {}) {
|
|
||||||
if (!xml) {
|
|
||||||
// empty string
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
xml = xml instanceof Document ? xml : parseXML(xml);
|
|
||||||
for (const template of xml.querySelectorAll("[t-name]")) {
|
|
||||||
const name = template.getAttribute("t-name")!;
|
|
||||||
template.removeAttribute("t-name");
|
|
||||||
this.addTemplate(name, template, options);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
getTemplate(name: string): Template {
|
|
||||||
if (!(name in this.templates)) {
|
|
||||||
const rawTemplate = this.rawTemplates[name];
|
|
||||||
if (rawTemplate === undefined) {
|
|
||||||
throw new Error(`Missing template: "${name}"`);
|
|
||||||
}
|
|
||||||
const templateFn = compile(rawTemplate, {
|
|
||||||
name,
|
|
||||||
dev: this.dev,
|
|
||||||
translateFn: this.translateFn,
|
|
||||||
translatableAttributes: this.translatableAttributes,
|
|
||||||
});
|
|
||||||
|
|
||||||
// first add a function to lazily get the template, in case there is a
|
|
||||||
// recursive call to the template name
|
|
||||||
this.templates[name] = (context, parent) => this.templates[name](context, parent);
|
|
||||||
const template = templateFn(bdom, this.utils);
|
|
||||||
this.templates[name] = template;
|
|
||||||
}
|
|
||||||
return this.templates[name];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -144,10 +144,10 @@ export function isProp(tag: string, key: string): boolean {
|
|||||||
case "option":
|
case "option":
|
||||||
return key === "selected" || key === "disabled";
|
return key === "selected" || key === "disabled";
|
||||||
case "textarea":
|
case "textarea":
|
||||||
return key === "value" || key === "readonly" || key === "disabled";
|
return key === "readonly" || key === "disabled";
|
||||||
case "select":
|
break;
|
||||||
return key === "value" || key === "disabled";
|
|
||||||
case "button":
|
case "button":
|
||||||
|
case "select":
|
||||||
case "optgroup":
|
case "optgroup":
|
||||||
return key === "disabled";
|
return key === "disabled";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -116,7 +116,6 @@ interface IntermediateTree {
|
|||||||
forceRef?: boolean;
|
forceRef?: boolean;
|
||||||
refIdx?: number;
|
refIdx?: number;
|
||||||
refN: number;
|
refN: number;
|
||||||
currentNS: string | null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildTree(
|
function buildTree(
|
||||||
@@ -125,10 +124,9 @@ function buildTree(
|
|||||||
domParentTree: IntermediateTree | null = null
|
domParentTree: IntermediateTree | null = null
|
||||||
): IntermediateTree {
|
): IntermediateTree {
|
||||||
switch (node.nodeType) {
|
switch (node.nodeType) {
|
||||||
case Node.ELEMENT_NODE: {
|
case 1: {
|
||||||
// HTMLElement
|
// HTMLElement
|
||||||
let isActive = false;
|
let isActive = false;
|
||||||
let currentNS = parent && parent.currentNS;
|
|
||||||
const tagName = (node as Element).tagName;
|
const tagName = (node as Element).tagName;
|
||||||
let el: Node | undefined = undefined;
|
let el: Node | undefined = undefined;
|
||||||
const info: DynamicInfo[] = [];
|
const info: DynamicInfo[] = [];
|
||||||
@@ -145,18 +143,11 @@ function buildTree(
|
|||||||
el = document.createTextNode("");
|
el = document.createTextNode("");
|
||||||
isActive = true;
|
isActive = true;
|
||||||
}
|
}
|
||||||
const attrs = (node as Element).attributes;
|
|
||||||
const ns = attrs.getNamedItem("block-ns");
|
|
||||||
if (ns) {
|
|
||||||
attrs.removeNamedItem("block-ns");
|
|
||||||
currentNS = ns.value;
|
|
||||||
}
|
|
||||||
if (!el) {
|
if (!el) {
|
||||||
el = currentNS
|
el = document.createElement(tagName);
|
||||||
? document.createElementNS(currentNS, tagName)
|
|
||||||
: document.createElement(tagName);
|
|
||||||
}
|
}
|
||||||
if (el instanceof Element) {
|
if (el instanceof HTMLElement) {
|
||||||
|
const attrs = (node as Element).attributes;
|
||||||
for (let i = 0; i < attrs.length; i++) {
|
for (let i = 0; i < attrs.length; i++) {
|
||||||
const attrName = attrs[i].name;
|
const attrName = attrs[i].name;
|
||||||
const attrValue = attrs[i].value;
|
const attrValue = attrs[i].value;
|
||||||
@@ -202,14 +193,13 @@ function buildTree(
|
|||||||
el,
|
el,
|
||||||
info,
|
info,
|
||||||
refN: isActive ? 1 : 0,
|
refN: isActive ? 1 : 0,
|
||||||
currentNS,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (node.firstChild) {
|
if (node.firstChild) {
|
||||||
const childNode = node.childNodes[0];
|
const childNode = node.childNodes[0];
|
||||||
if (
|
if (
|
||||||
node.childNodes.length === 1 &&
|
node.childNodes.length === 1 &&
|
||||||
childNode.nodeType === Node.ELEMENT_NODE &&
|
childNode.nodeType === 1 &&
|
||||||
(childNode as Element).tagName.startsWith("block-child-")
|
(childNode as Element).tagName.startsWith("block-child-")
|
||||||
) {
|
) {
|
||||||
const tagName = (childNode as Element).tagName;
|
const tagName = (childNode as Element).tagName;
|
||||||
@@ -237,11 +227,11 @@ function buildTree(
|
|||||||
}
|
}
|
||||||
return tree;
|
return tree;
|
||||||
}
|
}
|
||||||
case Node.TEXT_NODE:
|
case 3:
|
||||||
case Node.COMMENT_NODE: {
|
case 8: {
|
||||||
// text node or comment node
|
// text node or comment node
|
||||||
const el =
|
const el =
|
||||||
node.nodeType === Node.TEXT_NODE
|
node.nodeType === 3
|
||||||
? document.createTextNode(node.textContent!)
|
? document.createTextNode(node.textContent!)
|
||||||
: document.createComment(node.textContent!);
|
: document.createComment(node.textContent!);
|
||||||
return {
|
return {
|
||||||
@@ -251,7 +241,6 @@ function buildTree(
|
|||||||
el,
|
el,
|
||||||
info: [],
|
info: [],
|
||||||
refN: 0,
|
refN: 0,
|
||||||
currentNS: null,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -407,12 +396,12 @@ function updateCtx(ctx: BlockCtx, tree: IntermediateTree) {
|
|||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "handler": {
|
case "handler": {
|
||||||
const { setup, update } = createEventHandler(info.event!);
|
const setupHandler = createEventHandler(info.event!);
|
||||||
ctx.locations.push({
|
ctx.locations.push({
|
||||||
idx: info.idx,
|
idx: info.idx,
|
||||||
refIdx: info.refIdx!,
|
refIdx: info.refIdx!,
|
||||||
setData: setup,
|
setData: setupHandler,
|
||||||
updateData: update,
|
updateData: setupHandler,
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-13
@@ -1,13 +1,3 @@
|
|||||||
export function filterOutModifiersFromData(dataList: any[]): { modifiers: string[]; data: any[] } {
|
|
||||||
dataList = dataList.slice();
|
|
||||||
const modifiers = [];
|
|
||||||
let elm;
|
|
||||||
while ((elm = dataList[0]) && typeof elm === "string") {
|
|
||||||
modifiers.push(dataList.shift());
|
|
||||||
}
|
|
||||||
return { modifiers, data: dataList };
|
|
||||||
}
|
|
||||||
|
|
||||||
export const config = {
|
export const config = {
|
||||||
// whether or not blockdom should normalize DOM whenever a block is created.
|
// whether or not blockdom should normalize DOM whenever a block is created.
|
||||||
// Normalizing dom mean removing empty text nodes (or containing only spaces)
|
// Normalizing dom mean removing empty text nodes (or containing only spaces)
|
||||||
@@ -16,13 +6,11 @@ export const config = {
|
|||||||
// this is the main event handler. Every event handler registered with blockdom
|
// this is the main event handler. Every event handler registered with blockdom
|
||||||
// will go through this function, giving it the data registered in the block
|
// will go through this function, giving it the data registered in the block
|
||||||
// and the event
|
// and the event
|
||||||
mainEventHandler: (data: any, ev: Event, currentTarget?: EventTarget | null): boolean => {
|
mainEventHandler: (data: any, ev: Event) => {
|
||||||
if (typeof data === "function") {
|
if (typeof data === "function") {
|
||||||
data(ev);
|
data(ev);
|
||||||
} else if (Array.isArray(data)) {
|
} else if (Array.isArray(data)) {
|
||||||
data = filterOutModifiersFromData(data).data;
|
|
||||||
data[0](data[1], ev);
|
data[0](data[1], ev);
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
+16
-74
@@ -1,77 +1,21 @@
|
|||||||
import { config } from "./config";
|
import { config } from "./config";
|
||||||
|
|
||||||
type EventHandlerSetter = (this: HTMLElement, data: any) => void;
|
export function createEventHandler(event: string) {
|
||||||
|
setupSyntheticEvent(event);
|
||||||
interface EventHandlerCreator {
|
const key = `__event__${event}`;
|
||||||
setup: EventHandlerSetter;
|
return function setupHandler(this: HTMLElement, data: any) {
|
||||||
update: EventHandlerSetter;
|
(this as any)[key] = data;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createEventHandler(rawEvent: string): EventHandlerCreator {
|
function nativeToSyntheticEvent(event: Event, name: string) {
|
||||||
const eventName = rawEvent.split(".")[0];
|
const eventKey = `__event__${name}`;
|
||||||
const capture = rawEvent.includes(".capture");
|
|
||||||
if (rawEvent.includes(".synthetic")) {
|
|
||||||
return createSyntheticHandler(eventName, capture);
|
|
||||||
} else {
|
|
||||||
return createElementHandler(eventName, capture);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Native listener
|
|
||||||
let nextNativeEventId = 1;
|
|
||||||
function createElementHandler(evName: string, capture: boolean = false): EventHandlerCreator {
|
|
||||||
let eventKey = `__event__${evName}_${nextNativeEventId++}`;
|
|
||||||
if (capture) {
|
|
||||||
eventKey = `${eventKey}_capture`;
|
|
||||||
}
|
|
||||||
|
|
||||||
function listener(ev: Event) {
|
|
||||||
const currentTarget = ev.currentTarget;
|
|
||||||
if (!currentTarget || !document.contains(currentTarget as HTMLElement)) return;
|
|
||||||
const data = (currentTarget as any)[eventKey];
|
|
||||||
if (!data) return;
|
|
||||||
config.mainEventHandler(data, ev, currentTarget);
|
|
||||||
}
|
|
||||||
|
|
||||||
function setup(this: HTMLElement, data: any) {
|
|
||||||
(this as any)[eventKey] = data;
|
|
||||||
this.addEventListener(evName, listener, { capture });
|
|
||||||
}
|
|
||||||
|
|
||||||
function update(this: HTMLElement, data: any) {
|
|
||||||
(this as any)[eventKey] = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
return { setup, update };
|
|
||||||
}
|
|
||||||
|
|
||||||
// Synthetic handler: a form of event delegation that allows placing only one
|
|
||||||
// listener per event type.
|
|
||||||
let nextSyntheticEventId = 1;
|
|
||||||
function createSyntheticHandler(evName: string, capture: boolean = false): EventHandlerCreator {
|
|
||||||
let eventKey = `__event__synthetic_${evName}`;
|
|
||||||
if (capture) {
|
|
||||||
eventKey = `${eventKey}_capture`;
|
|
||||||
}
|
|
||||||
setupSyntheticEvent(evName, eventKey, capture);
|
|
||||||
const currentId = nextSyntheticEventId++;
|
|
||||||
function setup(this: HTMLElement, data: any) {
|
|
||||||
const _data = (this as any)[eventKey] || {};
|
|
||||||
_data[currentId] = data;
|
|
||||||
(this as any)[eventKey] = _data;
|
|
||||||
}
|
|
||||||
return { setup, update: setup };
|
|
||||||
}
|
|
||||||
|
|
||||||
function nativeToSyntheticEvent(eventKey: string, event: Event) {
|
|
||||||
let dom = event.target;
|
let dom = event.target;
|
||||||
while (dom !== null) {
|
while (dom !== null) {
|
||||||
const _data = (dom as any)[eventKey];
|
const data = (dom as any)[eventKey];
|
||||||
if (_data) {
|
if (data) {
|
||||||
for (const data of Object.values(_data)) {
|
config.mainEventHandler(data, event);
|
||||||
const stopped = config.mainEventHandler(data, event, dom);
|
return;
|
||||||
if (stopped) return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
dom = (dom as any).parentNode;
|
dom = (dom as any).parentNode;
|
||||||
}
|
}
|
||||||
@@ -79,12 +23,10 @@ function nativeToSyntheticEvent(eventKey: string, event: Event) {
|
|||||||
|
|
||||||
const CONFIGURED_SYNTHETIC_EVENTS: { [event: string]: boolean } = {};
|
const CONFIGURED_SYNTHETIC_EVENTS: { [event: string]: boolean } = {};
|
||||||
|
|
||||||
function setupSyntheticEvent(evName: string, eventKey: string, capture: boolean = false) {
|
function setupSyntheticEvent(name: string) {
|
||||||
if (CONFIGURED_SYNTHETIC_EVENTS[eventKey]) {
|
if (CONFIGURED_SYNTHETIC_EVENTS[name]) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
document.addEventListener(evName, (event) => nativeToSyntheticEvent(eventKey, event), {
|
document.addEventListener(name, (event) => nativeToSyntheticEvent(event, name));
|
||||||
capture,
|
CONFIGURED_SYNTHETIC_EVENTS[name] = true;
|
||||||
});
|
|
||||||
CONFIGURED_SYNTHETIC_EVENTS[eventKey] = true;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,8 +23,8 @@ export interface VNode<T = any> {
|
|||||||
|
|
||||||
export type BDom = VNode<any>;
|
export type BDom = VNode<any>;
|
||||||
|
|
||||||
export function mount(vnode: VNode, fixture: HTMLElement, afterNode: Node | null = null) {
|
export function mount(vnode: VNode, fixture: HTMLElement) {
|
||||||
vnode.mount(fixture, afterNode);
|
vnode.mount(fixture, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function patch(vnode1: VNode, vnode2: VNode, withBeforeRemove: boolean = false) {
|
export function patch(vnode1: VNode, vnode2: VNode, withBeforeRemove: boolean = false) {
|
||||||
|
|||||||
@@ -43,9 +43,7 @@ class VToggler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
beforeRemove() {
|
beforeRemove() {}
|
||||||
this.child.beforeRemove();
|
|
||||||
}
|
|
||||||
|
|
||||||
remove() {
|
remove() {
|
||||||
this.child.remove();
|
this.child.remove();
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
import type { BDom } from "../blockdom";
|
|
||||||
import { CodeGenerator, Config } from "./code_generator";
|
|
||||||
import { parse } from "./parser";
|
|
||||||
|
|
||||||
export type Template = (context: any, vnode: any, key?: string) => BDom;
|
|
||||||
|
|
||||||
export type TemplateFunction = (blocks: any, utils: any) => Template;
|
|
||||||
|
|
||||||
interface CompileOptions extends Config {
|
|
||||||
name?: string;
|
|
||||||
}
|
|
||||||
let nextId = 1;
|
|
||||||
export function compile(template: string | Node, options: CompileOptions = {}): TemplateFunction {
|
|
||||||
// parsing
|
|
||||||
const ast = parse(template);
|
|
||||||
|
|
||||||
// some work
|
|
||||||
const hasSafeContext =
|
|
||||||
template instanceof Node
|
|
||||||
? !(template instanceof Element) || template.querySelector("[t-set], [t-call]") === null
|
|
||||||
: !template.includes("t-set") && !template.includes("t-call");
|
|
||||||
const name = options.name || `template_${nextId++}`;
|
|
||||||
|
|
||||||
// code generation
|
|
||||||
const codeGenerator = new CodeGenerator(name, ast, { ...options, hasSafeContext });
|
|
||||||
const code = codeGenerator.generateCode();
|
|
||||||
|
|
||||||
// template function
|
|
||||||
return new Function("bdom, helpers", code) as TemplateFunction;
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
import type { Env } from "../app/app";
|
|
||||||
import type { ComponentNode } from "./component_node";
|
import type { ComponentNode } from "./component_node";
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
@@ -7,14 +6,12 @@ import type { ComponentNode } from "./component_node";
|
|||||||
|
|
||||||
export class Component {
|
export class Component {
|
||||||
static template: string = "";
|
static template: string = "";
|
||||||
static style: string = "";
|
|
||||||
static props?: any;
|
|
||||||
|
|
||||||
props: any;
|
props: any;
|
||||||
env: Env;
|
env: any;
|
||||||
__owl__: ComponentNode;
|
__owl__: ComponentNode;
|
||||||
|
|
||||||
constructor(props: any, env: Env, node: ComponentNode) {
|
constructor(props: any, env: any, node: ComponentNode) {
|
||||||
this.props = props;
|
this.props = props;
|
||||||
this.env = env;
|
this.env = env;
|
||||||
this.__owl__ = node;
|
this.__owl__ = node;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { App, Env } from "../app/app";
|
import type { App } from "../app";
|
||||||
import { BDom, VNode } from "../blockdom";
|
import { BDom, VNode } from "../blockdom";
|
||||||
import { Component } from "./component";
|
import { Component } from "./component";
|
||||||
import {
|
import {
|
||||||
@@ -6,14 +6,10 @@ import {
|
|||||||
makeChildFiber,
|
makeChildFiber,
|
||||||
makeRootFiber,
|
makeRootFiber,
|
||||||
MountFiber,
|
MountFiber,
|
||||||
MountOptions,
|
|
||||||
RootFiber,
|
RootFiber,
|
||||||
__internal__destroyed,
|
__internal__destroyed,
|
||||||
} from "./fibers";
|
} from "./fibers";
|
||||||
import { handleError, fibersInError } from "./error_handling";
|
|
||||||
import { applyDefaultProps } from "./props_validation";
|
|
||||||
import { STATUS } from "./status";
|
import { STATUS } from "./status";
|
||||||
import { applyStyles } from "./style";
|
|
||||||
|
|
||||||
export function component(
|
export function component(
|
||||||
name: string | typeof Component,
|
name: string | typeof Component,
|
||||||
@@ -25,13 +21,9 @@ export function component(
|
|||||||
let node: any = ctx.children[key];
|
let node: any = ctx.children[key];
|
||||||
let isDynamic = typeof name !== "string";
|
let isDynamic = typeof name !== "string";
|
||||||
|
|
||||||
if (node) {
|
if (node && node.status < STATUS.MOUNTED) {
|
||||||
if (node.status < STATUS.MOUNTED) {
|
node.destroy();
|
||||||
node.destroy();
|
node = undefined;
|
||||||
node = undefined;
|
|
||||||
} else if (node.status === STATUS.DESTROYED) {
|
|
||||||
node = undefined;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (isDynamic && node && node.component.constructor !== name) {
|
if (isDynamic && node && node.component.constructor !== name) {
|
||||||
node = undefined;
|
node = undefined;
|
||||||
@@ -42,16 +34,8 @@ export function component(
|
|||||||
node.updateAndRender(props, parentFiber);
|
node.updateAndRender(props, parentFiber);
|
||||||
} else {
|
} else {
|
||||||
// new component
|
// new component
|
||||||
let C;
|
const C = isDynamic ? name : parent.constructor.components[name as any];
|
||||||
if (isDynamic) {
|
node = new ComponentNode(C, props, ctx.app);
|
||||||
C = name;
|
|
||||||
} else {
|
|
||||||
C = parent.constructor.components[name as any];
|
|
||||||
if (!C) {
|
|
||||||
throw new Error(`Cannot find the definition of component "${name}"`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
node = new ComponentNode(C, props, ctx.app, ctx);
|
|
||||||
ctx.children[key] = node;
|
ctx.children[key] = node;
|
||||||
|
|
||||||
const fiber = makeChildFiber(node, parentFiber);
|
const fiber = makeChildFiber(node, parentFiber);
|
||||||
@@ -72,10 +56,9 @@ export function getCurrent(): ComponentNode | null {
|
|||||||
|
|
||||||
type LifecycleHook = Function;
|
type LifecycleHook = Function;
|
||||||
|
|
||||||
export class ComponentNode<T extends typeof Component = typeof Component>
|
export class ComponentNode<T extends typeof Component = any> implements VNode<ComponentNode> {
|
||||||
implements VNode<ComponentNode>
|
|
||||||
{
|
|
||||||
el?: HTMLElement | Text | undefined;
|
el?: HTMLElement | Text | undefined;
|
||||||
|
handlers: any = null;
|
||||||
app: App;
|
app: App;
|
||||||
fiber: Fiber | null = null;
|
fiber: Fiber | null = null;
|
||||||
component: InstanceType<T>;
|
component: InstanceType<T>;
|
||||||
@@ -83,10 +66,8 @@ export class ComponentNode<T extends typeof Component = typeof Component>
|
|||||||
status: STATUS = STATUS.NEW;
|
status: STATUS = STATUS.NEW;
|
||||||
|
|
||||||
renderFn: Function;
|
renderFn: Function;
|
||||||
parent: ComponentNode | null;
|
|
||||||
level: number;
|
|
||||||
childEnv: Env;
|
|
||||||
children: { [key: string]: ComponentNode } = Object.create(null);
|
children: { [key: string]: ComponentNode } = Object.create(null);
|
||||||
|
slots: any = {};
|
||||||
refs: any = {};
|
refs: any = {};
|
||||||
|
|
||||||
willStart: LifecycleHook[] = [];
|
willStart: LifecycleHook[] = [];
|
||||||
@@ -97,74 +78,49 @@ export class ComponentNode<T extends typeof Component = typeof Component>
|
|||||||
patched: LifecycleHook[] = [];
|
patched: LifecycleHook[] = [];
|
||||||
destroyed: LifecycleHook[] = [];
|
destroyed: LifecycleHook[] = [];
|
||||||
|
|
||||||
constructor(C: T, props: any, app: App, parent?: ComponentNode) {
|
constructor(C: T, props: any, app: App) {
|
||||||
currentNode = this;
|
currentNode = this;
|
||||||
this.app = app;
|
this.app = app;
|
||||||
this.parent = parent || null;
|
this.component = new C(props, app.env, this) as any;
|
||||||
this.level = parent ? parent.level + 1 : 0;
|
this.renderFn = app.getTemplate(C.template).bind(null, this.component, this);
|
||||||
applyDefaultProps(props, C);
|
|
||||||
const env = (parent && parent.childEnv) || app.env;
|
|
||||||
this.childEnv = env;
|
|
||||||
this.component = new C(props, env, this) as any;
|
|
||||||
this.renderFn = app.getTemplate(C.template).bind(this.component, this.component, this);
|
|
||||||
if (C.style) {
|
|
||||||
applyStyles(C);
|
|
||||||
}
|
|
||||||
this.component.setup();
|
this.component.setup();
|
||||||
}
|
}
|
||||||
|
|
||||||
mountComponent(target: any, options?: MountOptions): Promise<InstanceType<T>> {
|
mountComponent(target: any): Promise<InstanceType<T>> {
|
||||||
const fiber = new MountFiber(this, target, options);
|
const fiber = new MountFiber(this, target);
|
||||||
this.app.scheduler.addFiber(fiber);
|
this.app.scheduler.addFiber(fiber);
|
||||||
this.initiateRender(fiber);
|
this.initiateRender(fiber);
|
||||||
return fiber.promise.then(() => this.component);
|
return fiber.promise.then(() => this.component);
|
||||||
}
|
}
|
||||||
|
|
||||||
async initiateRender(fiber: Fiber | MountFiber) {
|
async initiateRender(fiber: Fiber | MountFiber) {
|
||||||
this.fiber = fiber;
|
|
||||||
if (this.mounted.length) {
|
if (this.mounted.length) {
|
||||||
fiber.root.mounted.push(fiber);
|
fiber.root.mounted.push(fiber);
|
||||||
}
|
}
|
||||||
const component = this.component;
|
const component = this.component;
|
||||||
try {
|
const prom = Promise.all(this.willStart.map((f) => f.call(component)));
|
||||||
await Promise.all(this.willStart.map((f) => f.call(component)));
|
await prom;
|
||||||
} catch (e) {
|
|
||||||
handleError({ node: this, error: e });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (this.status === STATUS.NEW && this.fiber === fiber) {
|
if (this.status === STATUS.NEW && this.fiber === fiber) {
|
||||||
this._render(fiber);
|
this._render(fiber);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async render() {
|
async render() {
|
||||||
const current = this.fiber;
|
if (this.fiber && !this.fiber.bdom) {
|
||||||
if (current && !current.bdom && !fibersInError.has(current)) {
|
return this.fiber.root.promise;
|
||||||
return current.root.promise;
|
|
||||||
}
|
}
|
||||||
if (!this.bdom && !current) {
|
if (!this.bdom && !this.fiber) {
|
||||||
// should find a way to return the future mounting promise
|
// should find a way to return the future mounting promise
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const fiber = makeRootFiber(this);
|
const fiber = makeRootFiber(this);
|
||||||
this.fiber = fiber;
|
|
||||||
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.DESTROYED) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// We only want to actually render the component if the following two
|
if (this.fiber === fiber) {
|
||||||
// conditions are true:
|
|
||||||
// * this.fiber: it could be null, in which case the render has been cancelled
|
|
||||||
// * (current || !fiber.parent): if current is not null, this means that the
|
|
||||||
// render function was called when a render was already occurring. In this
|
|
||||||
// case, the pending rendering was cancelled, and the fiber needs to be
|
|
||||||
// rendered to complete the work. If current is null, we check that the
|
|
||||||
// fiber has no parent. If that is the case, the fiber was downgraded from
|
|
||||||
// a root fiber to a child fiber in the previous microtick, because it was
|
|
||||||
// embedded in a rendering coming from above, so the fiber will be rendered
|
|
||||||
// in the next microtick anyway, so we should not render it again.
|
|
||||||
if (this.fiber && (current || !fiber.parent)) {
|
|
||||||
this._render(fiber);
|
this._render(fiber);
|
||||||
}
|
}
|
||||||
return fiber.root.promise;
|
return fiber.root.promise;
|
||||||
@@ -173,10 +129,15 @@ export class ComponentNode<T extends typeof Component = typeof Component>
|
|||||||
_render(fiber: Fiber | RootFiber) {
|
_render(fiber: Fiber | RootFiber) {
|
||||||
try {
|
try {
|
||||||
fiber.bdom = this.renderFn();
|
fiber.bdom = this.renderFn();
|
||||||
fiber.root.counter--;
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
handleError({ node: this, error: e });
|
fiber.root.error = e;
|
||||||
|
this.handleError(fiber);
|
||||||
}
|
}
|
||||||
|
fiber.root.counter--;
|
||||||
|
}
|
||||||
|
|
||||||
|
handleError(fiber: Fiber) {
|
||||||
|
fiber.node.app.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
@@ -213,7 +174,6 @@ export class ComponentNode<T extends typeof Component = typeof Component>
|
|||||||
async updateAndRender(props: any, parentFiber: Fiber) {
|
async updateAndRender(props: any, parentFiber: Fiber) {
|
||||||
// update
|
// update
|
||||||
const fiber = makeChildFiber(this, parentFiber);
|
const fiber = makeChildFiber(this, parentFiber);
|
||||||
this.fiber = fiber;
|
|
||||||
if (this.willPatch.length) {
|
if (this.willPatch.length) {
|
||||||
parentFiber.root.willPatch.push(fiber);
|
parentFiber.root.willPatch.push(fiber);
|
||||||
}
|
}
|
||||||
@@ -221,7 +181,6 @@ export class ComponentNode<T extends typeof Component = typeof Component>
|
|||||||
parentFiber.root.patched.push(fiber);
|
parentFiber.root.patched.push(fiber);
|
||||||
}
|
}
|
||||||
const component = this.component;
|
const component = this.component;
|
||||||
applyDefaultProps(props, component.constructor as any);
|
|
||||||
const prom = Promise.all(this.willUpdateProps.map((f) => f.call(component, props)));
|
const prom = Promise.all(this.willUpdateProps.map((f) => f.call(component, props)));
|
||||||
await prom;
|
await prom;
|
||||||
if (fiber !== this.fiber) {
|
if (fiber !== this.fiber) {
|
||||||
@@ -247,6 +206,18 @@ export class ComponentNode<T extends typeof Component = typeof Component>
|
|||||||
this.status = STATUS.MOUNTED;
|
this.status = STATUS.MOUNTED;
|
||||||
this.fiber!.appliedToDom = true;
|
this.fiber!.appliedToDom = true;
|
||||||
this.fiber = null;
|
this.fiber = null;
|
||||||
|
if (this.handlers) {
|
||||||
|
for (let i = 0; i < this.handlers.length; i++) {
|
||||||
|
const handler = this.handlers[i];
|
||||||
|
const eventType = handler[0];
|
||||||
|
const el = bdom.el!;
|
||||||
|
el.addEventListener(eventType, (ev: Event) => {
|
||||||
|
const info = this.handlers![i];
|
||||||
|
const [, ctx, method] = info;
|
||||||
|
(ctx.__owl__.component as any)[method](ev);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
moveBefore(other: ComponentNode | null, afterNode: Node | null) {
|
moveBefore(other: ComponentNode | null, afterNode: Node | null) {
|
||||||
|
|||||||
@@ -1,57 +0,0 @@
|
|||||||
import type { ComponentNode } from "./component_node";
|
|
||||||
import type { Fiber } from "./fibers";
|
|
||||||
|
|
||||||
// Maps fibers to thrown errors
|
|
||||||
export const fibersInError: WeakMap<Fiber, any> = new WeakMap();
|
|
||||||
export const nodeErrorHandlers: WeakMap<ComponentNode, ((error: any) => void)[]> = new WeakMap();
|
|
||||||
|
|
||||||
function _handleError(node: ComponentNode | null, error: any, isFirstRound = false): boolean {
|
|
||||||
if (!node) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
const fiber = node.fiber;
|
|
||||||
if (fiber) {
|
|
||||||
fibersInError.set(fiber, error);
|
|
||||||
}
|
|
||||||
|
|
||||||
const errorHandlers = nodeErrorHandlers.get(node);
|
|
||||||
if (errorHandlers) {
|
|
||||||
if (isFirstRound && fiber) {
|
|
||||||
fiber.root.counter--;
|
|
||||||
}
|
|
||||||
|
|
||||||
let propagate = true;
|
|
||||||
for (const h of errorHandlers) {
|
|
||||||
try {
|
|
||||||
h(error);
|
|
||||||
propagate = false;
|
|
||||||
} catch (e) {
|
|
||||||
error = e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (propagate) {
|
|
||||||
return _handleError(node.parent, error);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return _handleError(node.parent, error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type ErrorParams = { error: any } & ({ node: ComponentNode } | { fiber: Fiber });
|
|
||||||
export function handleError(params: ErrorParams) {
|
|
||||||
const error = params.error;
|
|
||||||
const node = "node" in params ? params.node : params.fiber.node;
|
|
||||||
const fiber = "fiber" in params ? params.fiber : node.fiber!;
|
|
||||||
|
|
||||||
fibersInError.set(fiber.root, error);
|
|
||||||
|
|
||||||
const handled = _handleError(node, error, true);
|
|
||||||
if (!handled) {
|
|
||||||
try {
|
|
||||||
node.app.destroy();
|
|
||||||
} catch (e) {}
|
|
||||||
}
|
|
||||||
return handled;
|
|
||||||
}
|
|
||||||
+55
-83
@@ -2,7 +2,7 @@ import type { BDom } from "../blockdom";
|
|||||||
import { mount } from "../blockdom";
|
import { mount } from "../blockdom";
|
||||||
import type { ComponentNode } from "./component_node";
|
import type { ComponentNode } from "./component_node";
|
||||||
import { STATUS } from "./status";
|
import { STATUS } from "./status";
|
||||||
import { fibersInError, handleError } from "./error_handling";
|
// import { mountBlock } from "./bdom/block";
|
||||||
|
|
||||||
export function makeChildFiber(node: ComponentNode, parent: Fiber): Fiber {
|
export function makeChildFiber(node: ComponentNode, parent: Fiber): Fiber {
|
||||||
let current = node.fiber;
|
let current = node.fiber;
|
||||||
@@ -27,10 +27,6 @@ export function makeRootFiber(node: ComponentNode): Fiber {
|
|||||||
current.children = [];
|
current.children = [];
|
||||||
root.counter++;
|
root.counter++;
|
||||||
current.bdom = null;
|
current.bdom = null;
|
||||||
if (fibersInError.has(current)) {
|
|
||||||
fibersInError.delete(current);
|
|
||||||
fibersInError.delete(root);
|
|
||||||
}
|
|
||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
const fiber = new RootFiber(node);
|
const fiber = new RootFiber(node);
|
||||||
@@ -70,6 +66,7 @@ export class Fiber {
|
|||||||
|
|
||||||
constructor(node: ComponentNode, parent: Fiber | null) {
|
constructor(node: ComponentNode, parent: Fiber | null) {
|
||||||
this.node = node;
|
this.node = node;
|
||||||
|
node.fiber = this;
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
if (parent) {
|
if (parent) {
|
||||||
const root = parent.root;
|
const root = parent.root;
|
||||||
@@ -84,6 +81,7 @@ export class Fiber {
|
|||||||
|
|
||||||
export class RootFiber extends Fiber {
|
export class RootFiber extends Fiber {
|
||||||
counter: number = 1;
|
counter: number = 1;
|
||||||
|
error: Error | null = null;
|
||||||
resolve: any;
|
resolve: any;
|
||||||
promise: Promise<any>;
|
promise: Promise<any>;
|
||||||
reject: any;
|
reject: any;
|
||||||
@@ -105,109 +103,83 @@ export class RootFiber extends Fiber {
|
|||||||
|
|
||||||
complete() {
|
complete() {
|
||||||
const node = this.node;
|
const node = this.node;
|
||||||
let current: Fiber | undefined = undefined;
|
|
||||||
try {
|
// Step 1: calling all willPatch lifecycle hooks
|
||||||
// Step 1: calling all willPatch lifecycle hooks
|
for (let fiber of this.willPatch) {
|
||||||
for (current of this.willPatch) {
|
// because of the asynchronous nature of the rendering, some parts of the
|
||||||
// because of the asynchronous nature of the rendering, some parts of the
|
// UI may have been rendered, then deleted in a followup rendering, and we
|
||||||
// UI may have been rendered, then deleted in a followup rendering, and we
|
// do not want to call onWillPatch in that case.
|
||||||
// do not want to call onWillPatch in that case.
|
let node = fiber.node;
|
||||||
let node = current.node;
|
if (node.fiber === fiber) {
|
||||||
if (node.fiber === current) {
|
const component = node.component;
|
||||||
const component = node.component;
|
for (let cb of node.willPatch) {
|
||||||
for (let cb of node.willPatch) {
|
cb.call(component);
|
||||||
cb.call(component);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
current = undefined;
|
}
|
||||||
|
|
||||||
// Step 2: patching the dom
|
// Step 2: patching the dom
|
||||||
node.bdom!.patch(this.bdom!, Object.keys(node.children).length > 0);
|
node.bdom!.patch(this.bdom!, Object.keys(node.children).length > 0);
|
||||||
this.appliedToDom = true;
|
this.appliedToDom = true;
|
||||||
|
|
||||||
// Step 3: calling all destroyed hooks
|
// Step 3: calling all destroyed hooks
|
||||||
for (let node of __internal__destroyed) {
|
for (let node of __internal__destroyed) {
|
||||||
for (let cb of node.destroyed) {
|
for (let cb of node.destroyed) {
|
||||||
|
cb();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
__internal__destroyed.length = 0;
|
||||||
|
|
||||||
|
// Step 4: calling all mounted lifecycle hooks
|
||||||
|
let current;
|
||||||
|
let mountedFibers = this.mounted;
|
||||||
|
while ((current = mountedFibers.pop())) {
|
||||||
|
if (current.appliedToDom) {
|
||||||
|
for (let cb of current.node.mounted) {
|
||||||
cb();
|
cb();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
__internal__destroyed.length = 0;
|
}
|
||||||
|
|
||||||
// Step 4: calling all mounted lifecycle hooks
|
// Step 5: calling all patched hooks
|
||||||
let mountedFibers = this.mounted;
|
let patchedFibers = this.patched;
|
||||||
while ((current = mountedFibers.pop())) {
|
while ((current = patchedFibers.pop())) {
|
||||||
current = current;
|
if (current.appliedToDom) {
|
||||||
if (current.appliedToDom) {
|
for (let cb of current.node.patched) {
|
||||||
for (let cb of current.node.mounted) {
|
cb();
|
||||||
cb();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 5: calling all patched hooks
|
|
||||||
let patchedFibers = this.patched;
|
|
||||||
while ((current = patchedFibers.pop())) {
|
|
||||||
current = current;
|
|
||||||
if (current.appliedToDom) {
|
|
||||||
for (let cb of current.node.patched) {
|
|
||||||
cb();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// unregistering the fiber
|
|
||||||
node.fiber = null;
|
|
||||||
} catch (e) {
|
|
||||||
if (!handleError({ fiber: current || this, error: e })) {
|
|
||||||
this.reject(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// unregistering the fiber
|
||||||
|
node.fiber = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export let __internal__destroyed: ComponentNode[] = [];
|
export let __internal__destroyed: ComponentNode[] = [];
|
||||||
|
|
||||||
type Position = "first-child" | "last-child";
|
|
||||||
|
|
||||||
export interface MountOptions {
|
|
||||||
position?: Position;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class MountFiber extends RootFiber {
|
export class MountFiber extends RootFiber {
|
||||||
target: HTMLElement;
|
target: HTMLElement;
|
||||||
position: Position;
|
|
||||||
|
|
||||||
constructor(node: ComponentNode, target: HTMLElement, options: MountOptions = {}) {
|
constructor(node: ComponentNode, target: HTMLElement) {
|
||||||
super(node);
|
super(node);
|
||||||
this.target = target;
|
this.target = target;
|
||||||
this.position = options.position || "last-child";
|
|
||||||
}
|
}
|
||||||
complete() {
|
complete() {
|
||||||
let current: Fiber | undefined = this;
|
const node = this.node;
|
||||||
try {
|
node.bdom = this.bdom;
|
||||||
const node = this.node;
|
mount(node.bdom!, this.target);
|
||||||
node.bdom = this.bdom;
|
node.status = STATUS.MOUNTED;
|
||||||
if (this.position === "last-child" || this.target.childNodes.length === 0) {
|
this.appliedToDom = true;
|
||||||
mount(node.bdom!, this.target);
|
let current;
|
||||||
} else {
|
let mountedFibers = this.mounted;
|
||||||
const firstChild = this.target.childNodes[0];
|
while ((current = mountedFibers.pop())) {
|
||||||
mount(node.bdom!, this.target, firstChild);
|
if (current.appliedToDom) {
|
||||||
}
|
for (let cb of current.node.mounted) {
|
||||||
node.status = STATUS.MOUNTED;
|
cb();
|
||||||
this.appliedToDom = true;
|
|
||||||
let mountedFibers = this.mounted;
|
|
||||||
while ((current = mountedFibers.pop())) {
|
|
||||||
if (current.appliedToDom) {
|
|
||||||
for (let cb of current.node.mounted) {
|
|
||||||
cb();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
node.fiber = null;
|
|
||||||
} catch (e) {
|
|
||||||
if (!handleError({ fiber: current as Fiber, error: e })) {
|
|
||||||
this.reject(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
node.fiber = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,36 +1,10 @@
|
|||||||
import { filterOutModifiersFromData } from "../blockdom/config";
|
export function mainEventHandler(data: any, ev: Event) {
|
||||||
|
if (typeof data === "function") {
|
||||||
export const mainEventHandler = (data: any, ev: Event, currentTarget?: EventTarget | null) => {
|
data(ev);
|
||||||
const { data: _data, modifiers } = filterOutModifiersFromData(data);
|
} else {
|
||||||
data = _data;
|
const ctx = data[0];
|
||||||
let stopped = false;
|
const method = data[1];
|
||||||
if (modifiers.length) {
|
const args = data[2] || [];
|
||||||
let selfMode = false;
|
ctx.__owl__.component[method](...args, ev);
|
||||||
const isSelf = ev.target === currentTarget;
|
|
||||||
for (const mod of modifiers) {
|
|
||||||
switch (mod) {
|
|
||||||
case "self":
|
|
||||||
selfMode = true;
|
|
||||||
if (isSelf) {
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
return stopped;
|
|
||||||
}
|
|
||||||
case "prevent":
|
|
||||||
if ((selfMode && isSelf) || !selfMode) ev.preventDefault();
|
|
||||||
continue;
|
|
||||||
case "stop":
|
|
||||||
if ((selfMode && isSelf) || !selfMode) ev.stopPropagation();
|
|
||||||
stopped = true;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// If handler is empty, the array slot 0 will also be empty, and data will not have the property 0
|
}
|
||||||
// We check this rather than data[0] being truthy (or typeof function) so that it crashes
|
|
||||||
// as expected when there is a handler expression that evaluates to a falsy value
|
|
||||||
if (Object.hasOwnProperty.call(data, 0)) {
|
|
||||||
data[0].call(data[1] ? data[1].__owl__.component : null, ev);
|
|
||||||
}
|
|
||||||
return stopped;
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -1,137 +0,0 @@
|
|||||||
import { Component } from "./component";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Apply default props (only top level).
|
|
||||||
*
|
|
||||||
* Note that this method does modify in place the props
|
|
||||||
*/
|
|
||||||
export function applyDefaultProps(props: { [key: string]: any }, ComponentClass: typeof Component) {
|
|
||||||
const defaultProps = (ComponentClass as any).defaultProps;
|
|
||||||
if (defaultProps) {
|
|
||||||
for (let propName in defaultProps) {
|
|
||||||
if (props![propName] === undefined) {
|
|
||||||
props![propName] = defaultProps[propName];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Prop validation helper
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validate the component props (or next props) against the (static) props
|
|
||||||
* description. This is potentially an expensive operation: it may needs to
|
|
||||||
* visit recursively the props and all the children to check if they are valid.
|
|
||||||
* This is why it is only done in 'dev' mode.
|
|
||||||
*/
|
|
||||||
export const validateProps = function (name: string | typeof Component, props: any, parent?: any) {
|
|
||||||
const ComponentClass = (
|
|
||||||
typeof name !== "string" ? name : parent.constructor.components[name]
|
|
||||||
) as typeof Component;
|
|
||||||
|
|
||||||
applyDefaultProps(props, ComponentClass);
|
|
||||||
|
|
||||||
const propsDef = ComponentClass.props;
|
|
||||||
if (propsDef instanceof Array) {
|
|
||||||
// list of strings (prop names)
|
|
||||||
for (const propName of propsDef) {
|
|
||||||
if (propName[propName.length - 1] === "?") {
|
|
||||||
// optional prop
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (!(propName in props)) {
|
|
||||||
throw new Error(`Missing props '${propName}' (component '${ComponentClass.name}')`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (let key in props) {
|
|
||||||
if (!propsDef.includes(key) && !propsDef.includes(key + "?")) {
|
|
||||||
throw new Error(`Unknown prop '${key}' given to component '${ComponentClass.name}'`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (propsDef) {
|
|
||||||
// propsDef is an object now
|
|
||||||
for (let propName in propsDef) {
|
|
||||||
if (props[propName] === undefined) {
|
|
||||||
if (propsDef[propName] && !propsDef[propName].optional) {
|
|
||||||
throw new Error(`Missing props '${propName}' (component '${ComponentClass.name}')`);
|
|
||||||
} else {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let isValid;
|
|
||||||
try {
|
|
||||||
isValid = isValidProp(props[propName], propsDef[propName]);
|
|
||||||
} catch (e) {
|
|
||||||
(e as Error).message = `Invalid prop '${propName}' in component ${ComponentClass.name} (${
|
|
||||||
(e as Error).message
|
|
||||||
})`;
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
if (!isValid) {
|
|
||||||
throw new Error(`Invalid Prop '${propName}' in component '${ComponentClass.name}'`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (let propName in props) {
|
|
||||||
if (!(propName in propsDef)) {
|
|
||||||
throw new Error(`Unknown prop '${propName}' given to component '${ComponentClass.name}'`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if an invidual prop value matches its (static) prop definition
|
|
||||||
*/
|
|
||||||
function isValidProp(prop: any, propDef: any): boolean {
|
|
||||||
if (propDef === true) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (typeof propDef === "function") {
|
|
||||||
// Check if a value is constructed by some Constructor. Note that there is a
|
|
||||||
// slight abuse of language: we want to consider primitive values as well.
|
|
||||||
//
|
|
||||||
// So, even though 1 is not an instance of Number, we want to consider that
|
|
||||||
// it is valid.
|
|
||||||
if (typeof prop === "object") {
|
|
||||||
return prop instanceof propDef;
|
|
||||||
}
|
|
||||||
return typeof prop === propDef.name.toLowerCase();
|
|
||||||
} else if (propDef instanceof Array) {
|
|
||||||
// If this code is executed, this means that we want to check if a prop
|
|
||||||
// matches at least one of its descriptor.
|
|
||||||
let result = false;
|
|
||||||
for (let i = 0, iLen = propDef.length; i < iLen; i++) {
|
|
||||||
result = result || isValidProp(prop, propDef[i]);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
// propsDef is an object
|
|
||||||
if (propDef.optional && prop === undefined) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
let result = propDef.type ? isValidProp(prop, propDef.type) : true;
|
|
||||||
if (propDef.validate) {
|
|
||||||
result = result && propDef.validate(prop);
|
|
||||||
}
|
|
||||||
if (propDef.type === Array && propDef.element) {
|
|
||||||
for (let i = 0, iLen = prop.length; i < iLen; i++) {
|
|
||||||
result = result && isValidProp(prop[i], propDef.element);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (propDef.type === Object && propDef.shape) {
|
|
||||||
const shape = propDef.shape;
|
|
||||||
for (let key in shape) {
|
|
||||||
result = result && isValidProp(prop[key], shape[key]);
|
|
||||||
}
|
|
||||||
if (result) {
|
|
||||||
for (let propName in prop) {
|
|
||||||
if (!(propName in shape)) {
|
|
||||||
throw new Error(`unknown prop '${propName}'`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
import { Fiber, RootFiber } from "./fibers";
|
import { Fiber, RootFiber } from "./fibers";
|
||||||
import { fibersInError } from "./error_handling";
|
|
||||||
import { STATUS } from "./status";
|
import { STATUS } from "./status";
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
@@ -47,22 +46,20 @@ export class Scheduler {
|
|||||||
this.tasks.delete(fiber);
|
this.tasks.delete(fiber);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const hasError = fibersInError.has(fiber);
|
if (fiber.error) {
|
||||||
if (hasError && fiber.counter !== 0) {
|
|
||||||
this.tasks.delete(fiber);
|
this.tasks.delete(fiber);
|
||||||
fiber.reject(fibersInError.get(fiber));
|
fiber.reject(fiber.error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (fiber.node.status === STATUS.DESTROYED) {
|
if (fiber.node.status === STATUS.DESTROYED) {
|
||||||
this.tasks.delete(fiber);
|
this.tasks.delete(fiber);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fiber.counter === 0) {
|
if (fiber.counter === 0) {
|
||||||
if (!hasError) {
|
if (!fiber.error) {
|
||||||
fiber.complete();
|
fiber.complete();
|
||||||
fiber.resolve();
|
|
||||||
}
|
}
|
||||||
|
fiber.resolve();
|
||||||
this.tasks.delete(fiber);
|
this.tasks.delete(fiber);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,88 +0,0 @@
|
|||||||
import { Component } from "./component";
|
|
||||||
|
|
||||||
export const globalStylesheets: { [key: string]: HTMLStyleElement } = {};
|
|
||||||
|
|
||||||
export function registerSheet(id: string, css: string) {
|
|
||||||
const sheet = document.createElement("style");
|
|
||||||
sheet.innerHTML = processSheet(css);
|
|
||||||
globalStylesheets[id] = sheet;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Apply the stylesheets defined by the component. Note that we need to make
|
|
||||||
* sure all inherited stylesheets are applied as well, in a reverse order to
|
|
||||||
* ensure that <style/> will be applied to the DOM in the order they are
|
|
||||||
* included in the document. We then delete the `style` key from the constructor
|
|
||||||
* to make sure we do not apply it again.
|
|
||||||
*/
|
|
||||||
export function applyStyles(ComponentClass: typeof Component) {
|
|
||||||
const toApply: [string, string][] = [];
|
|
||||||
while (ComponentClass && ComponentClass.style) {
|
|
||||||
if (ComponentClass.hasOwnProperty("style")) {
|
|
||||||
toApply.push([ComponentClass.style, ComponentClass.name]);
|
|
||||||
delete (ComponentClass as any).style;
|
|
||||||
}
|
|
||||||
ComponentClass = Object.getPrototypeOf(ComponentClass);
|
|
||||||
}
|
|
||||||
while (toApply.length) {
|
|
||||||
const [styleId, componentName] = toApply.pop()!;
|
|
||||||
activateSheet(styleId, componentName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function activateSheet(id: string, name: string) {
|
|
||||||
const sheet = globalStylesheets[id];
|
|
||||||
if (!sheet) {
|
|
||||||
throw new Error(
|
|
||||||
`Invalid css stylesheet for component '${name}'. Did you forget to use the 'css' tag helper?`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
sheet.dataset.component = name;
|
|
||||||
document.head.appendChild(sheet);
|
|
||||||
}
|
|
||||||
|
|
||||||
function processSheet(str: string): string {
|
|
||||||
const tokens = str.split(/(\{|\}|;)/).map((s) => s.trim());
|
|
||||||
const selectorStack: string[][] = [];
|
|
||||||
const parts: string[] = [];
|
|
||||||
let rules: string[] = [];
|
|
||||||
function generateSelector(stackIndex: number, parentSelector?: string) {
|
|
||||||
const parts: string[] = [];
|
|
||||||
for (const selector of selectorStack[stackIndex]) {
|
|
||||||
let part = (parentSelector && parentSelector + " " + selector) || selector;
|
|
||||||
if (part.includes("&")) {
|
|
||||||
part = selector.replace(/&/g, parentSelector || "");
|
|
||||||
}
|
|
||||||
if (stackIndex < selectorStack.length - 1) {
|
|
||||||
part = generateSelector(stackIndex + 1, part);
|
|
||||||
}
|
|
||||||
parts.push(part);
|
|
||||||
}
|
|
||||||
return parts.join(", ");
|
|
||||||
}
|
|
||||||
function generateRules() {
|
|
||||||
if (rules.length) {
|
|
||||||
parts.push(generateSelector(0) + " {");
|
|
||||||
parts.push(...rules);
|
|
||||||
parts.push("}");
|
|
||||||
rules = [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (tokens.length) {
|
|
||||||
let token = tokens.shift()!;
|
|
||||||
if (token === "}") {
|
|
||||||
generateRules();
|
|
||||||
selectorStack.pop();
|
|
||||||
} else {
|
|
||||||
if (tokens[0] === "{") {
|
|
||||||
generateRules();
|
|
||||||
selectorStack.push(token.split(/\s*,\s*/));
|
|
||||||
tokens.shift();
|
|
||||||
}
|
|
||||||
if (tokens[0] === ";") {
|
|
||||||
rules.push(" " + token + ";");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return parts.join("\n");
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
export class EventBus extends EventTarget {
|
||||||
|
trigger(name: string, payload?: any) {
|
||||||
|
this.dispatchEvent(new CustomEvent(name, { detail: payload }));
|
||||||
|
}
|
||||||
|
}
|
||||||
-121
@@ -1,121 +0,0 @@
|
|||||||
import type { Env } from "./app/app";
|
|
||||||
import { getCurrent } from "./component/component_node";
|
|
||||||
import { onMounted, onPatched, onWillPatch, onWillUnmount } from "./component/lifecycle_hooks";
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
// useRef
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The purpose of this hook is to allow components to get a reference to a sub
|
|
||||||
* html node or component.
|
|
||||||
*/
|
|
||||||
export function useRef<T extends HTMLElement = HTMLElement>(name: string): { el: T | null } {
|
|
||||||
const node = getCurrent()!;
|
|
||||||
return {
|
|
||||||
get el(): T | null {
|
|
||||||
return node.refs[name] || null;
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
// useEnv and useSubEnv
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This hook is useful as a building block for some customized hooks, that may
|
|
||||||
* need a reference to the env of the component calling them.
|
|
||||||
*/
|
|
||||||
export function useEnv<E extends Env>(): E {
|
|
||||||
return getCurrent()!.component.env as any;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This hook is a simple way to let components use a sub environment. Note that
|
|
||||||
* like for all hooks, it is important that this is only called in the
|
|
||||||
* constructor method.
|
|
||||||
*/
|
|
||||||
export function useSubEnv(envExtension: Env) {
|
|
||||||
const node = getCurrent()!;
|
|
||||||
node.childEnv = Object.freeze(Object.assign({}, node.childEnv, envExtension));
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
// useEffect
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
const NO_OP = () => {};
|
|
||||||
/**
|
|
||||||
* @param {...any} dependencies the dependencies computed by computeDependencies
|
|
||||||
* @returns {void|(()=>void)} a cleanup function that reverses the side
|
|
||||||
* effects of the effect callback.
|
|
||||||
*/
|
|
||||||
type Effect = (...dependencies: any[]) => void | (() => void);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This hook will run a callback when a component is mounted and patched, and
|
|
||||||
* will run a cleanup function before patching and before unmounting the
|
|
||||||
* the component.
|
|
||||||
*
|
|
||||||
* @param {Effect} effect the effect to run on component mount and/or patch
|
|
||||||
* @param {()=>any[]} [computeDependencies=()=>[NaN]] a callback to compute
|
|
||||||
* 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
|
|
||||||
* again. The default value returns an array containing only NaN because
|
|
||||||
* NaN !== NaN, which will cause the effect to rerun on every patch.
|
|
||||||
*/
|
|
||||||
export function useEffect(effect: Effect, computeDependencies: () => any[] = () => [NaN]) {
|
|
||||||
let cleanup: () => void;
|
|
||||||
let dependencies: any[];
|
|
||||||
onMounted(() => {
|
|
||||||
dependencies = computeDependencies();
|
|
||||||
cleanup = effect(...dependencies) || NO_OP;
|
|
||||||
});
|
|
||||||
|
|
||||||
let shouldReapplyOnPatch = false;
|
|
||||||
onWillPatch(() => {
|
|
||||||
const newDeps = computeDependencies();
|
|
||||||
shouldReapplyOnPatch = newDeps.some((val, i) => val !== dependencies[i]);
|
|
||||||
if (shouldReapplyOnPatch) {
|
|
||||||
cleanup();
|
|
||||||
dependencies = newDeps;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
onPatched(() => {
|
|
||||||
if (shouldReapplyOnPatch) {
|
|
||||||
cleanup = effect(...dependencies) || NO_OP;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
onWillUnmount(() => cleanup());
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
// useExternalListener
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* When a component needs to listen to DOM Events on element(s) that are not
|
|
||||||
* part of his hierarchy, we can use the `useExternalListener` hook.
|
|
||||||
* It will correctly add and remove the event listener, whenever the
|
|
||||||
* component is mounted and unmounted.
|
|
||||||
*
|
|
||||||
* Example:
|
|
||||||
* a menu needs to listen to the click on window to be closed automatically
|
|
||||||
*
|
|
||||||
* Usage:
|
|
||||||
* in the constructor of the OWL component that needs to be notified,
|
|
||||||
* `useExternalListener(window, 'click', this._doSomething);`
|
|
||||||
* */
|
|
||||||
export function useExternalListener(
|
|
||||||
target: HTMLElement | typeof window,
|
|
||||||
eventName: string,
|
|
||||||
handler: EventListener,
|
|
||||||
eventParams?: AddEventListenerOptions
|
|
||||||
) {
|
|
||||||
const node = getCurrent()!;
|
|
||||||
const boundHandler = handler.bind(node.component);
|
|
||||||
onMounted(() => target.addEventListener(eventName, boundHandler, eventParams));
|
|
||||||
onWillUnmount(() => target.removeEventListener(eventName, boundHandler, eventParams));
|
|
||||||
}
|
|
||||||
+13
-15
@@ -30,20 +30,20 @@ export const blockDom = {
|
|||||||
html,
|
html,
|
||||||
};
|
};
|
||||||
|
|
||||||
import type { AppConfig } from "./app/app";
|
// import { makeBlockClass } from "./_old_bdom/element";
|
||||||
import { App } from "./app/app";
|
import { App } from "./app";
|
||||||
import { Component } from "./component/component";
|
import { Component } from "./component/component";
|
||||||
import { getCurrent } from "./component/component_node";
|
import { getCurrent } from "./component/component_node";
|
||||||
|
// import { getCurrent } from "./b_node";
|
||||||
|
|
||||||
export { App, Component };
|
export { App, Component };
|
||||||
|
|
||||||
export async function mount<T extends typeof Component>(
|
export async function mount<T extends typeof Component>(
|
||||||
C: T,
|
C: T,
|
||||||
target: HTMLElement,
|
target: HTMLElement
|
||||||
config: AppConfig = {}
|
|
||||||
): Promise<InstanceType<T>> {
|
): Promise<InstanceType<T>> {
|
||||||
const app = new App(C);
|
const app = new App(C);
|
||||||
return app.configure(config).mount(target);
|
return app.mount(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useComponent(): Component {
|
export function useComponent(): Component {
|
||||||
@@ -52,12 +52,12 @@ export function useComponent(): Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export { status } from "./component/status";
|
export { status } from "./component/status";
|
||||||
export { Portal } from "./portal";
|
export { Portal } from "./misc/portal";
|
||||||
export { Memo } from "./memo";
|
export { Memo } from "./misc/memo";
|
||||||
export { css, xml } from "./tags";
|
export { xml } from "./tags";
|
||||||
export { useState, reactive } from "./reactivity";
|
export { useState } from "./reactivity";
|
||||||
export { useEffect, useEnv, useExternalListener, useRef, useSubEnv } from "./hooks";
|
export { useRef } from "./refs";
|
||||||
export { EventBus, whenReady, loadFile, markup } from "./utils";
|
export { EventBus } from "./event_bus";
|
||||||
|
|
||||||
export {
|
export {
|
||||||
onWillStart,
|
onWillStart,
|
||||||
@@ -66,10 +66,8 @@ export {
|
|||||||
onWillUpdateProps,
|
onWillUpdateProps,
|
||||||
onWillPatch,
|
onWillPatch,
|
||||||
onPatched,
|
onPatched,
|
||||||
onWillRender,
|
onRender,
|
||||||
onRendered,
|
|
||||||
onDestroyed,
|
onDestroyed,
|
||||||
onError,
|
} from "./lifecycle_hooks";
|
||||||
} from "./component/lifecycle_hooks";
|
|
||||||
|
|
||||||
export const __info__ = {};
|
export const __info__ = {};
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { getCurrent } from "./component_node";
|
import { getCurrent } from "./component/component_node";
|
||||||
import { nodeErrorHandlers } from "./error_handling";
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// hooks
|
// hooks
|
||||||
@@ -22,7 +21,7 @@ export function onMounted(fn: () => void | any) {
|
|||||||
|
|
||||||
export function onWillPatch(fn: () => Promise<void> | any | void) {
|
export function onWillPatch(fn: () => Promise<void> | any | void) {
|
||||||
const node = getCurrent()!;
|
const node = getCurrent()!;
|
||||||
node.willPatch.unshift(fn);
|
node.willPatch.push(fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function onPatched(fn: () => void | any) {
|
export function onPatched(fn: () => void | any) {
|
||||||
@@ -32,7 +31,7 @@ export function onPatched(fn: () => void | any) {
|
|||||||
|
|
||||||
export function onWillUnmount(fn: () => Promise<void> | void | any) {
|
export function onWillUnmount(fn: () => Promise<void> | void | any) {
|
||||||
const node = getCurrent()!;
|
const node = getCurrent()!;
|
||||||
node.willUnmount.unshift(fn);
|
node.willUnmount.push(fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function onDestroyed(fn: () => Promise<void> | void | any) {
|
export function onDestroyed(fn: () => Promise<void> | void | any) {
|
||||||
@@ -40,7 +39,7 @@ export function onDestroyed(fn: () => Promise<void> | void | any) {
|
|||||||
node.destroyed.push(fn);
|
node.destroyed.push(fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function onWillRender(fn: () => void | any) {
|
export function onRender(fn: () => void | any) {
|
||||||
const node = getCurrent()!;
|
const node = getCurrent()!;
|
||||||
const renderFn = node.renderFn;
|
const renderFn = node.renderFn;
|
||||||
node.renderFn = () => {
|
node.renderFn = () => {
|
||||||
@@ -48,25 +47,3 @@ export function onWillRender(fn: () => void | any) {
|
|||||||
return renderFn();
|
return renderFn();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function onRendered(fn: () => void | any) {
|
|
||||||
const node = getCurrent()!;
|
|
||||||
const renderFn = node.renderFn;
|
|
||||||
node.renderFn = () => {
|
|
||||||
const result = renderFn();
|
|
||||||
fn();
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function onError(fn: (error: Error) => void | any) {
|
|
||||||
const node = getCurrent()!;
|
|
||||||
let handlers = nodeErrorHandlers.get(node);
|
|
||||||
if (handlers) {
|
|
||||||
handlers.push(fn);
|
|
||||||
} else {
|
|
||||||
handlers = [];
|
|
||||||
handlers.push(fn);
|
|
||||||
nodeErrorHandlers.set(node, handlers);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Component } from "./component/component";
|
import { Component } from "../component/component";
|
||||||
import type { ComponentNode } from "./component/component_node";
|
import type { ComponentNode } from "../component/component_node";
|
||||||
import { xml } from "./tags";
|
import { xml } from "../tags";
|
||||||
import { Fiber } from "./component/fibers";
|
import { Fiber } from "../component/fibers";
|
||||||
|
|
||||||
export class Memo extends Component {
|
export class Memo extends Component {
|
||||||
static template = xml`<t t-slot="default"/>`;
|
static template = xml`<t t-slot="default"/>`;
|
||||||
@@ -39,7 +39,7 @@ export class Memo extends Component {
|
|||||||
*/
|
*/
|
||||||
function shallowEqual(p1: any, p2: any): boolean {
|
function shallowEqual(p1: any, p2: any): boolean {
|
||||||
for (let k in p1) {
|
for (let k in p1) {
|
||||||
if (k !== "slots" && p1[k] !== p2[k]) {
|
if (p1[k] !== p2[k]) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { ComponentNode } from "./component/component_node";
|
import type { ComponentNode } from "../component/component_node";
|
||||||
import { Component } from "./component/component";
|
import { Component } from "../component/component";
|
||||||
import { xml } from "./tags";
|
import { xml } from "../tags";
|
||||||
import { BDom, text, VNode } from "./blockdom";
|
import { BDom, text, VNode } from "../blockdom";
|
||||||
|
|
||||||
const VText: any = text("").constructor;
|
const VText: any = text("").constructor;
|
||||||
|
|
||||||
@@ -53,11 +53,6 @@ class VPortal extends VText implements Partial<VNode<VPortal>> {
|
|||||||
|
|
||||||
export class Portal extends Component {
|
export class Portal extends Component {
|
||||||
static template = xml`<t t-slot="default"/>`;
|
static template = xml`<t t-slot="default"/>`;
|
||||||
static props = {
|
|
||||||
target: {
|
|
||||||
type: String,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
constructor(props: any, env: any, node: ComponentNode) {
|
constructor(props: any, env: any, node: ComponentNode) {
|
||||||
super(props, env, node);
|
super(props, env, node);
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { BDom } from "../blockdom";
|
||||||
import { compileExpr, compileExprToArray, interpolate, INTERP_REGEXP } from "./inline_expressions";
|
import { compileExpr, compileExprToArray, interpolate, INTERP_REGEXP } from "./inline_expressions";
|
||||||
import {
|
import {
|
||||||
AST,
|
AST,
|
||||||
@@ -15,22 +16,20 @@ import {
|
|||||||
ASTTForEach,
|
ASTTForEach,
|
||||||
ASTTif,
|
ASTTif,
|
||||||
ASTTKey,
|
ASTTKey,
|
||||||
ASTTOut,
|
ASTTRaw,
|
||||||
ASTTSet,
|
ASTTSet,
|
||||||
ASTTranslation,
|
|
||||||
ASTType,
|
ASTType,
|
||||||
|
parse,
|
||||||
} from "./parser";
|
} from "./parser";
|
||||||
|
|
||||||
|
export type Template = (context: any, vnode: any, key?: string) => BDom;
|
||||||
|
export type TemplateFunction = (blocks: any, utils: any) => Template;
|
||||||
|
|
||||||
type BlockType = "block" | "text" | "multi" | "list" | "html";
|
type BlockType = "block" | "text" | "multi" | "list" | "html";
|
||||||
|
|
||||||
export interface Config {
|
export function compileTemplate(template: string, name?: string): TemplateFunction {
|
||||||
translateFn?: (s: string) => string;
|
const compiler = new QWebCompiler(template, name);
|
||||||
translatableAttributes?: string[];
|
return compiler.compile();
|
||||||
dev?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface CodeGenOptions extends Config {
|
|
||||||
hasSafeContext?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// using a non-html document so that <inner/outer>HTML serializes as XML instead
|
// using a non-html document so that <inner/outer>HTML serializes as XML instead
|
||||||
@@ -47,7 +46,6 @@ class BlockDescription {
|
|||||||
|
|
||||||
varName: string;
|
varName: string;
|
||||||
blockName: string;
|
blockName: string;
|
||||||
dynamicTagName: string | null = null;
|
|
||||||
isRoot: boolean = false;
|
isRoot: boolean = false;
|
||||||
hasDynamicChildren: boolean = false;
|
hasDynamicChildren: boolean = false;
|
||||||
children: BlockDescription[] = [];
|
children: BlockDescription[] = [];
|
||||||
@@ -89,12 +87,9 @@ class BlockDescription {
|
|||||||
if (hasChildren) {
|
if (hasChildren) {
|
||||||
params += ", [" + this.children.map((c) => c.varName).join(", ") + "]";
|
params += ", [" + this.children.map((c) => c.varName).join(", ") + "]";
|
||||||
}
|
}
|
||||||
if (this.dynamicTagName) {
|
|
||||||
return `toggler(${this.dynamicTagName}, ${this.blockName}(${this.dynamicTagName})(${params}))`;
|
|
||||||
}
|
|
||||||
return `${this.blockName}(${params})`;
|
return `${this.blockName}(${params})`;
|
||||||
} else if (this.type === "list") {
|
} else if (this.type === "list") {
|
||||||
return `list(c_block${this.id})`;
|
return `list(c${this.id})`;
|
||||||
}
|
}
|
||||||
return expr;
|
return expr;
|
||||||
}
|
}
|
||||||
@@ -102,7 +97,7 @@ class BlockDescription {
|
|||||||
asXmlString() {
|
asXmlString() {
|
||||||
// Can't use outerHTML on text/comment nodes
|
// Can't use outerHTML on text/comment nodes
|
||||||
// append dom to any element and use innerHTML instead
|
// append dom to any element and use innerHTML instead
|
||||||
const t = xmlDoc.createElement("t");
|
const t = xmlDoc.createElement('t');
|
||||||
t.appendChild(this.dom!);
|
t.appendChild(this.dom!);
|
||||||
return t.innerHTML;
|
return t.innerHTML;
|
||||||
}
|
}
|
||||||
@@ -111,6 +106,7 @@ class BlockDescription {
|
|||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Compiler code
|
// Compiler code
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
const FNAMEREGEXP = /^[$A-Z_][0-9A-Z_$]*$/i;
|
||||||
|
|
||||||
interface Context {
|
interface Context {
|
||||||
block: BlockDescription | null;
|
block: BlockDescription | null;
|
||||||
@@ -118,25 +114,11 @@ interface Context {
|
|||||||
forceNewBlock: boolean;
|
forceNewBlock: boolean;
|
||||||
preventRoot?: boolean;
|
preventRoot?: boolean;
|
||||||
isLast?: boolean;
|
isLast?: boolean;
|
||||||
translate: boolean;
|
|
||||||
tKeyExpr: string | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
function createContext(parentCtx: Context, params?: Partial<Context>) {
|
|
||||||
return Object.assign(
|
|
||||||
{
|
|
||||||
block: null,
|
|
||||||
index: 0,
|
|
||||||
forceNewBlock: true,
|
|
||||||
translate: parentCtx.translate,
|
|
||||||
tKeyExpr: null,
|
|
||||||
},
|
|
||||||
params
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class CodeTarget {
|
class CodeTarget {
|
||||||
name: string;
|
name: string;
|
||||||
|
signature: string = "";
|
||||||
indentLevel = 0;
|
indentLevel = 0;
|
||||||
loopLevel = 0;
|
loopLevel = 0;
|
||||||
code: string[] = [];
|
code: string[] = [];
|
||||||
@@ -157,117 +139,48 @@ class CodeTarget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const TRANSLATABLE_ATTRS = ["label", "title", "placeholder", "alt"];
|
export class QWebCompiler {
|
||||||
const translationRE = /^(\s*)([\s\S]+?)(\s*)$/;
|
|
||||||
|
|
||||||
export class CodeGenerator {
|
|
||||||
blocks: BlockDescription[] = [];
|
blocks: BlockDescription[] = [];
|
||||||
nextId = 1;
|
nextId = 1;
|
||||||
nextBlockId = 1;
|
nextBlockId = 1;
|
||||||
shouldProtectScope: boolean = false;
|
shouldProtectScope: boolean = false;
|
||||||
shouldDefineAssign: boolean = false;
|
shouldDefineAssign: boolean = false;
|
||||||
hasSafeContext: boolean;
|
shouldDefineKey0: boolean = false;
|
||||||
|
hasSafeContext: boolean | null = null;
|
||||||
hasRef: boolean = false;
|
hasRef: boolean = false;
|
||||||
|
// hasTCall: boolean = false;
|
||||||
isDebug: boolean = false;
|
isDebug: boolean = false;
|
||||||
functions: CodeTarget[] = [];
|
functions: CodeTarget[] = [];
|
||||||
target = new CodeTarget("main");
|
target = new CodeTarget("main");
|
||||||
templateName: string;
|
templateName: string;
|
||||||
dev: boolean;
|
template: string;
|
||||||
translateFn: (s: string) => string;
|
|
||||||
translatableAttributes: string[];
|
|
||||||
ast: AST;
|
ast: AST;
|
||||||
staticCalls: { id: string; template: string }[] = [];
|
staticCalls: { id: string; template: string }[] = [];
|
||||||
|
|
||||||
constructor(name: string, ast: AST, options: CodeGenOptions) {
|
constructor(template: string, name?: string) {
|
||||||
this.translateFn = options.translateFn || ((s: string) => s);
|
this.template = template;
|
||||||
this.translatableAttributes = options.translatableAttributes || TRANSLATABLE_ATTRS;
|
this.ast = parse(template);
|
||||||
this.hasSafeContext = options.hasSafeContext || false;
|
// console.warn(this.ast);
|
||||||
this.dev = options.dev || false;
|
if (name) {
|
||||||
this.ast = ast;
|
this.templateName = name;
|
||||||
this.templateName = name;
|
} else {
|
||||||
|
if (template.length > 250) {
|
||||||
|
this.templateName = template.slice(0, 250) + "...";
|
||||||
|
} else {
|
||||||
|
this.templateName = template;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
generateCode(): string {
|
compile(): TemplateFunction {
|
||||||
const ast = this.ast;
|
const ast = this.ast;
|
||||||
this.isDebug = ast.type === ASTType.TDebug;
|
this.isDebug = ast.type === ASTType.TDebug;
|
||||||
BlockDescription.nextBlockId = 1;
|
BlockDescription.nextBlockId = 1;
|
||||||
BlockDescription.nextDataId = 1;
|
BlockDescription.nextDataId = 1;
|
||||||
this.compileAST(ast, {
|
this.compileAST(ast, { block: null, index: 0, forceNewBlock: false, isLast: true });
|
||||||
block: null,
|
const code = this.generateCode();
|
||||||
index: 0,
|
// console.warn(code);
|
||||||
forceNewBlock: false,
|
return new Function("bdom, helpers", code) as TemplateFunction;
|
||||||
isLast: true,
|
|
||||||
translate: true,
|
|
||||||
tKeyExpr: null,
|
|
||||||
});
|
|
||||||
|
|
||||||
let mainCode = this.target.code;
|
|
||||||
this.target.code = [];
|
|
||||||
this.target.indentLevel = 0;
|
|
||||||
// define blocks and utility functions
|
|
||||||
this.addLine(`let { text, createBlock, list, multi, html, toggler, component } = bdom;`);
|
|
||||||
this.addLine(
|
|
||||||
`let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;`
|
|
||||||
);
|
|
||||||
if (this.shouldDefineAssign) {
|
|
||||||
this.addLine(`let assign = Object.assign;`);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let { id, template } of this.staticCalls) {
|
|
||||||
this.addLine(`const ${id} = getTemplate(${template});`);
|
|
||||||
}
|
|
||||||
|
|
||||||
// define all blocks
|
|
||||||
if (this.blocks.length) {
|
|
||||||
this.addLine(``);
|
|
||||||
for (let block of this.blocks) {
|
|
||||||
if (block.dom) {
|
|
||||||
let xmlString = block.asXmlString();
|
|
||||||
if (block.dynamicTagName) {
|
|
||||||
xmlString = xmlString.replace(/^<\w+/, `<\${tag || '${block.dom.nodeName}'}`);
|
|
||||||
xmlString = xmlString.replace(/\w+>$/, `\${tag || '${block.dom.nodeName}'}>`);
|
|
||||||
this.addLine(`let ${block.blockName} = tag => createBlock(\`${xmlString}\`);`);
|
|
||||||
} else {
|
|
||||||
this.addLine(`let ${block.blockName} = createBlock(\`${xmlString}\`);`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// define all slots
|
|
||||||
for (let fn of this.functions) {
|
|
||||||
this.generateFunctions(fn);
|
|
||||||
}
|
|
||||||
|
|
||||||
// // generate main code
|
|
||||||
this.target.indentLevel = 0;
|
|
||||||
this.addLine(``);
|
|
||||||
this.addLine(`return function template(ctx, node, key = "") {`);
|
|
||||||
if (this.hasRef) {
|
|
||||||
this.addLine(` const refs = ctx.__owl__.refs;`);
|
|
||||||
}
|
|
||||||
if (this.shouldProtectScope) {
|
|
||||||
this.addLine(` ctx = Object.create(ctx);`);
|
|
||||||
this.addLine(` ctx[isBoundary] = 1`);
|
|
||||||
}
|
|
||||||
if (this.target.hasCache) {
|
|
||||||
this.addLine(` let cache = ctx.cache || {};`);
|
|
||||||
this.addLine(` let nextCache = ctx.cache = {};`);
|
|
||||||
}
|
|
||||||
for (let line of mainCode) {
|
|
||||||
this.addLine(line);
|
|
||||||
}
|
|
||||||
if (!this.target.hasRoot) {
|
|
||||||
throw new Error("missing root block");
|
|
||||||
}
|
|
||||||
this.addLine("}");
|
|
||||||
const code = this.target.code.join("\n");
|
|
||||||
|
|
||||||
if (this.isDebug) {
|
|
||||||
const msg = `[Owl Debug]\n${code}`;
|
|
||||||
console.log(msg);
|
|
||||||
}
|
|
||||||
return code;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
addLine(line: string) {
|
addLine(line: string) {
|
||||||
@@ -302,38 +215,96 @@ export class CodeGenerator {
|
|||||||
if (parentBlock) {
|
if (parentBlock) {
|
||||||
parentBlock.children.push(block);
|
parentBlock.children.push(block);
|
||||||
if (parentBlock.type === "list") {
|
if (parentBlock.type === "list") {
|
||||||
block.parentVar = `c_block${parentBlock.id}`;
|
block.parentVar = `c${parentBlock.id}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return block;
|
return block;
|
||||||
}
|
}
|
||||||
|
|
||||||
insertBlock(expression: string, block: BlockDescription, ctx: Context): void {
|
insertBlock(expression: string, block: BlockDescription, ctx: Context): string | null {
|
||||||
let blockExpr = block.generateExpr(expression);
|
let id: string | null = null;
|
||||||
const tKeyExpr = ctx.tKeyExpr;
|
const blockExpr = block.generateExpr(expression);
|
||||||
if (block.parentVar) {
|
if (block.parentVar) {
|
||||||
let keyArg = `key${this.target.loopLevel}`;
|
this.addLine(
|
||||||
if (tKeyExpr) {
|
`${block.parentVar}[${ctx.index}] = withKey(${blockExpr}, key${this.target.loopLevel});`
|
||||||
keyArg = `${tKeyExpr} + ${keyArg}`;
|
);
|
||||||
}
|
} else if (block.isRoot && !ctx.preventRoot) {
|
||||||
this.addLine(`${block.parentVar}[${ctx.index}] = withKey(${blockExpr}, ${keyArg});`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tKeyExpr) {
|
|
||||||
blockExpr = `toggler(${tKeyExpr}, ${blockExpr})`;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (block.isRoot && !ctx.preventRoot) {
|
|
||||||
this.addLine(`return ${blockExpr};`);
|
this.addLine(`return ${blockExpr};`);
|
||||||
} else {
|
} else {
|
||||||
this.addLine(`let ${block.varName} = ${blockExpr};`);
|
this.addLine(`let ${block.varName} = ${blockExpr};`);
|
||||||
}
|
}
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
generateCode(): string {
|
||||||
|
let mainCode = this.target.code;
|
||||||
|
this.target.code = [];
|
||||||
|
this.target.indentLevel = 0;
|
||||||
|
// define blocks and utility functions
|
||||||
|
this.addLine(`let { text, createBlock, list, multi, html, toggler, component } = bdom;`);
|
||||||
|
this.addLine(
|
||||||
|
`let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;`
|
||||||
|
);
|
||||||
|
if (this.shouldDefineAssign) {
|
||||||
|
this.addLine(`let assign = Object.assign;`);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let { id, template } of this.staticCalls) {
|
||||||
|
this.addLine(`const ${id} = getTemplate(${template});`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// define all blocks
|
||||||
|
if (this.blocks.length) {
|
||||||
|
this.addLine(``);
|
||||||
|
for (let block of this.blocks) {
|
||||||
|
if (block.dom) {
|
||||||
|
this.addLine(`let ${block.blockName} = createBlock(\`${block.asXmlString()}\`);`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// define all slots
|
||||||
|
for (let fn of this.functions) {
|
||||||
|
this.generateFunctions(fn);
|
||||||
|
}
|
||||||
|
|
||||||
|
// // generate main code
|
||||||
|
this.target.indentLevel = 0;
|
||||||
|
this.addLine(``);
|
||||||
|
this.addLine(`return function template(ctx, node, key = "") {`);
|
||||||
|
if (this.hasRef) {
|
||||||
|
this.addLine(` const refs = ctx.__owl__.refs;`);
|
||||||
|
}
|
||||||
|
if (this.shouldProtectScope) {
|
||||||
|
this.addLine(` ctx = Object.create(ctx);`);
|
||||||
|
}
|
||||||
|
if (this.target.hasCache) {
|
||||||
|
this.addLine(` let cache = ctx.cache || {};`);
|
||||||
|
this.addLine(` let nextCache = ctx.cache = {};`);
|
||||||
|
}
|
||||||
|
// if (this.shouldDefineKey0) {
|
||||||
|
// this.addLine(` let key0;`);
|
||||||
|
// }
|
||||||
|
for (let line of mainCode) {
|
||||||
|
this.addLine(line);
|
||||||
|
}
|
||||||
|
// console.warn(this.target.code.join('\n'))
|
||||||
|
if (!this.target.hasRoot) {
|
||||||
|
throw new Error("missing root block");
|
||||||
|
}
|
||||||
|
this.addLine("}");
|
||||||
|
const code = this.target.code.join("\n");
|
||||||
|
|
||||||
|
if (this.isDebug) {
|
||||||
|
const msg = `[Owl Debug]\n${code}`;
|
||||||
|
console.log(msg);
|
||||||
|
}
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
generateFunctions(fn: CodeTarget) {
|
generateFunctions(fn: CodeTarget) {
|
||||||
this.addLine("");
|
this.addLine("");
|
||||||
this.addLine(`function ${fn.name}(ctx, node, key) {`);
|
this.addLine(`const ${fn.name} = ${fn.signature}`);
|
||||||
if (fn.hasCache) {
|
if (fn.hasCache) {
|
||||||
this.addLine(`let cache = ctx.cache || {};`);
|
this.addLine(`let cache = ctx.cache || {};`);
|
||||||
this.addLine(`let nextCache = ctx.cache = {};`);
|
this.addLine(`let nextCache = ctx.cache = {};`);
|
||||||
@@ -343,28 +314,13 @@ export class CodeGenerator {
|
|||||||
}
|
}
|
||||||
this.addLine(`}`);
|
this.addLine(`}`);
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* Captures variables that are used inside of an expression. This is useful
|
captureExpression(expr: string): string {
|
||||||
* because in compiled code, almost all variables are accessed through the ctx
|
|
||||||
* object. In the case of functions, that lookup in the context can be delayed
|
|
||||||
* which can cause issues if the value has changed since the function was
|
|
||||||
* defined.
|
|
||||||
*
|
|
||||||
* @param expr the expression to capture
|
|
||||||
* @param forceCapture whether the expression should capture its scope even if
|
|
||||||
* it doesn't contain a function. Useful when the expression will be used as
|
|
||||||
* a function body.
|
|
||||||
* @returns a new expression that uses the captured values
|
|
||||||
*/
|
|
||||||
captureExpression(expr: string, forceCapture: boolean = false): string {
|
|
||||||
if (!forceCapture && !expr.includes("=>")) {
|
|
||||||
return compileExpr(expr);
|
|
||||||
}
|
|
||||||
const tokens = compileExprToArray(expr);
|
const tokens = compileExprToArray(expr);
|
||||||
const mapping = new Map<string, string>();
|
const mapping = new Map<string, string>();
|
||||||
return tokens
|
return tokens
|
||||||
.map((tok) => {
|
.map((tok) => {
|
||||||
if (tok.varName && !tok.isLocal) {
|
if (tok.varName) {
|
||||||
if (!mapping.has(tok.varName)) {
|
if (!mapping.has(tok.varName)) {
|
||||||
const varId = this.generateId("v");
|
const varId = this.generateId("v");
|
||||||
mapping.set(tok.varName, varId);
|
mapping.set(tok.varName, varId);
|
||||||
@@ -391,8 +347,8 @@ export class CodeGenerator {
|
|||||||
case ASTType.TEsc:
|
case ASTType.TEsc:
|
||||||
this.compileTEsc(ast, ctx);
|
this.compileTEsc(ast, ctx);
|
||||||
break;
|
break;
|
||||||
case ASTType.TOut:
|
case ASTType.TRaw:
|
||||||
this.compileTOut(ast, ctx);
|
this.compileTRaw(ast, ctx);
|
||||||
break;
|
break;
|
||||||
case ASTType.TIf:
|
case ASTType.TIf:
|
||||||
this.compileTIf(ast, ctx);
|
this.compileTIf(ast, ctx);
|
||||||
@@ -427,9 +383,6 @@ export class CodeGenerator {
|
|||||||
case ASTType.TSlot:
|
case ASTType.TSlot:
|
||||||
this.compileTSlot(ast, ctx);
|
this.compileTSlot(ast, ctx);
|
||||||
break;
|
break;
|
||||||
case ASTType.TTranslation:
|
|
||||||
this.compileTTranslation(ast, ctx);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -462,64 +415,63 @@ export class CodeGenerator {
|
|||||||
|
|
||||||
compileText(ast: ASTText, ctx: Context) {
|
compileText(ast: ASTText, ctx: Context) {
|
||||||
let { block, forceNewBlock } = ctx;
|
let { block, forceNewBlock } = ctx;
|
||||||
|
|
||||||
let value = ast.value;
|
|
||||||
if (value && ctx.translate !== false) {
|
|
||||||
const match = translationRE.exec(value) as any;
|
|
||||||
value = match[1] + this.translateFn(match[2]) + match[3];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!block || forceNewBlock) {
|
if (!block || forceNewBlock) {
|
||||||
block = this.createBlock(block, "text", ctx);
|
block = this.createBlock(block, "text", ctx);
|
||||||
this.insertBlock(`text(\`${value}\`)`, block, {
|
this.insertBlock(`text(\`${ast.value}\`)`, block, {
|
||||||
...ctx,
|
...ctx,
|
||||||
forceNewBlock: forceNewBlock && !block,
|
forceNewBlock: forceNewBlock && !block,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
const createFn = ast.type === ASTType.Text ? xmlDoc.createTextNode : xmlDoc.createComment;
|
const createFn = ast.type === ASTType.Text ? xmlDoc.createTextNode : xmlDoc.createComment;
|
||||||
block.insert(createFn.call(xmlDoc, value));
|
block.insert(createFn.call(xmlDoc, ast.value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
generateHandlerCode(rawEvent: string, handler: string): string {
|
generateHandlerCode(handler: string, event: string = ""): string {
|
||||||
const modifiers = rawEvent
|
let args: string = "";
|
||||||
.split(".")
|
const name: string = handler.replace(/\(.*\)/, function (_args) {
|
||||||
.slice(1)
|
args = _args.slice(1, -1);
|
||||||
.map((m) => `"${m}"`);
|
return "";
|
||||||
let modifiersCode = "";
|
});
|
||||||
if (modifiers.length) {
|
const isMethodCall = name.match(FNAMEREGEXP);
|
||||||
modifiersCode = `${modifiers.join(",")}, `;
|
if (isMethodCall) {
|
||||||
|
let handlerFn: string;
|
||||||
|
if (args) {
|
||||||
|
const argId = this.generateId("arg");
|
||||||
|
this.addLine(`const ${argId} = [${compileExpr(args)}];`);
|
||||||
|
handlerFn = `'${name}', ${argId}`;
|
||||||
|
} else {
|
||||||
|
handlerFn = `'${name}'`;
|
||||||
|
}
|
||||||
|
return `[${event ? `\`${event}\`` + ", " : ""}ctx, ${handlerFn!}]`;
|
||||||
|
} else {
|
||||||
|
let code = this.captureExpression(handler);
|
||||||
|
code = `{const res = (() => { return ${code} })(); if (typeof res === 'function') { res(e) }}`;
|
||||||
|
let handlerFn = `(e) => ${code}`;
|
||||||
|
if (event) {
|
||||||
|
handlerFn = `[\`${event}\`, ${handlerFn}]`;
|
||||||
|
}
|
||||||
|
return handlerFn;
|
||||||
}
|
}
|
||||||
return `[${modifiersCode}${this.captureExpression(handler)}, ctx]`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
compileTDomNode(ast: ASTDomNode, ctx: Context) {
|
compileTDomNode(ast: ASTDomNode, ctx: Context) {
|
||||||
let { block, forceNewBlock } = ctx;
|
let { block, forceNewBlock } = ctx;
|
||||||
const isNewBlock = !block || forceNewBlock || ast.dynamicTag !== null;
|
const isNewBlock = !block || forceNewBlock;
|
||||||
let codeIdx = this.target.code.length;
|
let codeIdx = this.target.code.length;
|
||||||
if (isNewBlock) {
|
if (isNewBlock) {
|
||||||
if (ast.dynamicTag && ctx.block) {
|
|
||||||
this.insertAnchor(ctx.block!);
|
|
||||||
}
|
|
||||||
block = this.createBlock(block, "block", ctx);
|
block = this.createBlock(block, "block", ctx);
|
||||||
this.blocks.push(block);
|
this.blocks.push(block);
|
||||||
if (ast.dynamicTag) {
|
|
||||||
const tagExpr = this.generateId("tag");
|
|
||||||
this.addLine(`let ${tagExpr} = ${compileExpr(ast.dynamicTag)};`);
|
|
||||||
block.dynamicTagName = tagExpr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// attributes
|
// attributes
|
||||||
const attrs: { [key: string]: string } = {};
|
const attrs: { [key: string]: string } = {};
|
||||||
if (ast.ns) {
|
|
||||||
// specific namespace uri
|
|
||||||
attrs["block-ns"] = ast.ns;
|
|
||||||
}
|
|
||||||
for (let key in ast.attrs) {
|
for (let key in ast.attrs) {
|
||||||
if (key.startsWith("t-attf")) {
|
if (key.startsWith("t-attf")) {
|
||||||
let expr = interpolate(ast.attrs[key]);
|
let expr = interpolate(ast.attrs[key]);
|
||||||
const idx = block!.insertData(expr);
|
const idx = block!.insertData(expr);
|
||||||
attrs["block-attribute-" + idx] = key.slice(7);
|
attrs["block-attribute-" + idx] = key.slice(7);
|
||||||
|
// console.warn('ccc', staticAttrs)
|
||||||
} else if (key.startsWith("t-att")) {
|
} else if (key.startsWith("t-att")) {
|
||||||
let expr = compileExpr(ast.attrs[key]);
|
let expr = compileExpr(ast.attrs[key]);
|
||||||
const idx = block!.insertData(expr);
|
const idx = block!.insertData(expr);
|
||||||
@@ -528,8 +480,6 @@ export class CodeGenerator {
|
|||||||
} else {
|
} else {
|
||||||
attrs[`block-attribute-${idx}`] = key.slice(6);
|
attrs[`block-attribute-${idx}`] = key.slice(6);
|
||||||
}
|
}
|
||||||
} else if (this.translatableAttributes.includes(key)) {
|
|
||||||
attrs[key] = this.translateFn(ast.attrs[key]);
|
|
||||||
} else {
|
} else {
|
||||||
attrs[key] = ast.attrs[key];
|
attrs[key] = ast.attrs[key];
|
||||||
}
|
}
|
||||||
@@ -537,7 +487,7 @@ export class CodeGenerator {
|
|||||||
|
|
||||||
// event handlers
|
// event handlers
|
||||||
for (let ev in ast.on) {
|
for (let ev in ast.on) {
|
||||||
const name = this.generateHandlerCode(ev, ast.on[ev]);
|
const name = this.generateHandlerCode(ast.on[ev]);
|
||||||
const idx = block!.insertData(name);
|
const idx = block!.insertData(name);
|
||||||
attrs[`block-handler-${idx}`] = ev;
|
attrs[`block-handler-${idx}`] = ev;
|
||||||
}
|
}
|
||||||
@@ -549,7 +499,7 @@ export class CodeGenerator {
|
|||||||
if (isDynamic) {
|
if (isDynamic) {
|
||||||
const str = ast.ref.replace(
|
const str = ast.ref.replace(
|
||||||
INTERP_REGEXP,
|
INTERP_REGEXP,
|
||||||
(expr) => "${" + this.captureExpression(expr.slice(2, -2), true) + "}"
|
(expr) => "${" + this.captureExpression(expr.slice(2, -2)) + "}"
|
||||||
);
|
);
|
||||||
const idx = block!.insertData(`(el) => refs[\`${str}\`] = el`);
|
const idx = block!.insertData(`(el) => refs[\`${str}\`] = el`);
|
||||||
attrs["block-ref"] = String(idx);
|
attrs["block-ref"] = String(idx);
|
||||||
@@ -559,41 +509,6 @@ export class CodeGenerator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// t-model
|
|
||||||
if (ast.model) {
|
|
||||||
const {
|
|
||||||
baseExpr,
|
|
||||||
expr,
|
|
||||||
eventType,
|
|
||||||
shouldNumberize,
|
|
||||||
shouldTrim,
|
|
||||||
targetAttr,
|
|
||||||
specialInitTargetAttr,
|
|
||||||
} = ast.model;
|
|
||||||
|
|
||||||
const baseExpression = compileExpr(baseExpr);
|
|
||||||
const id = this.generateId();
|
|
||||||
this.addLine(`const bExpr${id} = ${baseExpression};`);
|
|
||||||
|
|
||||||
const expression = compileExpr(expr);
|
|
||||||
|
|
||||||
let idx: number;
|
|
||||||
if (specialInitTargetAttr) {
|
|
||||||
idx = block!.insertData(`${baseExpression}[${expression}] === '${attrs[targetAttr]}'`);
|
|
||||||
attrs[`block-attribute-${idx}`] = specialInitTargetAttr;
|
|
||||||
} else {
|
|
||||||
idx = block!.insertData(`${baseExpression}[${expression}]`);
|
|
||||||
attrs[`block-attribute-${idx}`] = targetAttr;
|
|
||||||
}
|
|
||||||
let valueCode = `ev.target.${targetAttr}`;
|
|
||||||
valueCode = shouldTrim ? `${valueCode}.trim()` : valueCode;
|
|
||||||
valueCode = shouldNumberize ? `toNumber(${valueCode})` : valueCode;
|
|
||||||
|
|
||||||
const handler = `[(ev) => { bExpr${id}[${expression}] = ${valueCode}; }]`;
|
|
||||||
idx = block!.insertData(handler);
|
|
||||||
attrs[`block-handler-${idx}`] = eventType;
|
|
||||||
}
|
|
||||||
|
|
||||||
const dom = xmlDoc.createElement(ast.tag);
|
const dom = xmlDoc.createElement(ast.tag);
|
||||||
for (const [attr, val] of Object.entries(attrs)) {
|
for (const [attr, val] of Object.entries(attrs)) {
|
||||||
if (!(attr === "class" && val === "")) {
|
if (!(attr === "class" && val === "")) {
|
||||||
@@ -607,12 +522,12 @@ export class CodeGenerator {
|
|||||||
const children = ast.content;
|
const children = ast.content;
|
||||||
for (let i = 0; i < children.length; i++) {
|
for (let i = 0; i < children.length; i++) {
|
||||||
const child = ast.content[i];
|
const child = ast.content[i];
|
||||||
const subCtx: Context = createContext(ctx, {
|
const subCtx: Context = {
|
||||||
block,
|
block: block,
|
||||||
index: block!.childNumber,
|
index: block!.childNumber,
|
||||||
forceNewBlock: false,
|
forceNewBlock: false,
|
||||||
isLast: ctx.isLast && i === children.length - 1,
|
isLast: ctx.isLast && i === children.length - 1,
|
||||||
});
|
};
|
||||||
this.compileAST(child, subCtx);
|
this.compileAST(child, subCtx);
|
||||||
}
|
}
|
||||||
block!.currentDom = initialDom;
|
block!.currentDom = initialDom;
|
||||||
@@ -658,20 +573,20 @@ export class CodeGenerator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
compileTOut(ast: ASTTOut, ctx: Context) {
|
compileTRaw(ast: ASTTRaw, ctx: Context) {
|
||||||
let { block } = ctx;
|
let { block } = ctx;
|
||||||
if (block) {
|
if (block) {
|
||||||
this.insertAnchor(block);
|
this.insertAnchor(block);
|
||||||
}
|
}
|
||||||
block = this.createBlock(block, "html", ctx);
|
block = this.createBlock(block, "html", ctx);
|
||||||
let expr = ast.expr === "0" ? "ctx[zero]" : `safeOutput(${compileExpr(ast.expr)})`;
|
let expr = ast.expr === "0" ? "ctx[zero]" : compileExpr(ast.expr);
|
||||||
if (ast.body) {
|
if (ast.body) {
|
||||||
const nextId = BlockDescription.nextBlockId;
|
const nextId = BlockDescription.nextBlockId;
|
||||||
const subCtx: Context = createContext(ctx);
|
const subCtx: Context = { block: null, index: 0, forceNewBlock: true };
|
||||||
this.compileAST({ type: ASTType.Multi, content: ast.body }, subCtx);
|
this.compileAST({ type: ASTType.Multi, content: ast.body }, subCtx);
|
||||||
expr = `withDefault(${expr}, b${nextId})`;
|
expr = `withDefault(${expr}, b${nextId})`;
|
||||||
}
|
}
|
||||||
this.insertBlock(`${expr}`, block, ctx);
|
this.insertBlock(`html(${expr})`, block, ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
compileTIf(ast: ASTTif, ctx: Context, nextNode?: ASTDomNode) {
|
compileTIf(ast: ASTTif, ctx: Context, nextNode?: ASTDomNode) {
|
||||||
@@ -688,7 +603,7 @@ export class CodeGenerator {
|
|||||||
this.addLine(`if (${compileExpr(ast.condition)}) {`);
|
this.addLine(`if (${compileExpr(ast.condition)}) {`);
|
||||||
this.target.indentLevel++;
|
this.target.indentLevel++;
|
||||||
this.insertAnchor(block!);
|
this.insertAnchor(block!);
|
||||||
const subCtx: Context = createContext(ctx, { block, index: currentIndex });
|
const subCtx: Context = { block: block, index: currentIndex, forceNewBlock: true };
|
||||||
this.compileAST(ast.content, subCtx);
|
this.compileAST(ast.content, subCtx);
|
||||||
this.target.indentLevel--;
|
this.target.indentLevel--;
|
||||||
if (ast.tElif) {
|
if (ast.tElif) {
|
||||||
@@ -696,7 +611,11 @@ export class CodeGenerator {
|
|||||||
this.addLine(`} else if (${compileExpr(clause.condition)}) {`);
|
this.addLine(`} else if (${compileExpr(clause.condition)}) {`);
|
||||||
this.target.indentLevel++;
|
this.target.indentLevel++;
|
||||||
this.insertAnchor(block);
|
this.insertAnchor(block);
|
||||||
const subCtx: Context = createContext(ctx, { block, index: currentIndex });
|
const subCtx: Context = {
|
||||||
|
block: block,
|
||||||
|
index: currentIndex,
|
||||||
|
forceNewBlock: true,
|
||||||
|
};
|
||||||
this.compileAST(clause.content, subCtx);
|
this.compileAST(clause.content, subCtx);
|
||||||
this.target.indentLevel--;
|
this.target.indentLevel--;
|
||||||
}
|
}
|
||||||
@@ -705,7 +624,11 @@ export class CodeGenerator {
|
|||||||
this.addLine(`} else {`);
|
this.addLine(`} else {`);
|
||||||
this.target.indentLevel++;
|
this.target.indentLevel++;
|
||||||
this.insertAnchor(block);
|
this.insertAnchor(block);
|
||||||
const subCtx: Context = createContext(ctx, { block, index: currentIndex });
|
const subCtx: Context = {
|
||||||
|
block: block,
|
||||||
|
index: currentIndex,
|
||||||
|
forceNewBlock: true,
|
||||||
|
};
|
||||||
this.compileAST(ast.tElse, subCtx);
|
this.compileAST(ast.tElse, subCtx);
|
||||||
this.target.indentLevel--;
|
this.target.indentLevel--;
|
||||||
}
|
}
|
||||||
@@ -741,17 +664,14 @@ export class CodeGenerator {
|
|||||||
this.target.loopLevel++;
|
this.target.loopLevel++;
|
||||||
const loopVar = `i${this.target.loopLevel}`;
|
const loopVar = `i${this.target.loopLevel}`;
|
||||||
this.addLine(`ctx = Object.create(ctx);`);
|
this.addLine(`ctx = Object.create(ctx);`);
|
||||||
const vals = `v_block${block.id}`;
|
// const cId = this.generateId();
|
||||||
const keys = `k_block${block.id}`;
|
const vals = `v${block.id}`;
|
||||||
const l = `l_block${block.id}`;
|
const keys = `k${block.id}`;
|
||||||
const c = `c_block${block.id}`;
|
const l = `l${block.id}`;
|
||||||
|
const c = `c${block.id}`;
|
||||||
this.addLine(
|
this.addLine(
|
||||||
`const [${keys}, ${vals}, ${l}, ${c}] = prepareList(${compileExpr(ast.collection)});`
|
`const [${keys}, ${vals}, ${l}, ${c}] = prepareList(${compileExpr(ast.collection)});`
|
||||||
);
|
);
|
||||||
// Throw errors on duplicate keys in dev mode
|
|
||||||
if (this.dev) {
|
|
||||||
this.addLine(`const keys${block.id} = new Set();`);
|
|
||||||
}
|
|
||||||
this.addLine(`for (let ${loopVar} = 0; ${loopVar} < ${l}; ${loopVar}++) {`);
|
this.addLine(`for (let ${loopVar} = 0; ${loopVar} < ${l}; ${loopVar}++) {`);
|
||||||
this.target.indentLevel++;
|
this.target.indentLevel++;
|
||||||
this.addLine(`ctx[\`${ast.elem}\`] = ${vals}[${loopVar}];`);
|
this.addLine(`ctx[\`${ast.elem}\`] = ${vals}[${loopVar}];`);
|
||||||
@@ -768,13 +688,6 @@ export class CodeGenerator {
|
|||||||
this.addLine(`ctx[\`${ast.elem}_value\`] = ${keys}[${loopVar}];`);
|
this.addLine(`ctx[\`${ast.elem}_value\`] = ${keys}[${loopVar}];`);
|
||||||
}
|
}
|
||||||
this.addLine(`let key${this.target.loopLevel} = ${ast.key ? compileExpr(ast.key) : loopVar};`);
|
this.addLine(`let key${this.target.loopLevel} = ${ast.key ? compileExpr(ast.key) : loopVar};`);
|
||||||
if (this.dev) {
|
|
||||||
// Throw error on duplicate keys in dev mode
|
|
||||||
this.addLine(
|
|
||||||
`if (keys${block.id}.has(key${this.target.loopLevel})) { throw new Error(\`Got duplicate key in t-foreach: \${key${this.target.loopLevel}}\`)}`
|
|
||||||
);
|
|
||||||
this.addLine(`keys${block.id}.add(key${this.target.loopLevel});`);
|
|
||||||
}
|
|
||||||
let id: string;
|
let id: string;
|
||||||
if (ast.memo) {
|
if (ast.memo) {
|
||||||
this.target.hasCache = true;
|
this.target.hasCache = true;
|
||||||
@@ -795,8 +708,17 @@ export class CodeGenerator {
|
|||||||
this.addLine("}");
|
this.addLine("}");
|
||||||
}
|
}
|
||||||
|
|
||||||
const subCtx: Context = createContext(ctx, { block, index: loopVar });
|
const subCtx: Context = {
|
||||||
|
block: block, //collectionBlock,
|
||||||
|
index: loopVar,
|
||||||
|
forceNewBlock: true,
|
||||||
|
};
|
||||||
this.compileAST(ast.body, subCtx);
|
this.compileAST(ast.body, subCtx);
|
||||||
|
if (!ast.key) {
|
||||||
|
console.warn(
|
||||||
|
`"Directive t-foreach should always be used with a t-key! (in template: '${this.templateName}')"`
|
||||||
|
);
|
||||||
|
}
|
||||||
if (ast.memo) {
|
if (ast.memo) {
|
||||||
this.addLine(
|
this.addLine(
|
||||||
`nextCache[key${this.target.loopLevel}] = assign(${c}[${loopVar}], {memo: memo${id!}});`
|
`nextCache[key${this.target.loopLevel}] = assign(${c}[${loopVar}], {memo: memo${id!}});`
|
||||||
@@ -812,13 +734,6 @@ export class CodeGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
compileTKey(ast: ASTTKey, ctx: Context) {
|
compileTKey(ast: ASTTKey, ctx: Context) {
|
||||||
const tKeyExpr = this.generateId("tKey_");
|
|
||||||
this.addLine(`const ${tKeyExpr} = ${compileExpr(ast.expr)};`);
|
|
||||||
ctx = createContext(ctx, {
|
|
||||||
tKeyExpr,
|
|
||||||
block: ctx.block,
|
|
||||||
index: ctx.index,
|
|
||||||
});
|
|
||||||
this.compileAST(ast.content, ctx);
|
this.compileAST(ast.content, ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -840,13 +755,13 @@ export class CodeGenerator {
|
|||||||
for (let i = 0, l = ast.content.length; i < l; i++) {
|
for (let i = 0, l = ast.content.length; i < l; i++) {
|
||||||
const child = ast.content[i];
|
const child = ast.content[i];
|
||||||
const isTSet = child.type === ASTType.TSet;
|
const isTSet = child.type === ASTType.TSet;
|
||||||
const subCtx: Context = createContext(ctx, {
|
const subCtx: Context = {
|
||||||
block,
|
block: block,
|
||||||
index,
|
index: index,
|
||||||
forceNewBlock: !isTSet,
|
forceNewBlock: !isTSet,
|
||||||
preventRoot: ctx.preventRoot,
|
preventRoot: ctx.preventRoot,
|
||||||
isLast: ctx.isLast && i === l - 1,
|
isLast: ctx.isLast && i === l - 1,
|
||||||
});
|
};
|
||||||
this.compileAST(child, subCtx);
|
this.compileAST(child, subCtx);
|
||||||
if (!isTSet) {
|
if (!isTSet) {
|
||||||
index++;
|
index++;
|
||||||
@@ -876,11 +791,11 @@ export class CodeGenerator {
|
|||||||
|
|
||||||
compileTCall(ast: ASTTCall, ctx: Context) {
|
compileTCall(ast: ASTTCall, ctx: Context) {
|
||||||
let { block, forceNewBlock } = ctx;
|
let { block, forceNewBlock } = ctx;
|
||||||
|
// this.hasTCall = true;
|
||||||
if (ast.body) {
|
if (ast.body) {
|
||||||
this.addLine(`ctx = Object.create(ctx);`);
|
this.addLine(`ctx = Object.create(ctx);`);
|
||||||
this.addLine(`ctx[isBoundary] = 1;`);
|
|
||||||
const nextId = BlockDescription.nextBlockId;
|
const nextId = BlockDescription.nextBlockId;
|
||||||
const subCtx: Context = createContext(ctx, { preventRoot: true });
|
const subCtx: Context = { block: null, index: 0, forceNewBlock: true, preventRoot: true };
|
||||||
this.compileAST({ type: ASTType.Multi, content: ast.body }, subCtx);
|
this.compileAST({ type: ASTType.Multi, content: ast.body }, subCtx);
|
||||||
if (nextId !== BlockDescription.nextBlockId) {
|
if (nextId !== BlockDescription.nextBlockId) {
|
||||||
this.addLine(`ctx[zero] = b${nextId};`);
|
this.addLine(`ctx[zero] = b${nextId};`);
|
||||||
@@ -905,11 +820,9 @@ export class CodeGenerator {
|
|||||||
} else {
|
} else {
|
||||||
const id = this.generateId(`callTemplate_`);
|
const id = this.generateId(`callTemplate_`);
|
||||||
this.staticCalls.push({ id, template: subTemplate });
|
this.staticCalls.push({ id, template: subTemplate });
|
||||||
|
// console.warn('coucoup', this.target.hasRoot)
|
||||||
block = this.createBlock(block, "multi", ctx);
|
block = this.createBlock(block, "multi", ctx);
|
||||||
this.insertBlock(`${id}.call(this, ctx, node, ${key})`, block!, {
|
this.insertBlock(`${id}(ctx, node, ${key})`, block!, { ...ctx, forceNewBlock: !block });
|
||||||
...ctx,
|
|
||||||
forceNewBlock: !block,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
if (ast.body && !ctx.isLast) {
|
if (ast.body && !ctx.isLast) {
|
||||||
this.addLine(`ctx = ctx.__proto__;`);
|
this.addLine(`ctx = ctx.__proto__;`);
|
||||||
@@ -931,7 +844,7 @@ export class CodeGenerator {
|
|||||||
this.shouldProtectScope = true;
|
this.shouldProtectScope = true;
|
||||||
const expr = ast.value ? compileExpr(ast.value || "") : "null";
|
const expr = ast.value ? compileExpr(ast.value || "") : "null";
|
||||||
if (ast.body) {
|
if (ast.body) {
|
||||||
const subCtx: Context = createContext(ctx);
|
const subCtx: Context = { block: null, index: 0, forceNewBlock: true };
|
||||||
const nextId = `b${BlockDescription.nextBlockId}`;
|
const nextId = `b${BlockDescription.nextBlockId}`;
|
||||||
this.compileAST({ type: ASTType.Multi, content: ast.body }, subCtx);
|
this.compileAST({ type: ASTType.Multi, content: ast.body }, subCtx);
|
||||||
const value = ast.value ? (nextId ? `withDefault(${expr}, ${nextId})` : expr) : nextId;
|
const value = ast.value ? (nextId ? `withDefault(${expr}, ${nextId})` : expr) : nextId;
|
||||||
@@ -947,7 +860,7 @@ export class CodeGenerator {
|
|||||||
} else {
|
} else {
|
||||||
value = expr;
|
value = expr;
|
||||||
}
|
}
|
||||||
this.addLine(`setContextValue(ctx, "${ast.name}", ${value});`);
|
this.addLine(`ctx[\`${ast.name}\`] = ${value};`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -961,83 +874,14 @@ export class CodeGenerator {
|
|||||||
|
|
||||||
compileComponent(ast: ASTComponent, ctx: Context) {
|
compileComponent(ast: ASTComponent, ctx: Context) {
|
||||||
let { block } = ctx;
|
let { block } = ctx;
|
||||||
|
let extraArgs: { [key: string]: string } = {};
|
||||||
|
|
||||||
// props
|
// props
|
||||||
const props: string[] = [];
|
const props: string[] = [];
|
||||||
let hasSlotsProp = false;
|
|
||||||
for (let p in ast.props) {
|
for (let p in ast.props) {
|
||||||
const propName = /^[a-z_]+$/i.test(p) ? p : `'${p}'`;
|
props.push(`${p}: ${compileExpr(ast.props[p]) || undefined}`);
|
||||||
props.push(`${propName}: ${this.captureExpression(ast.props[p]) || undefined}`);
|
|
||||||
if (p === "slots") {
|
|
||||||
hasSlotsProp = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// slots
|
|
||||||
const hasSlot = !!Object.keys(ast.slots).length;
|
|
||||||
let slotDef: string = "";
|
|
||||||
if (hasSlot) {
|
|
||||||
let ctxStr = "ctx";
|
|
||||||
if (this.target.loopLevel || !this.hasSafeContext) {
|
|
||||||
ctxStr = this.generateId("ctx");
|
|
||||||
this.addLine(`const ${ctxStr} = capture(ctx);`);
|
|
||||||
}
|
|
||||||
let slotStr: string[] = [];
|
|
||||||
const initialTarget = this.target;
|
|
||||||
for (let slotName in ast.slots) {
|
|
||||||
let name = this.generateId("slot");
|
|
||||||
const slot = new CodeTarget(name);
|
|
||||||
this.functions.push(slot);
|
|
||||||
this.target = slot;
|
|
||||||
const subCtx: Context = createContext(ctx);
|
|
||||||
this.compileAST(ast.slots[slotName].content, subCtx);
|
|
||||||
const params = [`__render: ${name}, __ctx: ${ctxStr}`];
|
|
||||||
const scope = ast.slots[slotName].scope;
|
|
||||||
if (scope) {
|
|
||||||
params.push(`__scope: "${scope}"`);
|
|
||||||
}
|
|
||||||
if (ast.slots[slotName].attrs) {
|
|
||||||
for (const [n, v] of Object.entries(ast.slots[slotName].attrs!)) {
|
|
||||||
params.push(`${n}: ${compileExpr(v) || undefined}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const slotInfo = `{${params.join(", ")}}`;
|
|
||||||
if (this.hasRef) {
|
|
||||||
slot.code.unshift(` const refs = ctx.__owl__.refs`);
|
|
||||||
slotStr.push(`'${slotName}': ${slotInfo}`);
|
|
||||||
} else {
|
|
||||||
slotStr.push(`'${slotName}': ${slotInfo}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.target = initialTarget;
|
|
||||||
slotDef = `{${slotStr.join(", ")}}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (slotDef && !(ast.dynamicProps || hasSlotsProp)) {
|
|
||||||
props.push(`slots: ${slotDef}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const propStr = `{${props.join(",")}}`;
|
|
||||||
|
|
||||||
let propString = propStr;
|
|
||||||
if (ast.dynamicProps) {
|
|
||||||
if (!props.length) {
|
|
||||||
propString = `${compileExpr(ast.dynamicProps)}`;
|
|
||||||
} else {
|
|
||||||
propString = `Object.assign({}, ${compileExpr(ast.dynamicProps)}, ${propStr})`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let propVar: string;
|
|
||||||
if ((slotDef && (ast.dynamicProps || hasSlotsProp)) || this.dev) {
|
|
||||||
propVar = this.generateId("props");
|
|
||||||
this.addLine(`const ${propVar!} = ${propString}`);
|
|
||||||
propString = propVar!;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (slotDef && (ast.dynamicProps || hasSlotsProp)) {
|
|
||||||
this.addLine(`${propVar!}.slots = Object.assign(${slotDef}, ${propVar!}.slots)`);
|
|
||||||
}
|
}
|
||||||
|
const propString = `{${props.join(",")}}`;
|
||||||
|
|
||||||
// cmap key
|
// cmap key
|
||||||
const key = this.generateComponentKey();
|
const key = this.generateComponentKey();
|
||||||
@@ -1048,22 +892,64 @@ export class CodeGenerator {
|
|||||||
} else {
|
} else {
|
||||||
expr = `\`${ast.name}\``;
|
expr = `\`${ast.name}\``;
|
||||||
}
|
}
|
||||||
|
let blockArgs = `${expr}, ${propString}, key + \`${key}\`, node, ctx`;
|
||||||
|
|
||||||
if (this.dev) {
|
// slots
|
||||||
this.addLine(`helpers.validateProps(${expr}, ${propVar!}, ctx)`);
|
const hasSlot = !!Object.keys(ast.slots).length;
|
||||||
|
let slotDef: string;
|
||||||
|
if (hasSlot) {
|
||||||
|
if (this.hasSafeContext === null) {
|
||||||
|
this.hasSafeContext = !this.template.includes("t-set") && !this.template.includes("t-call");
|
||||||
|
}
|
||||||
|
let ctxStr = "ctx";
|
||||||
|
if (this.target.loopLevel || !this.hasSafeContext) {
|
||||||
|
ctxStr = this.generateId("ctx");
|
||||||
|
this.addLine(`const ${ctxStr} = capture(ctx);`);
|
||||||
|
}
|
||||||
|
let slotStr: string[] = [];
|
||||||
|
const initialTarget = this.target;
|
||||||
|
for (let slotName in ast.slots) {
|
||||||
|
let name = this.generateId("slot");
|
||||||
|
const slot = new CodeTarget(name);
|
||||||
|
slot.signature = "ctx => (node, key) => {";
|
||||||
|
this.functions.push(slot);
|
||||||
|
this.target = slot;
|
||||||
|
const subCtx: Context = { block: null, index: 0, forceNewBlock: true };
|
||||||
|
this.compileAST(ast.slots[slotName], subCtx);
|
||||||
|
if (this.hasRef) {
|
||||||
|
slot.signature = "ctx => node => {";
|
||||||
|
slot.code.unshift(` const refs = ctx.__owl__.refs`);
|
||||||
|
slotStr.push(`'${slotName}': ${name}(${ctxStr})`);
|
||||||
|
} else {
|
||||||
|
slotStr.push(`'${slotName}': ${name}(${ctxStr})`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.target = initialTarget;
|
||||||
|
slotDef = `{${slotStr.join(", ")}}`;
|
||||||
|
extraArgs.slots = slotDef;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (block && (ctx.forceNewBlock === false || ctx.tKeyExpr)) {
|
// handlers
|
||||||
|
const hasHandlers = Object.keys(ast.handlers).length;
|
||||||
|
if (hasHandlers) {
|
||||||
|
const vars = Object.keys(ast.handlers).map((ev) => {
|
||||||
|
let id = this.generateId("h");
|
||||||
|
this.addLine(`let ${id} = ${this.generateHandlerCode(ast.handlers[ev], ev)};`);
|
||||||
|
return id;
|
||||||
|
});
|
||||||
|
extraArgs.handlers = `[${vars}]`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (block && ctx.forceNewBlock === false) {
|
||||||
// todo: check the forcenewblock condition
|
// todo: check the forcenewblock condition
|
||||||
this.insertAnchor(block);
|
this.insertAnchor(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
let keyArg = `key + \`${key}\``;
|
|
||||||
if (ctx.tKeyExpr) {
|
|
||||||
keyArg = `${ctx.tKeyExpr} + ${keyArg}`;
|
|
||||||
}
|
|
||||||
const blockArgs = `${expr}, ${propString}, ${keyArg}, node, ctx`;
|
|
||||||
let blockExpr = `component(${blockArgs})`;
|
let blockExpr = `component(${blockArgs})`;
|
||||||
|
if (Object.keys(extraArgs).length) {
|
||||||
|
this.shouldDefineAssign = true;
|
||||||
|
const content = Object.keys(extraArgs).map((k) => `${k}: ${extraArgs[k]}`);
|
||||||
|
blockExpr = `assign(${blockExpr}, {${content.join(", ")}})`;
|
||||||
|
}
|
||||||
if (ast.isDynamic) {
|
if (ast.isDynamic) {
|
||||||
blockExpr = `toggler(${expr}, ${blockExpr})`;
|
blockExpr = `toggler(${expr}, ${blockExpr})`;
|
||||||
}
|
}
|
||||||
@@ -1082,33 +968,24 @@ export class CodeGenerator {
|
|||||||
} else {
|
} else {
|
||||||
slotName = "'" + ast.name + "'";
|
slotName = "'" + ast.name + "'";
|
||||||
}
|
}
|
||||||
|
|
||||||
let scope = null;
|
|
||||||
if (ast.attrs) {
|
|
||||||
const params = [];
|
|
||||||
for (const [n, v] of Object.entries(ast.attrs!)) {
|
|
||||||
params.push(`${n}: ${compileExpr(v) || undefined}`);
|
|
||||||
}
|
|
||||||
scope = `{${params.join(", ")}}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ast.defaultContent) {
|
if (ast.defaultContent) {
|
||||||
let name = this.generateId("defaultContent");
|
let name = this.generateId("defaultSlot");
|
||||||
const slot = new CodeTarget(name);
|
const slot = new CodeTarget(name);
|
||||||
|
slot.signature = "ctx => {";
|
||||||
this.functions.push(slot);
|
this.functions.push(slot);
|
||||||
const initialTarget = this.target;
|
const initialTarget = this.target;
|
||||||
const subCtx: Context = createContext(ctx);
|
const subCtx: Context = { block: null, index: 0, forceNewBlock: true };
|
||||||
this.target = slot;
|
this.target = slot;
|
||||||
this.compileAST(ast.defaultContent, subCtx);
|
this.compileAST(ast.defaultContent, subCtx);
|
||||||
this.target = initialTarget;
|
this.target = initialTarget;
|
||||||
blockString = `callSlot(ctx, node, key, ${slotName}, ${dynamic}, ${scope}, ${name})`;
|
blockString = `callSlot(ctx, node, key, ${slotName}, ${name}, ${dynamic})`;
|
||||||
} else {
|
} else {
|
||||||
if (dynamic) {
|
if (dynamic) {
|
||||||
let name = this.generateId("slot");
|
let name = this.generateId("slot");
|
||||||
this.addLine(`const ${name} = ${slotName};`);
|
this.addLine(`const ${name} = ${slotName};`);
|
||||||
blockString = `toggler(${name}, callSlot(ctx, node, key, ${name}), ${dynamic}, ${scope})`;
|
blockString = `toggler(${name}, callSlot(ctx, node, key, ${name}))`;
|
||||||
} else {
|
} else {
|
||||||
blockString = `callSlot(ctx, node, key, ${slotName}, ${dynamic}, ${scope})`;
|
blockString = `callSlot(ctx, node, key, ${slotName})`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (block) {
|
if (block) {
|
||||||
@@ -1117,10 +994,4 @@ export class CodeGenerator {
|
|||||||
block = this.createBlock(block, "multi", ctx);
|
block = this.createBlock(block, "multi", ctx);
|
||||||
this.insertBlock(blockString, block, { ...ctx, forceNewBlock: false });
|
this.insertBlock(blockString, block, { ...ctx, forceNewBlock: false });
|
||||||
}
|
}
|
||||||
|
|
||||||
compileTTranslation(ast: ASTTranslation, ctx: Context) {
|
|
||||||
if (ast.content) {
|
|
||||||
this.compileAST(ast.content, Object.assign({}, ctx, { translate: false }));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -70,7 +70,6 @@ interface Token {
|
|||||||
size?: number;
|
size?: number;
|
||||||
varName?: string;
|
varName?: string;
|
||||||
replace?: Function;
|
replace?: Function;
|
||||||
isLocal?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const STATIC_TOKEN_MAP: { [key: string]: TKind } = Object.assign(Object.create(null), {
|
const STATIC_TOKEN_MAP: { [key: string]: TKind } = Object.assign(Object.create(null), {
|
||||||
@@ -326,13 +325,6 @@ export function compileExprToArray(expr: string): Token[] {
|
|||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
// Mark all variables that have been used locally.
|
|
||||||
// This assumes the expression has only one scope (incorrect but "good enough for now")
|
|
||||||
for (const token of tokens) {
|
|
||||||
if (token.type === "SYMBOL" && localVars.has(token.value)) {
|
|
||||||
token.isLocal = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return tokens;
|
return tokens;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -11,7 +11,7 @@ export const enum ASTType {
|
|||||||
TIf,
|
TIf,
|
||||||
TSet,
|
TSet,
|
||||||
TCall,
|
TCall,
|
||||||
TOut,
|
TRaw,
|
||||||
TForEach,
|
TForEach,
|
||||||
TKey,
|
TKey,
|
||||||
TComponent,
|
TComponent,
|
||||||
@@ -19,7 +19,6 @@ export const enum ASTType {
|
|||||||
TLog,
|
TLog,
|
||||||
TSlot,
|
TSlot,
|
||||||
TCallBlock,
|
TCallBlock,
|
||||||
TTranslation,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ASTText {
|
export interface ASTText {
|
||||||
@@ -35,21 +34,10 @@ export interface ASTComment {
|
|||||||
export interface ASTDomNode {
|
export interface ASTDomNode {
|
||||||
type: ASTType.DomNode;
|
type: ASTType.DomNode;
|
||||||
tag: string;
|
tag: string;
|
||||||
dynamicTag: string | null;
|
|
||||||
attrs: { [key: string]: string };
|
attrs: { [key: string]: string };
|
||||||
content: AST[];
|
content: AST[];
|
||||||
ref: string | null;
|
ref: string | null;
|
||||||
on: { [key: string]: string };
|
on: { [key: string]: string };
|
||||||
model: {
|
|
||||||
baseExpr: string;
|
|
||||||
expr: string;
|
|
||||||
targetAttr: string;
|
|
||||||
specialInitTargetAttr: string | null;
|
|
||||||
eventType: "change" | "click" | "input";
|
|
||||||
shouldTrim: boolean;
|
|
||||||
shouldNumberize: boolean;
|
|
||||||
} | null;
|
|
||||||
ns: string | null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ASTMulti {
|
export interface ASTMulti {
|
||||||
@@ -63,8 +51,8 @@ export interface ASTTEsc {
|
|||||||
defaultValue: string;
|
defaultValue: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ASTTOut {
|
export interface ASTTRaw {
|
||||||
type: ASTType.TOut;
|
type: ASTType.TRaw;
|
||||||
expr: string;
|
expr: string;
|
||||||
body: AST[] | null;
|
body: AST[] | null;
|
||||||
}
|
}
|
||||||
@@ -116,15 +104,14 @@ export interface ASTComponent {
|
|||||||
type: ASTType.TComponent;
|
type: ASTType.TComponent;
|
||||||
name: string;
|
name: string;
|
||||||
isDynamic: boolean;
|
isDynamic: boolean;
|
||||||
dynamicProps: string | null;
|
|
||||||
props: { [name: string]: string };
|
props: { [name: string]: string };
|
||||||
slots: { [name: string]: { content: AST; attrs?: { [key: string]: string }; scope?: string } };
|
handlers: { [event: string]: string };
|
||||||
|
slots: { [name: string]: AST };
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ASTSlot {
|
export interface ASTSlot {
|
||||||
type: ASTType.TSlot;
|
type: ASTType.TSlot;
|
||||||
name: string;
|
name: string;
|
||||||
attrs: { [key: string]: string };
|
|
||||||
defaultContent: AST | null;
|
defaultContent: AST | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,11 +131,6 @@ export interface ASTLog {
|
|||||||
content: AST | null;
|
content: AST | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ASTTranslation {
|
|
||||||
type: ASTType.TTranslation;
|
|
||||||
content: AST | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type AST =
|
export type AST =
|
||||||
| ASTText
|
| ASTText
|
||||||
| ASTComment
|
| ASTComment
|
||||||
@@ -158,29 +140,27 @@ export type AST =
|
|||||||
| ASTTif
|
| ASTTif
|
||||||
| ASTTSet
|
| ASTTSet
|
||||||
| ASTTCall
|
| ASTTCall
|
||||||
| ASTTOut
|
| ASTTRaw
|
||||||
| ASTTForEach
|
| ASTTForEach
|
||||||
| ASTTKey
|
| ASTTKey
|
||||||
| ASTComponent
|
| ASTComponent
|
||||||
| ASTSlot
|
| ASTSlot
|
||||||
| ASTTCallBlock
|
| ASTTCallBlock
|
||||||
| ASTLog
|
| ASTLog
|
||||||
| ASTDebug
|
| ASTDebug;
|
||||||
| ASTTranslation;
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Parser
|
// Parser
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
interface ParsingContext {
|
interface ParsingContext {
|
||||||
inPreTag: boolean;
|
inPreTag: boolean;
|
||||||
inSVG: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function parse(xml: string | Node): AST {
|
export function parse(xml: string): AST {
|
||||||
const node = xml instanceof Element ? xml : (parseXML(`<t>${xml}</t>`).firstChild! as Element);
|
const template = `<t>${xml}</t>`;
|
||||||
normalizeXML(node);
|
const doc = parseXML(template);
|
||||||
const ctx = { inPreTag: false, inSVG: false };
|
const ctx = { inPreTag: false };
|
||||||
const ast = parseNode(node, ctx);
|
const ast = parseNode(doc.firstChild!, ctx);
|
||||||
if (!ast) {
|
if (!ast) {
|
||||||
return { type: ASTType.Text, value: "" };
|
return { type: ASTType.Text, value: "" };
|
||||||
}
|
}
|
||||||
@@ -199,9 +179,8 @@ function parseNode(node: ChildNode, ctx: ParsingContext): AST | null {
|
|||||||
parseTCallBlock(node, ctx) ||
|
parseTCallBlock(node, ctx) ||
|
||||||
parseTEscNode(node, ctx) ||
|
parseTEscNode(node, ctx) ||
|
||||||
parseTKey(node, ctx) ||
|
parseTKey(node, ctx) ||
|
||||||
parseTTranslation(node, ctx) ||
|
|
||||||
parseTSlot(node, ctx) ||
|
parseTSlot(node, ctx) ||
|
||||||
parseTOutNode(node, ctx) ||
|
parseTRawNode(node, ctx) ||
|
||||||
parseComponent(node, ctx) ||
|
parseComponent(node, ctx) ||
|
||||||
parseDOMNode(node, ctx) ||
|
parseDOMNode(node, ctx) ||
|
||||||
parseTSetNode(node, ctx) ||
|
parseTSetNode(node, ctx) ||
|
||||||
@@ -244,7 +223,7 @@ const lineBreakRE = /[\r\n]/;
|
|||||||
const whitespaceRE = /\s+/g;
|
const whitespaceRE = /\s+/g;
|
||||||
|
|
||||||
function parseTextCommentNode(node: ChildNode, ctx: ParsingContext): AST | null {
|
function parseTextCommentNode(node: ChildNode, ctx: ParsingContext): AST | null {
|
||||||
if (node.nodeType === Node.TEXT_NODE) {
|
if (node.nodeType === 3) {
|
||||||
let value = node.textContent || "";
|
let value = node.textContent || "";
|
||||||
if (!ctx.inPreTag) {
|
if (!ctx.inPreTag) {
|
||||||
if (lineBreakRE.test(value) && !value.trim()) {
|
if (lineBreakRE.test(value) && !value.trim()) {
|
||||||
@@ -254,7 +233,7 @@ function parseTextCommentNode(node: ChildNode, ctx: ParsingContext): AST | null
|
|||||||
}
|
}
|
||||||
|
|
||||||
return { type: ASTType.Text, value };
|
return { type: ASTType.Text, value };
|
||||||
} else if (node.nodeType === Node.COMMENT_NODE) {
|
} else if (node.nodeType === 8) {
|
||||||
return { type: ASTType.Comment, value: node.textContent || "" };
|
return { type: ASTType.Comment, value: node.textContent || "" };
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@@ -288,25 +267,20 @@ function parseTDebugLog(node: Element, ctx: ParsingContext): AST | null {
|
|||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Regular dom node
|
// Regular dom node
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
const hasDotAtTheEnd = /\.[\w_]+\s*$/;
|
|
||||||
const hasBracketsAtTheEnd = /\[[^\[]+\]\s*$/;
|
|
||||||
|
|
||||||
function parseDOMNode(node: Element, ctx: ParsingContext): AST | null {
|
function parseDOMNode(node: Element, ctx: ParsingContext): AST | null {
|
||||||
const { tagName } = node;
|
if (node.tagName === "t") {
|
||||||
const dynamicTag = node.getAttribute("t-tag");
|
|
||||||
node.removeAttribute("t-tag");
|
|
||||||
if (tagName === "t" && !dynamicTag) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const children: AST[] = [];
|
const children: AST[] = [];
|
||||||
if (tagName === "pre") {
|
if (node.tagName === "pre") {
|
||||||
ctx.inPreTag = true;
|
ctx = { inPreTag: true };
|
||||||
|
}
|
||||||
|
let ref = null;
|
||||||
|
if (node.hasAttribute("t-ref")) {
|
||||||
|
ref = node.getAttribute("t-ref");
|
||||||
|
node.removeAttribute("t-ref");
|
||||||
}
|
}
|
||||||
const shouldAddSVGNS = tagName === "svg" || (tagName === "g" && !ctx.inSVG);
|
|
||||||
ctx.inSVG = ctx.inSVG || shouldAddSVGNS;
|
|
||||||
const ns = shouldAddSVGNS ? "http://www.w3.org/2000/svg" : null;
|
|
||||||
const ref = node.getAttribute("t-ref");
|
|
||||||
node.removeAttribute("t-ref");
|
|
||||||
|
|
||||||
for (let child of node.childNodes) {
|
for (let child of node.childNodes) {
|
||||||
const ast = parseNode(child, ctx);
|
const ast = parseNode(child, ctx);
|
||||||
@@ -315,57 +289,16 @@ function parseDOMNode(node: Element, ctx: ParsingContext): AST | null {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const nodeAttrsNames = node.getAttributeNames();
|
|
||||||
const attrs: ASTDomNode["attrs"] = {};
|
const attrs: ASTDomNode["attrs"] = {};
|
||||||
const on: ASTDomNode["on"] = {};
|
const on: ASTDomNode["on"] = {};
|
||||||
let model: ASTDomNode["model"] = null;
|
|
||||||
|
|
||||||
for (let attr of nodeAttrsNames) {
|
for (let attr of node.getAttributeNames()) {
|
||||||
const value = node.getAttribute(attr)!;
|
const value = node.getAttribute(attr)!;
|
||||||
if (attr.startsWith("t-on")) {
|
if (attr.startsWith("t-on")) {
|
||||||
if (attr === "t-on") {
|
if (attr === "t-on") {
|
||||||
throw new Error("Missing event name with t-on directive");
|
throw new Error("Missing event name with t-on directive");
|
||||||
}
|
}
|
||||||
on[attr.slice(5)] = value;
|
on[attr.slice(5)] = value;
|
||||||
} else if (attr.startsWith("t-model")) {
|
|
||||||
if (!["input", "select", "textarea"].includes(tagName)) {
|
|
||||||
throw new Error("The t-model directive only works with <input>, <textarea> and <select>");
|
|
||||||
}
|
|
||||||
|
|
||||||
let baseExpr, expr;
|
|
||||||
if (hasDotAtTheEnd.test(value)) {
|
|
||||||
const index = value.lastIndexOf(".");
|
|
||||||
baseExpr = value.slice(0, index);
|
|
||||||
expr = `'${value.slice(index + 1)}'`;
|
|
||||||
} else if (hasBracketsAtTheEnd.test(value)) {
|
|
||||||
const index = value.lastIndexOf("[");
|
|
||||||
baseExpr = value.slice(0, index);
|
|
||||||
expr = value.slice(index + 1, -1);
|
|
||||||
} else {
|
|
||||||
throw new Error(`Invalid t-model expression: "${value}" (it should be assignable)`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const typeAttr = node.getAttribute("type");
|
|
||||||
const isInput = tagName === "input";
|
|
||||||
const isSelect = tagName === "select";
|
|
||||||
const isTextarea = tagName === "textarea";
|
|
||||||
const isCheckboxInput = isInput && typeAttr === "checkbox";
|
|
||||||
const isRadioInput = isInput && typeAttr === "radio";
|
|
||||||
const isOtherInput = isInput && !isCheckboxInput && !isRadioInput;
|
|
||||||
const hasLazyMod = attr.includes(".lazy");
|
|
||||||
const hasNumberMod = attr.includes(".number");
|
|
||||||
const hasTrimMod = attr.includes(".trim");
|
|
||||||
const eventType = isRadioInput ? "click" : isSelect || hasLazyMod ? "change" : "input";
|
|
||||||
|
|
||||||
model = {
|
|
||||||
baseExpr,
|
|
||||||
expr,
|
|
||||||
targetAttr: isCheckboxInput ? "checked" : "value",
|
|
||||||
specialInitTargetAttr: isRadioInput ? "checked" : null,
|
|
||||||
eventType,
|
|
||||||
shouldTrim: hasTrimMod && (isOtherInput || isTextarea),
|
|
||||||
shouldNumberize: hasNumberMod && (isOtherInput || isTextarea),
|
|
||||||
};
|
|
||||||
} else {
|
} else {
|
||||||
if (attr.startsWith("t-") && !attr.startsWith("t-att")) {
|
if (attr.startsWith("t-") && !attr.startsWith("t-att")) {
|
||||||
throw new Error(`Unknown QWeb directive: '${attr}'`);
|
throw new Error(`Unknown QWeb directive: '${attr}'`);
|
||||||
@@ -378,14 +311,11 @@ function parseDOMNode(node: Element, ctx: ParsingContext): AST | null {
|
|||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
type: ASTType.DomNode,
|
type: ASTType.DomNode,
|
||||||
tag: tagName,
|
tag: node.tagName,
|
||||||
dynamicTag,
|
|
||||||
attrs,
|
attrs,
|
||||||
on,
|
on,
|
||||||
ref,
|
ref,
|
||||||
content: children,
|
content: children,
|
||||||
model,
|
|
||||||
ns,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -410,53 +340,56 @@ function parseTEscNode(node: Element, ctx: ParsingContext): AST | null {
|
|||||||
if (!ast) {
|
if (!ast) {
|
||||||
return tesc;
|
return tesc;
|
||||||
}
|
}
|
||||||
if (ast.type === ASTType.DomNode) {
|
if (ast && ast.type === ASTType.DomNode) {
|
||||||
return {
|
return {
|
||||||
...ast,
|
type: ASTType.DomNode,
|
||||||
|
tag: ast.tag,
|
||||||
|
attrs: ast.attrs,
|
||||||
|
on: ast.on,
|
||||||
ref,
|
ref,
|
||||||
content: [tesc],
|
content: [tesc],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (ast.type === ASTType.TComponent) {
|
if (ast && ast.type === ASTType.TComponent) {
|
||||||
throw new Error("t-esc is not supported on Component nodes");
|
return {
|
||||||
|
...ast,
|
||||||
|
slots: { default: tesc },
|
||||||
|
};
|
||||||
}
|
}
|
||||||
return tesc;
|
return tesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// t-out
|
// t-raw
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
function parseTOutNode(node: Element, ctx: ParsingContext): AST | null {
|
function parseTRawNode(node: Element, ctx: ParsingContext): AST | null {
|
||||||
if (!node.hasAttribute("t-out") && !node.hasAttribute("t-raw")) {
|
if (!node.hasAttribute("t-raw")) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (node.hasAttribute("t-raw")) {
|
const expr = node.getAttribute("t-raw")!;
|
||||||
console.warn(
|
|
||||||
`t-raw has been deprecated in favor of t-out. If the value to render is not wrapped by the "markup" function, it will be escaped`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
const expr = (node.getAttribute("t-out") || node.getAttribute("t-raw"))!;
|
|
||||||
node.removeAttribute("t-out");
|
|
||||||
node.removeAttribute("t-raw");
|
node.removeAttribute("t-raw");
|
||||||
|
|
||||||
const tOut: AST = { type: ASTType.TOut, expr, body: null };
|
const tRaw: AST = { type: ASTType.TRaw, expr, body: null };
|
||||||
const ref = node.getAttribute("t-ref");
|
const ref = node.getAttribute("t-ref");
|
||||||
node.removeAttribute("t-ref");
|
node.removeAttribute("t-ref");
|
||||||
const ast = parseNode(node, ctx);
|
const ast = parseNode(node, ctx);
|
||||||
if (!ast) {
|
if (!ast) {
|
||||||
return tOut;
|
return tRaw;
|
||||||
}
|
}
|
||||||
if (ast.type === ASTType.DomNode) {
|
if (ast && ast.type === ASTType.DomNode) {
|
||||||
tOut.body = ast.content.length ? ast.content : null;
|
tRaw.body = ast.content.length ? ast.content : null;
|
||||||
return {
|
return {
|
||||||
...ast,
|
type: ASTType.DomNode,
|
||||||
|
tag: ast.tag,
|
||||||
|
attrs: ast.attrs,
|
||||||
|
on: ast.on,
|
||||||
ref,
|
ref,
|
||||||
content: [tOut],
|
content: [tRaw],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return tOut;
|
return tRaw;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
@@ -473,11 +406,6 @@ function parseTForEach(node: Element, ctx: ParsingContext): AST | null {
|
|||||||
const elem = node.getAttribute("t-as") || "";
|
const elem = node.getAttribute("t-as") || "";
|
||||||
node.removeAttribute("t-as");
|
node.removeAttribute("t-as");
|
||||||
const key = node.getAttribute("t-key");
|
const key = node.getAttribute("t-key");
|
||||||
if (!key) {
|
|
||||||
throw new Error(
|
|
||||||
`"Directive t-foreach should always be used with a t-key!" (expression: t-foreach="${collection}" t-as="${elem}")`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
node.removeAttribute("t-key");
|
node.removeAttribute("t-key");
|
||||||
const memo = node.getAttribute("t-memo") || "";
|
const memo = node.getAttribute("t-memo") || "";
|
||||||
node.removeAttribute("t-memo");
|
node.removeAttribute("t-memo");
|
||||||
@@ -515,7 +443,7 @@ function parseTForEach(node: Element, ctx: ParsingContext): AST | null {
|
|||||||
function hasNoComponent(ast: AST): boolean {
|
function hasNoComponent(ast: AST): boolean {
|
||||||
switch (ast.type) {
|
switch (ast.type) {
|
||||||
case ASTType.TComponent:
|
case ASTType.TComponent:
|
||||||
case ASTType.TOut:
|
case ASTType.TRaw:
|
||||||
case ASTType.TCall:
|
case ASTType.TCall:
|
||||||
case ASTType.TCallBlock:
|
case ASTType.TCallBlock:
|
||||||
case ASTType.TSlot:
|
case ASTType.TSlot:
|
||||||
@@ -529,7 +457,6 @@ function hasNoComponent(ast: AST): boolean {
|
|||||||
return hasNoComponent(ast.content);
|
return hasNoComponent(ast.content);
|
||||||
case ASTType.TDebug:
|
case ASTType.TDebug:
|
||||||
case ASTType.TLog:
|
case ASTType.TLog:
|
||||||
case ASTType.TTranslation:
|
|
||||||
return ast.content ? hasNoComponent(ast.content) : true;
|
return ast.content ? hasNoComponent(ast.content) : true;
|
||||||
case ASTType.TForEach:
|
case ASTType.TForEach:
|
||||||
return ast.hasNoComponent;
|
return ast.hasNoComponent;
|
||||||
@@ -595,7 +522,7 @@ function parseTCall(node: Element, ctx: ParsingContext): AST | null {
|
|||||||
if (ast && ast.type === ASTType.TComponent) {
|
if (ast && ast.type === ASTType.TComponent) {
|
||||||
return {
|
return {
|
||||||
...ast,
|
...ast,
|
||||||
slots: { default: { content: tcall } },
|
slots: { default: tcall },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -704,29 +631,11 @@ function parseTSetNode(node: Element, ctx: ParsingContext): AST | null {
|
|||||||
// Components
|
// Components
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
// Error messages when trying to use an unsupported directive on a component
|
|
||||||
const directiveErrorMap = new Map([
|
|
||||||
["t-on", "t-on is no longer supported on components. Consider passing a callback in props."],
|
|
||||||
[
|
|
||||||
"t-ref",
|
|
||||||
"t-ref is no longer supported on components. Consider exposing only the public part of the component's API through a callback prop.",
|
|
||||||
],
|
|
||||||
["t-att", "t-att makes no sense on component: props are already treated as expressions"],
|
|
||||||
[
|
|
||||||
"t-attf",
|
|
||||||
"t-attf is not supported on components: use template strings for string interpolation in props",
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
|
|
||||||
function parseComponent(node: Element, ctx: ParsingContext): AST | null {
|
function parseComponent(node: Element, ctx: ParsingContext): AST | null {
|
||||||
let name = node.tagName;
|
let name = node.tagName;
|
||||||
const firstLetter = name[0];
|
const firstLetter = name[0];
|
||||||
let isDynamic = node.hasAttribute("t-component");
|
let isDynamic = node.hasAttribute("t-component");
|
||||||
|
|
||||||
if (isDynamic && name !== "t") {
|
|
||||||
throw new Error(`Directive 't-component' can only be used on <t> nodes (used on a <${name}>)`);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(firstLetter === firstLetter.toUpperCase() || isDynamic)) {
|
if (!(firstLetter === firstLetter.toUpperCase() || isDynamic)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -735,15 +644,12 @@ function parseComponent(node: Element, ctx: ParsingContext): AST | null {
|
|||||||
node.removeAttribute("t-component");
|
node.removeAttribute("t-component");
|
||||||
}
|
}
|
||||||
|
|
||||||
const dynamicProps = node.getAttribute("t-props");
|
|
||||||
node.removeAttribute("t-props");
|
|
||||||
|
|
||||||
const props: ASTComponent["props"] = {};
|
const props: ASTComponent["props"] = {};
|
||||||
|
const handlers: ASTComponent["handlers"] = {};
|
||||||
for (let name of node.getAttributeNames()) {
|
for (let name of node.getAttributeNames()) {
|
||||||
const value = node.getAttribute(name)!;
|
const value = node.getAttribute(name)!;
|
||||||
if (name.startsWith("t-")) {
|
if (name.startsWith("t-on-")) {
|
||||||
const message = directiveErrorMap.get(name.split("-").slice(0, 2).join("-"));
|
handlers[name.slice(5)] = value;
|
||||||
throw new Error(message || `unsupported directive on Component: ${name}`);
|
|
||||||
} else {
|
} else {
|
||||||
props[name] = value;
|
props[name] = value;
|
||||||
}
|
}
|
||||||
@@ -756,11 +662,6 @@ function parseComponent(node: Element, ctx: ParsingContext): AST | null {
|
|||||||
// named slots
|
// named slots
|
||||||
const slotNodes = Array.from(clone.querySelectorAll("[t-set-slot]"));
|
const slotNodes = Array.from(clone.querySelectorAll("[t-set-slot]"));
|
||||||
for (let slotNode of slotNodes) {
|
for (let slotNode of slotNodes) {
|
||||||
if (slotNode.tagName !== "t") {
|
|
||||||
throw new Error(
|
|
||||||
`Directive 't-set-slot' can only be used on <t> nodes (used on a <${slotNode.tagName}>)`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
const name = slotNode.getAttribute("t-set-slot")!;
|
const name = slotNode.getAttribute("t-set-slot")!;
|
||||||
|
|
||||||
// check if this is defined in a sub component (in which case it should
|
// check if this is defined in a sub component (in which case it should
|
||||||
@@ -782,30 +683,17 @@ function parseComponent(node: Element, ctx: ParsingContext): AST | null {
|
|||||||
slotNode.remove();
|
slotNode.remove();
|
||||||
const slotAst = parseNode(slotNode, ctx);
|
const slotAst = parseNode(slotNode, ctx);
|
||||||
if (slotAst) {
|
if (slotAst) {
|
||||||
const slotInfo: any = { content: slotAst };
|
slots[name] = slotAst;
|
||||||
const attrs: { [key: string]: string } = {};
|
|
||||||
for (let attributeName of slotNode.getAttributeNames()) {
|
|
||||||
const value = slotNode.getAttribute(attributeName)!;
|
|
||||||
if (attributeName === "t-slot-scope") {
|
|
||||||
slotInfo.scope = value;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
attrs[attributeName] = value;
|
|
||||||
}
|
|
||||||
if (Object.keys(attrs).length) {
|
|
||||||
slotInfo.attrs = attrs;
|
|
||||||
}
|
|
||||||
slots[name] = slotInfo;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// default slot
|
// default slot
|
||||||
const defaultContent = parseChildNodes(clone, ctx);
|
const defaultContent = parseChildNodes(clone, ctx);
|
||||||
if (defaultContent) {
|
if (defaultContent) {
|
||||||
slots.default = { content: defaultContent };
|
slots.default = defaultContent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return { type: ASTType.TComponent, name, isDynamic, dynamicProps, props, slots };
|
return { type: ASTType.TComponent, name, isDynamic, props, handlers, slots };
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
@@ -816,32 +704,13 @@ function parseTSlot(node: Element, ctx: ParsingContext): AST | null {
|
|||||||
if (!node.hasAttribute("t-slot")) {
|
if (!node.hasAttribute("t-slot")) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const name = node.getAttribute("t-slot")!;
|
|
||||||
node.removeAttribute("t-slot");
|
|
||||||
const attrs: { [key: string]: string } = {};
|
|
||||||
for (let attributeName of node.getAttributeNames()) {
|
|
||||||
const value = node.getAttribute(attributeName)!;
|
|
||||||
attrs[attributeName] = value;
|
|
||||||
}
|
|
||||||
return {
|
return {
|
||||||
type: ASTType.TSlot,
|
type: ASTType.TSlot,
|
||||||
name,
|
name: node.getAttribute("t-slot")!,
|
||||||
attrs,
|
|
||||||
defaultContent: parseChildNodes(node, ctx),
|
defaultContent: parseChildNodes(node, ctx),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseTTranslation(node: Element, ctx: ParsingContext): AST | null {
|
|
||||||
if (node.getAttribute("t-translation") !== "off") {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
node.removeAttribute("t-translation");
|
|
||||||
return {
|
|
||||||
type: ASTType.TTranslation,
|
|
||||||
content: parseNode(node, ctx),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// helpers
|
// helpers
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
@@ -863,17 +732,34 @@ function parseChildNodes(node: Element, ctx: ParsingContext): AST | null {
|
|||||||
return { type: ASTType.Multi, content: children };
|
return { type: ASTType.Multi, content: children };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
function parseXML(xml: string): Document {
|
||||||
|
const parser = new DOMParser();
|
||||||
|
|
||||||
/**
|
const doc = parser.parseFromString(xml, "text/xml");
|
||||||
* Normalizes the content of an Element so that t-if/t-elif/t-else directives
|
if (doc.getElementsByTagName("parsererror").length) {
|
||||||
* immediately follow one another (by removing empty text nodes or comments).
|
let msg = "Invalid XML in template.";
|
||||||
* Throws an error when a conditional branching statement is malformed. This
|
const parsererrorText = doc.getElementsByTagName("parsererror")[0].textContent;
|
||||||
* function modifies the Element in place.
|
if (parsererrorText) {
|
||||||
*
|
msg += "\nThe parser has produced the following error message:\n" + parsererrorText;
|
||||||
* @param el the element containing the tree that should be normalized
|
const re = /\d+/g;
|
||||||
*/
|
const firstMatch = re.exec(parsererrorText);
|
||||||
function normalizeTIf(el: Element) {
|
if (firstMatch) {
|
||||||
let tbranch = el.querySelectorAll("[t-elif], [t-else]");
|
const lineNumber = Number(firstMatch[0]);
|
||||||
|
const line = xml.split("\n")[lineNumber - 1];
|
||||||
|
const secondMatch = re.exec(parsererrorText);
|
||||||
|
if (line && secondMatch) {
|
||||||
|
const columnIndex = Number(secondMatch[0]) - 1;
|
||||||
|
if (line[columnIndex]) {
|
||||||
|
msg +=
|
||||||
|
`\nThe error might be located at xml line ${lineNumber} column ${columnIndex}\n` +
|
||||||
|
`${line}\n${"-".repeat(columnIndex - 1)}^`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new Error(msg);
|
||||||
|
}
|
||||||
|
let tbranch = doc.querySelectorAll("[t-elif], [t-else]");
|
||||||
for (let i = 0, ilen = tbranch.length; i < ilen; i++) {
|
for (let i = 0, ilen = tbranch.length; i < ilen; i++) {
|
||||||
let node = tbranch[i];
|
let node = tbranch[i];
|
||||||
let prevElem = node.previousElementSibling!;
|
let prevElem = node.previousElementSibling!;
|
||||||
@@ -907,78 +793,6 @@ function normalizeTIf(el: Element) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Normalizes the content of an Element so that t-esc directives on components
|
|
||||||
* are removed and instead places a <t t-esc=""> as the default slot of the
|
|
||||||
* component. Also throws if the component already has content. This function
|
|
||||||
* modifies the Element in place.
|
|
||||||
*
|
|
||||||
* @param el the element containing the tree that should be normalized
|
|
||||||
*/
|
|
||||||
function normalizeTEsc(el: Element) {
|
|
||||||
const elements = [...el.querySelectorAll("[t-esc]")].filter(
|
|
||||||
(el) => el.tagName[0] === el.tagName[0].toUpperCase() || el.hasAttribute("t-component")
|
|
||||||
);
|
|
||||||
for (const el of elements) {
|
|
||||||
if (el.childNodes.length) {
|
|
||||||
throw new Error("Cannot have t-esc on a component that already has content");
|
|
||||||
}
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Normalizes the tree inside a given element and do some preliminary validation
|
|
||||||
* on it. This function modifies the Element in place.
|
|
||||||
*
|
|
||||||
* @param el the element containing the tree that should be normalized
|
|
||||||
*/
|
|
||||||
function normalizeXML(el: Element) {
|
|
||||||
normalizeTIf(el);
|
|
||||||
normalizeTEsc(el);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parses an XML string into an XML document, throwing errors on parser errors
|
|
||||||
* instead of returning an XML document containing the parseerror.
|
|
||||||
*
|
|
||||||
* @param xml the string to parse
|
|
||||||
* @returns an XML document corresponding to the content of the string
|
|
||||||
*/
|
|
||||||
function parseXML(xml: string): XMLDocument {
|
|
||||||
const parser = new DOMParser();
|
|
||||||
const doc = parser.parseFromString(xml, "text/xml");
|
|
||||||
if (doc.getElementsByTagName("parsererror").length) {
|
|
||||||
let msg = "Invalid XML in template.";
|
|
||||||
const parsererrorText = doc.getElementsByTagName("parsererror")[0].textContent;
|
|
||||||
if (parsererrorText) {
|
|
||||||
msg += "\nThe parser has produced the following error message:\n" + parsererrorText;
|
|
||||||
const re = /\d+/g;
|
|
||||||
const firstMatch = re.exec(parsererrorText);
|
|
||||||
if (firstMatch) {
|
|
||||||
const lineNumber = Number(firstMatch[0]);
|
|
||||||
const line = xml.split("\n")[lineNumber - 1];
|
|
||||||
const secondMatch = re.exec(parsererrorText);
|
|
||||||
if (line && secondMatch) {
|
|
||||||
const columnIndex = Number(secondMatch[0]) - 1;
|
|
||||||
if (line[columnIndex]) {
|
|
||||||
msg +=
|
|
||||||
`\nThe error might be located at xml line ${lineNumber} column ${columnIndex}\n` +
|
|
||||||
`${line}\n${"-".repeat(columnIndex - 1)}^`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new Error(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
return doc;
|
return doc;
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,129 @@
|
|||||||
|
// import { compileTemplate, Template } from "./qweb/index";
|
||||||
|
import { BDom, createBlock, html, list, multi, text, toggler } from "../blockdom";
|
||||||
|
import { component } from "../component/component_node";
|
||||||
|
import { Template, compileTemplate } from "./compiler";
|
||||||
|
|
||||||
|
const bdom = { text, createBlock, list, multi, html, toggler, component };
|
||||||
|
|
||||||
|
export const globalTemplates: { [key: string]: string } = {};
|
||||||
|
|
||||||
|
function withDefault(value: any, defaultValue: any): any {
|
||||||
|
return value === undefined || value === null || value === false ? defaultValue : value;
|
||||||
|
}
|
||||||
|
|
||||||
|
function callSlot(
|
||||||
|
ctx: any,
|
||||||
|
parent: any,
|
||||||
|
key: string,
|
||||||
|
name: string,
|
||||||
|
defaultSlot?: (ctx: any, key: string) => BDom,
|
||||||
|
dynamic?: boolean
|
||||||
|
): BDom | null {
|
||||||
|
const slots = ctx.__owl__.slots;
|
||||||
|
const slotFn = slots[name];
|
||||||
|
const slotBDom = slotFn ? slotFn(parent, key) : null;
|
||||||
|
if (defaultSlot) {
|
||||||
|
let child1: BDom | undefined = undefined;
|
||||||
|
let child2: BDom | undefined = undefined;
|
||||||
|
// const result = new BMulti(2);
|
||||||
|
if (slotBDom) {
|
||||||
|
child1 = dynamic ? toggler(name, slotBDom) : slotBDom;
|
||||||
|
} else {
|
||||||
|
child2 = defaultSlot(parent, key);
|
||||||
|
}
|
||||||
|
return multi([child1, child2]);
|
||||||
|
}
|
||||||
|
return slotBDom;
|
||||||
|
}
|
||||||
|
|
||||||
|
function capture(ctx: any): any {
|
||||||
|
const component = ctx.__owl__.component;
|
||||||
|
const result = Object.create(component);
|
||||||
|
for (let k in ctx) {
|
||||||
|
result[k] = ctx[k];
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function withKey(elem: any, k: string) {
|
||||||
|
elem.key = k;
|
||||||
|
return elem;
|
||||||
|
}
|
||||||
|
|
||||||
|
function prepareList(collection: any): [any[], any[], number, any[]] {
|
||||||
|
let keys: any[];
|
||||||
|
let values: any[];
|
||||||
|
|
||||||
|
if (Array.isArray(collection)) {
|
||||||
|
keys = collection;
|
||||||
|
values = collection;
|
||||||
|
} else if (collection) {
|
||||||
|
values = Object.keys(collection);
|
||||||
|
keys = Object.values(collection);
|
||||||
|
} else {
|
||||||
|
throw new Error("Invalid loop expression");
|
||||||
|
}
|
||||||
|
const n = values.length;
|
||||||
|
return [keys, values, n, new Array(n)];
|
||||||
|
}
|
||||||
|
export const UTILS = {
|
||||||
|
// elem,
|
||||||
|
// setText,
|
||||||
|
withDefault,
|
||||||
|
zero: Symbol("zero"),
|
||||||
|
callSlot,
|
||||||
|
capture,
|
||||||
|
// toClassObj,
|
||||||
|
withKey,
|
||||||
|
prepareList,
|
||||||
|
shallowEqual,
|
||||||
|
};
|
||||||
|
|
||||||
|
export class TemplateSet {
|
||||||
|
rawTemplates: { [name: string]: string } = Object.create(globalTemplates);
|
||||||
|
templates: { [name: string]: Template } = {};
|
||||||
|
utils: typeof UTILS;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
const call = (subTemplate: string, ctx: any, parent: any) => {
|
||||||
|
const template = this.getTemplate(subTemplate);
|
||||||
|
return toggler(subTemplate, template(ctx, parent));
|
||||||
|
};
|
||||||
|
|
||||||
|
const getTemplate = (name: string) => this.getTemplate(name);
|
||||||
|
this.utils = Object.assign({}, UTILS, { getTemplate, call });
|
||||||
|
}
|
||||||
|
|
||||||
|
addTemplate(name: string, template: string, options: { allowDuplicate?: boolean } = {}) {
|
||||||
|
if (name in this.rawTemplates && !options.allowDuplicate) {
|
||||||
|
throw new Error(`Template ${name} already defined`);
|
||||||
|
}
|
||||||
|
this.rawTemplates[name] = template;
|
||||||
|
}
|
||||||
|
|
||||||
|
getTemplate(name: string): Template {
|
||||||
|
if (!(name in this.templates)) {
|
||||||
|
const rawTemplate = this.rawTemplates[name];
|
||||||
|
if (rawTemplate === undefined) {
|
||||||
|
throw new Error(`Missing template: "${name}"`);
|
||||||
|
}
|
||||||
|
const templateFn = compileTemplate(rawTemplate, name);
|
||||||
|
|
||||||
|
// first add a function to lazily get the template, in case there is a
|
||||||
|
// recursive call to the template name
|
||||||
|
this.templates[name] = (context, parent) => this.templates[name](context, parent);
|
||||||
|
const template = templateFn(bdom, this.utils);
|
||||||
|
this.templates[name] = template;
|
||||||
|
}
|
||||||
|
return this.templates[name];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function shallowEqual(l1: any[], l2: any[]): boolean {
|
||||||
|
for (let i = 0, l = l1.length; i < l; i++) {
|
||||||
|
if (l1[i] !== l2[i]) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
+129
-225
@@ -1,240 +1,144 @@
|
|||||||
import { onWillUnmount } from "./component/lifecycle_hooks";
|
import { getCurrent } from "./component/component_node";
|
||||||
import { ComponentNode, getCurrent } from "./component/component_node";
|
|
||||||
|
|
||||||
// Allows to get the target of a Reactive (used for making a new Reactive from the underlying object)
|
export function useState<T>(state: T): T {
|
||||||
const TARGET = Symbol("Target");
|
const node = getCurrent()!;
|
||||||
// Special key to subscribe to, to be notified of key creation/deletion
|
return observe(state, () => node.render());
|
||||||
const KEYCHANGES = Symbol("Key changes");
|
}
|
||||||
|
|
||||||
type ObjectKey = string | number | symbol;
|
type CB = () => void;
|
||||||
type Target = object;
|
const observers: WeakMap<any, PSet<CB>> = new WeakMap();
|
||||||
type Callback = () => void;
|
|
||||||
type Reactive<T extends Target = Target> = T & {
|
|
||||||
[TARGET]: any;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether a given value can be made into a reactive object.
|
* PSet (for Prototypal Set) are sets that can lookup in their "parent sets", if
|
||||||
*
|
* any.
|
||||||
* @param value the value to check
|
|
||||||
* @returns whether the value can be made reactive
|
|
||||||
*/
|
*/
|
||||||
function canBeMadeReactive(value: any): boolean {
|
|
||||||
|
class PSet<T> extends Set<T> {
|
||||||
|
parent?: PSet<T>;
|
||||||
|
|
||||||
|
static createChild<T>(parent: PSet<T>): PSet<T> {
|
||||||
|
const pset: PSet<T> = new PSet();
|
||||||
|
pset.parent = parent;
|
||||||
|
return pset;
|
||||||
|
}
|
||||||
|
|
||||||
|
has(key: T): boolean {
|
||||||
|
if (super.has(key)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return this.parent ? this.parent.has(key) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
*[Symbol.iterator](): Generator<T> {
|
||||||
|
let iterator = super[Symbol.iterator]();
|
||||||
|
for (let elem of iterator) {
|
||||||
|
yield elem;
|
||||||
|
}
|
||||||
|
if (this.parent) {
|
||||||
|
for (let elem of this.parent) {
|
||||||
|
yield elem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
export function observe<T>(value: T, cb: CB): T {
|
||||||
|
if (isNotObservable(value)) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
if (observers.has(value)) {
|
||||||
|
const callbacks = observers.get(value)!;
|
||||||
|
callbacks.add(cb);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
const callbacks: PSet<CB> = new PSet();
|
||||||
|
callbacks.add(cb);
|
||||||
|
return observeValue(value, callbacks);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function unobserve<T>(value: T, cb: () => void) {
|
||||||
|
if (isNotObservable(value)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (observers.has(value)) {
|
||||||
|
const callbacks = observers.get(value)!;
|
||||||
|
callbacks.delete(cb);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function isNotObservable(value: any): boolean {
|
||||||
return (
|
return (
|
||||||
typeof value === "object" &&
|
value === null || typeof value !== "object" || value instanceof Date || value instanceof Promise
|
||||||
value !== null &&
|
|
||||||
!(value instanceof Date) &&
|
|
||||||
!(value instanceof Promise) &&
|
|
||||||
!(value instanceof String) &&
|
|
||||||
!(value instanceof Number)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const targetToKeysToCallbacks = new WeakMap<Target, Map<ObjectKey, Set<Callback>>>();
|
|
||||||
/**
|
/**
|
||||||
* Observes a given key on a target with an callback. The callback will be
|
* value should
|
||||||
* called when the given key changes on the target.
|
* 1. be observable
|
||||||
*
|
* 2. not yet be observed
|
||||||
* @param target the target whose key should be observed
|
|
||||||
* @param key the key to observe (or Symbol(KEYCHANGES) for key creation
|
|
||||||
* or deletion)
|
|
||||||
* @param callback the function to call when the key changes
|
|
||||||
*/
|
*/
|
||||||
function observeTargetKey(target: Target, key: ObjectKey, callback: Callback): void {
|
function observeValue(value: any, callbacks: PSet<CB>): any {
|
||||||
if (!targetToKeysToCallbacks.get(target)) {
|
const proxy = new Proxy(value as any, {
|
||||||
targetToKeysToCallbacks.set(target, new Map());
|
get(target: any, key: any): any {
|
||||||
}
|
const current = target[key];
|
||||||
const keyToCallbacks = targetToKeysToCallbacks.get(target)!;
|
if (isNotObservable(current)) {
|
||||||
if (!keyToCallbacks.get(key)) {
|
return current;
|
||||||
keyToCallbacks.set(key, new Set());
|
}
|
||||||
}
|
if (observers.has(current)) {
|
||||||
keyToCallbacks.get(key)!.add(callback);
|
// this is wrong ?
|
||||||
}
|
observers.get(current)!.parent = callbacks;
|
||||||
/**
|
return current;
|
||||||
* Notify Reactives that are observing a given target that a key has changed on
|
}
|
||||||
* the target.
|
const subCallbacks = PSet.createChild(callbacks);
|
||||||
*
|
const subValue = observeValue(current, subCallbacks);
|
||||||
* @param target target whose Reactives should be notified that the target was
|
target[key] = subValue;
|
||||||
* changed.
|
return subValue;
|
||||||
* @param key the key that changed (or Symbol `KEYCHANGES` if a key was created
|
},
|
||||||
* or deleted)
|
set(target: any, key: any, value: any): boolean {
|
||||||
*/
|
// TODO: check if current !== target or proxy ??
|
||||||
function notifyReactives(target: Target, key: ObjectKey): void {
|
const current = target[key];
|
||||||
const keyToCallbacks = targetToKeysToCallbacks.get(target);
|
if (current !== value) {
|
||||||
if (!keyToCallbacks) {
|
if (isNotObservable(value)) {
|
||||||
return;
|
target[key] = value;
|
||||||
}
|
} else {
|
||||||
const callbacks = keyToCallbacks.get(key);
|
// TODO: test following scenario:
|
||||||
if (!callbacks) {
|
// 1. obj1 = observer({a:1}, somecb);
|
||||||
return;
|
// 2. unobserve(obj1, somecb)
|
||||||
}
|
// 3. obj1.a = {b: 2};
|
||||||
// Loop on copy because clearReactivesForCallback will modify the set in place
|
// check that somecb was not called
|
||||||
for (const callback of [...callbacks]) {
|
// obj1.a.b = 3;
|
||||||
clearReactivesForCallback(callback);
|
// check again that somecb was not called
|
||||||
callback();
|
if (observers.has(value)) {
|
||||||
}
|
const pset = observers.get(value)!;
|
||||||
|
pset.parent = callbacks;
|
||||||
|
target[key] = value;
|
||||||
|
} else {
|
||||||
|
const subCallbacks = PSet.createChild(callbacks);
|
||||||
|
target[key] = observeValue(value, subCallbacks);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
notify(target);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
deleteProperty(target: any, key: any) {
|
||||||
|
if (key in target) {
|
||||||
|
delete target[key];
|
||||||
|
notify(target);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
observers.set(value, callbacks);
|
||||||
|
observers.set(proxy, callbacks);
|
||||||
|
return proxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
const callbacksToTargets = new WeakMap<Callback, Set<Target>>();
|
function notify(value: any) {
|
||||||
/**
|
const cbs = observers.get(value)!;
|
||||||
* Clears all subscriptions of the Reactives associated with a given callback.
|
for (let cb of cbs) {
|
||||||
*
|
cb();
|
||||||
* @param callback the callback for which the reactives need to be cleared
|
|
||||||
*/
|
|
||||||
function clearReactivesForCallback(callback: Callback): void {
|
|
||||||
const targetsToClear = callbacksToTargets.get(callback);
|
|
||||||
if (!targetsToClear) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (const target of targetsToClear) {
|
|
||||||
const observedKeys = targetToKeysToCallbacks.get(target);
|
|
||||||
if (!observedKeys) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
for (const callbacks of observedKeys.values()) {
|
|
||||||
callbacks.delete(callback);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const reactiveCache = new WeakMap<Target, Map<Callback, Reactive>>();
|
|
||||||
/**
|
|
||||||
* Creates a reactive proxy for an object. Reading data on the reactive object
|
|
||||||
* subscribes to changes to the data. Writing data on the object will cause the
|
|
||||||
* notify callback to be called if there are suscriptions to that data. Nested
|
|
||||||
* objects and arrays are automatically made reactive as well.
|
|
||||||
*
|
|
||||||
* Whenever you are notified of a change, all subscriptions are cleared, and if
|
|
||||||
* you would like to be notified of any further changes, you should go read
|
|
||||||
* the underlying data again. We assume that if you don't go read it again after
|
|
||||||
* being notified, it means that you are no longer interested in that data.
|
|
||||||
*
|
|
||||||
* Subscriptions:
|
|
||||||
* + Reading a property on an object will subscribe you to changes in the value
|
|
||||||
* of that property.
|
|
||||||
* + Accessing an object keys (eg with Object.keys or with `for..in`) will
|
|
||||||
* subscribe you to the creation/deletion of keys. Checking the presence of a
|
|
||||||
* key on the object with 'in' has the same effect.
|
|
||||||
* - getOwnPropertyDescriptor does not currently subscribe you to the property.
|
|
||||||
* This is a choice that was made because changing a key's value will trigger
|
|
||||||
* this trap and we do not want to subscribe by writes. This also means that
|
|
||||||
* Object.hasOwnProperty doesn't subscribe as it goes through this trap.
|
|
||||||
*
|
|
||||||
* @param target the object for which to create a reactive proxy
|
|
||||||
* @param callback the function to call when an observed property of the
|
|
||||||
* reactive has changed
|
|
||||||
* @returns a proxy that tracks changes to it
|
|
||||||
*/
|
|
||||||
export function reactive<T extends Target>(target: T, callback: Callback): Reactive<T> {
|
|
||||||
if (!canBeMadeReactive(target)) {
|
|
||||||
throw new Error(`Cannot make the given value reactive`);
|
|
||||||
}
|
|
||||||
const originalTarget = (target as Reactive)[TARGET];
|
|
||||||
if (originalTarget) {
|
|
||||||
return reactive(originalTarget, callback);
|
|
||||||
}
|
|
||||||
if (!reactiveCache.has(target)) {
|
|
||||||
reactiveCache.set(target, new Map());
|
|
||||||
}
|
|
||||||
const reactivesForTarget = reactiveCache.get(target)!;
|
|
||||||
if (!reactivesForTarget.has(callback)) {
|
|
||||||
const proxy = new Proxy(target, {
|
|
||||||
get(target: any, key: ObjectKey, proxy: Reactive<T>) {
|
|
||||||
if (key === TARGET) {
|
|
||||||
return target;
|
|
||||||
}
|
|
||||||
observeTargetKey(target, key, callback);
|
|
||||||
const value = Reflect.get(target, key, proxy);
|
|
||||||
if (!canBeMadeReactive(value)) {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
return reactive(value, callback);
|
|
||||||
},
|
|
||||||
set(target, key, value, proxy) {
|
|
||||||
const isNewKey = !Object.hasOwnProperty.call(target, key);
|
|
||||||
const originalValue = Reflect.get(target, key, proxy);
|
|
||||||
const ret = Reflect.set(target, key, value, proxy);
|
|
||||||
if (isNewKey) {
|
|
||||||
notifyReactives(target, KEYCHANGES);
|
|
||||||
}
|
|
||||||
// While Array length may trigger the set trap, it's not actually set by this
|
|
||||||
// method but is updated behind the scenes, and the trap is not called with the
|
|
||||||
// new value. We disable the "same-value-optimization" for it because of that.
|
|
||||||
if (originalValue !== value || (Array.isArray(target) && key === "length")) {
|
|
||||||
notifyReactives(target, key);
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
},
|
|
||||||
deleteProperty(target, key) {
|
|
||||||
const ret = Reflect.deleteProperty(target, key);
|
|
||||||
notifyReactives(target, KEYCHANGES);
|
|
||||||
notifyReactives(target, key);
|
|
||||||
return ret;
|
|
||||||
},
|
|
||||||
ownKeys(target) {
|
|
||||||
observeTargetKey(target, KEYCHANGES, callback);
|
|
||||||
return Reflect.ownKeys(target);
|
|
||||||
},
|
|
||||||
has(target, key) {
|
|
||||||
// TODO: this observes all key changes instead of only the presence of the argument key
|
|
||||||
observeTargetKey(target, KEYCHANGES, callback);
|
|
||||||
return Reflect.has(target, key);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
reactivesForTarget.set(callback, proxy);
|
|
||||||
if (!callbacksToTargets.has(callback)) {
|
|
||||||
callbacksToTargets.set(callback, new Set());
|
|
||||||
}
|
|
||||||
callbacksToTargets.get(callback)!.add(target);
|
|
||||||
}
|
|
||||||
return reactivesForTarget.get(callback) as Reactive<T>;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a batched version of a callback so that all calls to it in the same
|
|
||||||
* microtick will only call the original callback once.
|
|
||||||
*
|
|
||||||
* @param callback the callback to batch
|
|
||||||
* @returns a batched version of the original callback
|
|
||||||
*/
|
|
||||||
export function batched(callback: Callback): Callback {
|
|
||||||
let called = false;
|
|
||||||
return async () => {
|
|
||||||
// This await blocks all calls to the callback here, then releases them sequentially
|
|
||||||
// in the next microtick. This line decides the granularity of the batch.
|
|
||||||
await Promise.resolve();
|
|
||||||
if (!called) {
|
|
||||||
called = true;
|
|
||||||
callback();
|
|
||||||
// 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
|
|
||||||
await Promise.resolve();
|
|
||||||
called = false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const batchedRenderFunctions = new WeakMap<ComponentNode, Callback>();
|
|
||||||
/**
|
|
||||||
* Creates a reactive object that will be observed by the current component.
|
|
||||||
* Reading data from the returned object (eg during rendering) will cause the
|
|
||||||
* component to subscribe to that data and be rerendered when it changes.
|
|
||||||
*
|
|
||||||
* @param state the state to observe
|
|
||||||
* @returns a reactive object that will cause the component to re-render on
|
|
||||||
* relevant changes
|
|
||||||
* @see reactive
|
|
||||||
*/
|
|
||||||
export function useState<T extends object>(state: T): Reactive<T> {
|
|
||||||
const node = getCurrent()!;
|
|
||||||
if (!batchedRenderFunctions.has(node)) {
|
|
||||||
batchedRenderFunctions.set(
|
|
||||||
node,
|
|
||||||
batched(() => node.render())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
const render = batchedRenderFunctions.get(node)!;
|
|
||||||
const reactiveState = reactive(state, render);
|
|
||||||
onWillUnmount(() => clearReactivesForCallback(render));
|
|
||||||
return reactiveState;
|
|
||||||
}
|
|
||||||
|
|||||||
+36
@@ -0,0 +1,36 @@
|
|||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// useRef
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
import type { Component } from "./component/component";
|
||||||
|
import { getCurrent } from "./component/component_node";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The purpose of this hook is to allow components to get a reference to a sub
|
||||||
|
* html node or component.
|
||||||
|
*/
|
||||||
|
interface Ref<C extends Component = Component> {
|
||||||
|
el: HTMLElement | null;
|
||||||
|
comp: C | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useRef<C extends Component = Component>(name: string): Ref<C> {
|
||||||
|
const node = getCurrent()!;
|
||||||
|
return {
|
||||||
|
get el(): HTMLElement | null {
|
||||||
|
const val = node.refs[name];
|
||||||
|
return val!;
|
||||||
|
// if (val instanceof HTMLElement) {
|
||||||
|
// return val;
|
||||||
|
// } else if (val instanceof Component) {
|
||||||
|
// return val.el;
|
||||||
|
// }
|
||||||
|
// return null;
|
||||||
|
},
|
||||||
|
get comp(): C | null {
|
||||||
|
return null;
|
||||||
|
// const val = node.refs && node.refs[name];
|
||||||
|
// return val instanceof Component ? (val as C) : null;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
+3
-17
@@ -1,28 +1,14 @@
|
|||||||
import { registerSheet } from "./component/style";
|
import { globalTemplates } from "./qweb/template_helpers";
|
||||||
import { globalTemplates } from "./app/template_set";
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Global templates
|
// Global templates
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
export function xml(...args: Parameters<typeof String.raw>) {
|
export function xml(strings: TemplateStringsArray, ...args: any[]) {
|
||||||
const name = `__template__${xml.nextId++}`;
|
const name = `__template__${xml.nextId++}`;
|
||||||
const value = String.raw(...args);
|
const value = String.raw(strings, ...args);
|
||||||
globalTemplates[name] = value;
|
globalTemplates[name] = value;
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
xml.nextId = 1;
|
xml.nextId = 1;
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
// Global stylesheets
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
export function css(strings: TemplateStringsArray, ...args: any[]) {
|
|
||||||
const name = `__sheet__${css.nextId++}`;
|
|
||||||
const value = String.raw(strings, ...args);
|
|
||||||
registerSheet(name, value);
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
css.nextId = 1;
|
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
export class EventBus extends EventTarget {
|
|
||||||
trigger(name: string, payload?: any) {
|
|
||||||
this.dispatchEvent(new CustomEvent(name, { detail: payload }));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function whenReady(fn?: any): Promise<void> {
|
|
||||||
return new Promise(function (resolve) {
|
|
||||||
if (document.readyState !== "loading") {
|
|
||||||
resolve(true);
|
|
||||||
} else {
|
|
||||||
document.addEventListener("DOMContentLoaded", resolve, false);
|
|
||||||
}
|
|
||||||
}).then(fn || function () {});
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function loadFile(url: string): Promise<string> {
|
|
||||||
const result = await fetch(url);
|
|
||||||
if (!result.ok) {
|
|
||||||
throw new Error("Error while fetching xml templates");
|
|
||||||
}
|
|
||||||
return await result.text();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This class just transports the fact that a string is safe
|
|
||||||
* to be injected as HTML. Overriding a JS primitive is quite painful though
|
|
||||||
* so we need to redfine toString and valueOf.
|
|
||||||
*/
|
|
||||||
export class Markup extends String {}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Marks a value as safe, that is, a value that can be injected as HTML directly.
|
|
||||||
* It should be used to wrap the value passed to a t-out directive to allow a raw rendering.
|
|
||||||
*/
|
|
||||||
export function markup(value: any) {
|
|
||||||
return new Markup(value);
|
|
||||||
}
|
|
||||||
@@ -1,401 +0,0 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
||||||
|
|
||||||
exports[`Reactivity: useState concurrent renderings 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-text-0/><block-text-1/></span>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = ctx['context'][ctx['props'].key].n;
|
|
||||||
let d2 = ctx['state'].x;
|
|
||||||
return block1([d1, d2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`Reactivity: useState concurrent renderings 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<p><block-child-0/></p>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2 = component(\`ComponentC\`, {key: ctx['props'].key}, key + \`__1\`, node, ctx);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`Reactivity: useState concurrent renderings 3`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2 = component(\`ComponentB\`, {key: ctx['context'].key}, key + \`__1\`, node, ctx);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`Reactivity: useState destroyed component before being mounted is inactive 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = ctx['contextObj'].a;
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`Reactivity: useState destroyed component before being mounted is inactive 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2;
|
|
||||||
if (ctx['state'].flag) {
|
|
||||||
b2 = component(\`Child\`, {}, key + \`__1\`, node, ctx);
|
|
||||||
}
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`Reactivity: useState destroyed component is inactive 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = ctx['contextObj'].a;
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`Reactivity: useState destroyed component is inactive 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2;
|
|
||||||
if (ctx['state'].flag) {
|
|
||||||
b2 = component(\`Child\`, {}, key + \`__1\`, node, ctx);
|
|
||||||
}
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`Reactivity: useState one components can subscribe twice to same context 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/><block-text-1/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = ctx['contextObj1'].a;
|
|
||||||
let d2 = ctx['contextObj2'].b;
|
|
||||||
return block1([d1, d2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`Reactivity: useState parent and children subscribed to same context 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = ctx['contextObj'].a;
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`Reactivity: useState parent and children subscribed to same context 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><block-text-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2 = component(\`Child\`, {}, key + \`__1\`, node, ctx);
|
|
||||||
let d1 = ctx['contextObj'].b;
|
|
||||||
return block1([d1], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`Reactivity: useState several nodes on different level use same context 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/> <block-text-1/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = ctx['contextObj'].a;
|
|
||||||
let d2 = ctx['contextObj'].b;
|
|
||||||
return block1([d1, d2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`Reactivity: useState several nodes on different level use same context 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = ctx['contextObj'].b;
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`Reactivity: useState several nodes on different level use same context 3`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = ctx['contextObj'].a;
|
|
||||||
let b2 = component(\`L3A\`, {}, key + \`__1\`, node, ctx);
|
|
||||||
return block1([d1], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`Reactivity: useState several nodes on different level use same context 4`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2 = component(\`L2A\`, {}, key + \`__1\`, node, ctx);
|
|
||||||
let b3 = component(\`L2B\`, {}, key + \`__2\`, node, ctx);
|
|
||||||
return block1([], [b2, b3]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`Reactivity: useState two components are updated in parallel 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = ctx['contextObj'].value;
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`Reactivity: useState two components are updated in parallel 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2 = component(\`Child\`, {}, key + \`__1\`, node, ctx);
|
|
||||||
let b3 = component(\`Child\`, {}, key + \`__2\`, node, ctx);
|
|
||||||
return block1([], [b2, b3]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`Reactivity: useState two components can subscribe to same context 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = ctx['contextObj'].value;
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`Reactivity: useState two components can subscribe to same context 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2 = component(\`Child\`, {}, key + \`__1\`, node, ctx);
|
|
||||||
let b3 = component(\`Child\`, {}, key + \`__2\`, node, ctx);
|
|
||||||
return block1([], [b2, b3]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`Reactivity: useState two independent components on different levels are updated in parallel 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = ctx['contextObj'].value;
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`Reactivity: useState two independent components on different levels are updated in parallel 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2 = component(\`Child\`, {}, key + \`__1\`, node, ctx);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`Reactivity: useState two independent components on different levels are updated in parallel 3`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2 = component(\`Child\`, {}, key + \`__1\`, node, ctx);
|
|
||||||
let b3 = component(\`Parent\`, {}, key + \`__2\`, node, ctx);
|
|
||||||
return block1([], [b2, b3]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`Reactivity: useState useContext=useState hook is reactive, for one component 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = ctx['contextObj'].value;
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`Reactivity: useState useless atoms should be deleted 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = ctx['state'].quantity;
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`Reactivity: useState useless atoms should be deleted 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/> Total: <block-text-0/> Count: <block-text-1/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
ctx = Object.create(ctx);
|
|
||||||
const [k_block2, v_block2, l_block2, c_block2] = prepareList(Object.keys(ctx['state']));
|
|
||||||
for (let i1 = 0; i1 < l_block2; i1++) {
|
|
||||||
ctx[\`id\`] = v_block2[i1];
|
|
||||||
let key1 = ctx['id'];
|
|
||||||
c_block2[i1] = withKey(component(\`Quantity\`, {id: ctx['id']}, key + \`__1__\${key1}\`, node, ctx), key1);
|
|
||||||
}
|
|
||||||
ctx = ctx.__proto__;
|
|
||||||
let b2 = list(c_block2);
|
|
||||||
let d1 = ctx['total'];
|
|
||||||
let d2 = Object.keys(ctx['state']).length;
|
|
||||||
return block1([d1, d2], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`Reactivity: useState very simple use, with initial value 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = ctx['contextObj'].value;
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
@@ -61,7 +61,6 @@ test("simple event handling ", async () => {
|
|||||||
const [owner, method] = data;
|
const [owner, method] = data;
|
||||||
owner[method]();
|
owner[method]();
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const block = createBlock('<div block-handler-0="click"></div>');
|
const block = createBlock('<div block-handler-0="click"></div>');
|
||||||
@@ -107,167 +106,3 @@ test("two same block nodes with different handlers", async () => {
|
|||||||
(fixture.firstChild!.nextSibling as HTMLDivElement).click();
|
(fixture.firstChild!.nextSibling as HTMLDivElement).click();
|
||||||
expect(steps).toEqual(["1", "2"]);
|
expect(steps).toEqual(["1", "2"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("two same block nodes with different handlers (synthetic)", async () => {
|
|
||||||
const block = createBlock('<div block-handler-0="click.synthetic"></div>');
|
|
||||||
let steps: string[] = [];
|
|
||||||
let handler1 = () => steps.push("1");
|
|
||||||
let handler2 = () => steps.push("2");
|
|
||||||
const tree = multi([block([handler1]), block([handler2])]);
|
|
||||||
|
|
||||||
mount(tree, fixture);
|
|
||||||
expect(fixture.innerHTML).toBe("<div></div><div></div>");
|
|
||||||
|
|
||||||
(fixture.firstChild as HTMLDivElement).click();
|
|
||||||
(fixture.firstChild!.nextSibling as HTMLDivElement).click();
|
|
||||||
expect(steps).toEqual(["1", "2"]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("two event handlers on same event", async () => {
|
|
||||||
const block = createBlock('<div block-handler-0="click" block-handler-1="click"></div>');
|
|
||||||
let n = 0;
|
|
||||||
let m = 0;
|
|
||||||
const tree = block([() => m++, () => n++]);
|
|
||||||
|
|
||||||
mount(tree, fixture);
|
|
||||||
expect(fixture.innerHTML).toBe("<div></div>");
|
|
||||||
|
|
||||||
expect(m).toBe(0);
|
|
||||||
expect(n).toBe(0);
|
|
||||||
(fixture.firstChild as HTMLDivElement).click();
|
|
||||||
expect(m).toBe(1);
|
|
||||||
expect(n).toBe(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("two synthetic event handlers on same event", async () => {
|
|
||||||
const block = createBlock(
|
|
||||||
'<div block-handler-0="click.synthetic" block-handler-1="click.synthetic"></div>'
|
|
||||||
);
|
|
||||||
let n = 0;
|
|
||||||
let m = 0;
|
|
||||||
const tree = block([() => m++, () => n++]);
|
|
||||||
|
|
||||||
mount(tree, fixture);
|
|
||||||
expect(fixture.innerHTML).toBe("<div></div>");
|
|
||||||
|
|
||||||
expect(m).toBe(0);
|
|
||||||
expect(n).toBe(0);
|
|
||||||
(fixture.firstChild as HTMLDivElement).click();
|
|
||||||
expect(m).toBe(1);
|
|
||||||
expect(n).toBe(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("synthetic and native handlers can cohabitate", async () => {
|
|
||||||
const block = createBlock(
|
|
||||||
'<div block-handler-0="click.synthetic"><div block-handler-1="click"/></div>'
|
|
||||||
);
|
|
||||||
let steps: string[] = [];
|
|
||||||
let handler1 = () => steps.push("1");
|
|
||||||
let handler2 = () => steps.push("2");
|
|
||||||
const tree = block([handler1, handler2]);
|
|
||||||
|
|
||||||
mount(tree, fixture);
|
|
||||||
expect(fixture.innerHTML).toBe("<div><div></div></div>");
|
|
||||||
|
|
||||||
(fixture.firstChild!.firstChild as HTMLDivElement).click();
|
|
||||||
expect(steps).toEqual(["2", "1"]);
|
|
||||||
(fixture.firstChild as HTMLDivElement).click();
|
|
||||||
expect(steps).toEqual(["2", "1", "1"]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("synthetic and native handlers can cohabitate (2)", async () => {
|
|
||||||
const block = createBlock(
|
|
||||||
'<div block-handler-0="click"><div block-handler-1="click.synthetic"/></div>'
|
|
||||||
);
|
|
||||||
let steps: string[] = [];
|
|
||||||
let handler1 = () => steps.push("1");
|
|
||||||
let handler2 = () => steps.push("2");
|
|
||||||
const tree = block([handler1, handler2]);
|
|
||||||
|
|
||||||
mount(tree, fixture);
|
|
||||||
expect(fixture.innerHTML).toBe("<div><div></div></div>");
|
|
||||||
|
|
||||||
(fixture.firstChild!.firstChild as HTMLDivElement).click();
|
|
||||||
expect(steps).toEqual(["1", "2"]);
|
|
||||||
(fixture.firstChild as HTMLDivElement).click();
|
|
||||||
expect(steps).toEqual(["1", "2", "1"]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("synthetic and native handlers can cohabitate (3)", async () => {
|
|
||||||
const parent = createBlock(`<div block-handler-0="click"><block-child-0/><block-child-1/></div>`);
|
|
||||||
const block = createBlock('<div block-handler-0="click"/>');
|
|
||||||
const blockSynth = createBlock('<div block-handler-0="click.synthetic"/>');
|
|
||||||
let steps: string[] = [];
|
|
||||||
const handler0 = () => steps.push("0");
|
|
||||||
let handler1 = () => steps.push("1");
|
|
||||||
let handler2 = () => steps.push("2");
|
|
||||||
const tree = parent([handler0], [block([handler1]), blockSynth([handler2])]);
|
|
||||||
|
|
||||||
mount(tree, fixture);
|
|
||||||
expect(fixture.innerHTML).toBe("<div><div></div><div></div></div>");
|
|
||||||
|
|
||||||
const children = fixture.children[0].children;
|
|
||||||
|
|
||||||
(children[0] as HTMLElement).click();
|
|
||||||
expect(steps).toEqual(["1", "0"]);
|
|
||||||
(children[1] as HTMLElement).click();
|
|
||||||
expect(steps).toEqual(["1", "0", "0", "2"]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("synthetic and native handlers can cohabitate (4)", async () => {
|
|
||||||
const parent = createBlock(`<div block-handler-0="click"><block-child-0/><block-child-1/></div>`);
|
|
||||||
const block = createBlock('<div block-handler-0="click"/>');
|
|
||||||
const blockSynth = createBlock('<div block-handler-0="click.synthetic"/>');
|
|
||||||
let steps: string[] = [];
|
|
||||||
const handler0 = (ev: Event) => {
|
|
||||||
steps.push("0");
|
|
||||||
ev.stopPropagation();
|
|
||||||
};
|
|
||||||
let handler1 = () => steps.push("1");
|
|
||||||
let handler2 = () => steps.push("2");
|
|
||||||
const tree = parent([handler0], [block([handler1]), blockSynth([handler2])]);
|
|
||||||
|
|
||||||
mount(tree, fixture);
|
|
||||||
expect(fixture.innerHTML).toBe("<div><div></div><div></div></div>");
|
|
||||||
|
|
||||||
const children = fixture.children[0].children;
|
|
||||||
|
|
||||||
(children[0] as HTMLElement).click();
|
|
||||||
expect(steps).toEqual(["1", "0"]);
|
|
||||||
(children[1] as HTMLElement).click();
|
|
||||||
expect(steps).toEqual(["1", "0", "0"]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("synthetic and native handlers can cohabitate (5)", async () => {
|
|
||||||
const block = createBlock('<div block-handler-0="click.synthetic" block-handler-1="click"/>');
|
|
||||||
let steps: string[] = [];
|
|
||||||
let handler1 = () => steps.push("1");
|
|
||||||
let handler2 = () => steps.push("2");
|
|
||||||
const tree = block([handler1, handler2]);
|
|
||||||
|
|
||||||
mount(tree, fixture);
|
|
||||||
expect(fixture.innerHTML).toBe("<div></div>");
|
|
||||||
|
|
||||||
(fixture.firstChild as HTMLDivElement).click();
|
|
||||||
expect(steps).toEqual(["2", "1"]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("synthetic and native handlers can cohabitate (6)", async () => {
|
|
||||||
const block = createBlock(`<div
|
|
||||||
block-handler-0="click.synthetic"
|
|
||||||
block-handler-1="click"
|
|
||||||
block-handler-2="click.synthetic"
|
|
||||||
block-handler-3="click"
|
|
||||||
/>`);
|
|
||||||
let steps: string[] = [];
|
|
||||||
const handler1 = () => steps.push("1");
|
|
||||||
const handler2 = () => steps.push("2");
|
|
||||||
const handler3 = () => steps.push("3");
|
|
||||||
const handler4 = () => steps.push("4");
|
|
||||||
const tree = block([handler1, handler2, handler3, handler4]);
|
|
||||||
mount(tree, fixture);
|
|
||||||
expect(fixture.innerHTML).toBe("<div></div>");
|
|
||||||
|
|
||||||
(fixture.firstChild as HTMLDivElement).click();
|
|
||||||
expect(steps).toEqual(["2", "4", "1", "3"]);
|
|
||||||
});
|
|
||||||
|
|||||||
@@ -1,72 +0,0 @@
|
|||||||
import { createBlock, mount } from "../../src/blockdom";
|
|
||||||
import { makeTestFixture } from "./helpers";
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Setup and helpers
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
const XHTML_URI = "http://www.w3.org/1999/xhtml";
|
|
||||||
const SVG_URI = "http://www.w3.org/2000/svg";
|
|
||||||
let fixture: HTMLElement;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
fixture = makeTestFixture();
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
fixture.remove();
|
|
||||||
});
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Tests
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
describe("namespace", () => {
|
|
||||||
test("default namespace is xhtml", () => {
|
|
||||||
const block = createBlock(`<tag/>`);
|
|
||||||
const tree = block();
|
|
||||||
mount(tree, fixture);
|
|
||||||
expect(fixture.innerHTML).toBe("<tag></tag>");
|
|
||||||
expect(fixture.firstElementChild!.namespaceURI).toBe(XHTML_URI);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("namespace can be changed with block-ns", () => {
|
|
||||||
const block = createBlock(`<tag block-ns="${SVG_URI}"/>`);
|
|
||||||
const tree = block();
|
|
||||||
mount(tree, fixture);
|
|
||||||
expect(fixture.innerHTML).toBe("<tag></tag>");
|
|
||||||
expect(fixture.firstElementChild!.namespaceURI).toBe(SVG_URI);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("namespace is kept for children", () => {
|
|
||||||
const block = createBlock(
|
|
||||||
`<parent block-ns="${SVG_URI}"><child><subchild/></child><child/></parent>`
|
|
||||||
);
|
|
||||||
const tree = block();
|
|
||||||
mount(tree, fixture);
|
|
||||||
expect(fixture.innerHTML).toBe(
|
|
||||||
"<parent><child><subchild></subchild></child><child></child></parent>"
|
|
||||||
);
|
|
||||||
const parent = fixture.firstElementChild!;
|
|
||||||
const child1 = parent.firstElementChild!;
|
|
||||||
const subchild = child1.firstElementChild!;
|
|
||||||
const child2 = child1.nextElementSibling!;
|
|
||||||
expect(parent.namespaceURI).toBe(SVG_URI);
|
|
||||||
expect(child1.namespaceURI).toBe(SVG_URI);
|
|
||||||
expect(child2.namespaceURI).toBe(SVG_URI);
|
|
||||||
expect(subchild.namespaceURI).toBe(SVG_URI);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("various namespaces in same block", () => {
|
|
||||||
const block = createBlock(`<none><one block-ns="one"/><two block-ns="two"/></none>`);
|
|
||||||
const tree = block();
|
|
||||||
mount(tree, fixture);
|
|
||||||
expect(fixture.innerHTML).toBe("<none><one></one><two></two></none>");
|
|
||||||
const none = fixture.firstElementChild!;
|
|
||||||
const one = none.firstElementChild!;
|
|
||||||
const two = one.nextElementSibling!;
|
|
||||||
expect(none.namespaceURI).toBe(XHTML_URI);
|
|
||||||
expect(one.namespaceURI).toBe("one");
|
|
||||||
expect(two.namespaceURI).toBe("two");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -54,61 +54,4 @@ describe("togglers", () => {
|
|||||||
expect(fixture.innerHTML).toBe("<p>hey</p>");
|
expect(fixture.innerHTML).toBe("<p>hey</p>");
|
||||||
expect(fixture.firstChild).not.toBe(textnode);
|
expect(fixture.firstChild).not.toBe(textnode);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("beforeRemove is called", () => {
|
|
||||||
const block = createBlock("<p>hey</p>");
|
|
||||||
|
|
||||||
function blockOverriden() {
|
|
||||||
const vn = block();
|
|
||||||
vn.beforeRemove = () => {
|
|
||||||
steps.push("beforeRemove");
|
|
||||||
};
|
|
||||||
return vn;
|
|
||||||
}
|
|
||||||
|
|
||||||
const steps: string[] = [];
|
|
||||||
const tree = toggler("key1", blockOverriden());
|
|
||||||
mount(tree, fixture);
|
|
||||||
expect(fixture.innerHTML).toBe("<p>hey</p>");
|
|
||||||
patch(tree, toggler("key2", text("foo")));
|
|
||||||
expect(fixture.innerHTML).toBe("foo");
|
|
||||||
|
|
||||||
patch(tree, toggler("key3", blockOverriden()), true);
|
|
||||||
expect(fixture.innerHTML).toBe("<p>hey</p>");
|
|
||||||
|
|
||||||
patch(tree, toggler("key2", text("foo")), true);
|
|
||||||
expect(fixture.innerHTML).toBe("foo");
|
|
||||||
|
|
||||||
expect(steps).toEqual(["beforeRemove"]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("beforeRemove is called when within a block", () => {
|
|
||||||
const block = createBlock("<p><block-child-0/></p>");
|
|
||||||
const conditionalBlock = createBlock("<p>hey</p>");
|
|
||||||
|
|
||||||
const steps: string[] = [];
|
|
||||||
|
|
||||||
function blockOverriden() {
|
|
||||||
const vn = conditionalBlock();
|
|
||||||
vn.beforeRemove = function () {
|
|
||||||
steps.push("beforeRemove");
|
|
||||||
};
|
|
||||||
return vn;
|
|
||||||
}
|
|
||||||
const mainBlock = block([], [toggler("key1", blockOverriden())]);
|
|
||||||
|
|
||||||
mount(mainBlock, fixture);
|
|
||||||
expect(fixture.innerHTML).toBe("<p><p>hey</p></p>");
|
|
||||||
|
|
||||||
patch(mainBlock, block([], []));
|
|
||||||
expect(fixture.innerHTML).toBe("<p></p>");
|
|
||||||
|
|
||||||
patch(mainBlock, block([], [toggler("key1", blockOverriden())]), true);
|
|
||||||
expect(fixture.innerHTML).toBe("<p><p>hey</p></p>");
|
|
||||||
|
|
||||||
patch(mainBlock, block([], []), true);
|
|
||||||
expect(fixture.innerHTML).toBe("<p></p>");
|
|
||||||
|
|
||||||
expect(steps).toEqual(["beforeRemove"]);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
||||||
|
|
||||||
exports[`error handling cannot add twice the same template 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div/>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return block1();
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
@@ -1,555 +0,0 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
||||||
|
|
||||||
exports[`t-on can bind event handler 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<button block-handler-0=\\"click\\">Click</button>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = [ctx['add'], ctx];
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-on can bind handlers with arguments 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<button block-handler-0=\\"click\\">Click</button>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const v1 = ctx['add'];
|
|
||||||
let d1 = [()=>v1(5), ctx];
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-on can bind handlers with empty object 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<button block-handler-0=\\"click\\">Click</button>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const v1 = ctx['doSomething'];
|
|
||||||
let d1 = [()=>v1({}), ctx];
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-on can bind handlers with empty object (with non empty inner string) 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<button block-handler-0=\\"click\\">Click</button>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const v1 = ctx['doSomething'];
|
|
||||||
let d1 = [()=>v1({}), ctx];
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-on can bind handlers with empty object (with non empty inner string) 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<ul><block-child-0/></ul>\`);
|
|
||||||
let block3 = createBlock(\`<li><a block-handler-0=\\"click\\">link</a></li>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
ctx = Object.create(ctx);
|
|
||||||
const [k_block2, v_block2, l_block2, c_block2] = prepareList(['someval']);
|
|
||||||
for (let i1 = 0; i1 < l_block2; i1++) {
|
|
||||||
ctx[\`action\`] = v_block2[i1];
|
|
||||||
ctx[\`action_index\`] = i1;
|
|
||||||
let key1 = ctx['action_index'];
|
|
||||||
const v1 = ctx['activate'];
|
|
||||||
const v2 = ctx['action'];
|
|
||||||
let d1 = [()=>v1(v2), ctx];
|
|
||||||
c_block2[i1] = withKey(block3([d1]), key1);
|
|
||||||
}
|
|
||||||
let b2 = list(c_block2);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-on can bind handlers with object arguments 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<button block-handler-0=\\"click\\">Click</button>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const v1 = ctx['add'];
|
|
||||||
let d1 = [()=>v1({val:5}), ctx];
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-on can bind two event handlers 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<button block-handler-0=\\"click\\" block-handler-1=\\"dblclick\\">Click</button>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = [ctx['handleClick'], ctx];
|
|
||||||
let d2 = [ctx['handleDblClick'], ctx];
|
|
||||||
return block1([d1, d2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-on handler is bound to proper owner 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<button block-handler-0=\\"click\\">Click</button>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = [ctx['add'], ctx];
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-on handler is bound to proper owner, part 2 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block2 = createBlock(\`<button block-handler-0=\\"click\\">Click</button>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
ctx = Object.create(ctx);
|
|
||||||
const [k_block1, v_block1, l_block1, c_block1] = prepareList([1]);
|
|
||||||
for (let i1 = 0; i1 < l_block1; i1++) {
|
|
||||||
ctx[\`value\`] = v_block1[i1];
|
|
||||||
let key1 = ctx['value'];
|
|
||||||
let d1 = [ctx['add'], ctx];
|
|
||||||
c_block1[i1] = withKey(block2([d1]), key1);
|
|
||||||
}
|
|
||||||
return list(c_block1);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-on handler is bound to proper owner, part 3 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<button block-handler-0=\\"click\\">Click</button>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = [ctx['add'], ctx];
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-on handler is bound to proper owner, part 3 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
const callTemplate_2 = getTemplate(\`sub\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return callTemplate_2.call(this, ctx, node, key + \`__1\`);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-on handler is bound to proper owner, part 4 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<button block-handler-0=\\"click\\">Click</button>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = [ctx['add'], ctx];
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-on handler is bound to proper owner, part 4 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
const callTemplate_2 = getTemplate(\`sub\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
ctx = Object.create(ctx);
|
|
||||||
const [k_block1, v_block1, l_block1, c_block1] = prepareList([1]);
|
|
||||||
for (let i1 = 0; i1 < l_block1; i1++) {
|
|
||||||
ctx[\`value\`] = v_block1[i1];
|
|
||||||
ctx[\`value_first\`] = i1 === 0;
|
|
||||||
ctx[\`value_last\`] = i1 === v_block1.length - 1;
|
|
||||||
ctx[\`value_index\`] = i1;
|
|
||||||
ctx[\`value_value\`] = k_block1[i1];
|
|
||||||
let key1 = ctx['value'];
|
|
||||||
c_block1[i1] = withKey(callTemplate_2.call(this, ctx, node, key + \`__1__\${key1}\`), key1);
|
|
||||||
}
|
|
||||||
return list(c_block1);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-on receive event in first argument 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<button block-handler-0=\\"click\\">Click</button>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = [ctx['add'], ctx];
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-on t-on modifiers (native listener) basic support for native listener 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div class=\\"myClass\\" block-handler-0=\\"click\\"><button block-handler-1=\\"click\\">Button</button></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = [ctx['divClicked'], ctx];
|
|
||||||
let d2 = [ctx['btnClicked'], ctx];
|
|
||||||
return block1([d1, d2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-on t-on modifiers (native listener) t-on combined with t-esc 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><button block-handler-0=\\"click\\"><block-text-1/></button></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = [ctx['onClick'], ctx];
|
|
||||||
let d2 = ctx['text'];
|
|
||||||
return block1([d1, d2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-on t-on modifiers (native listener) t-on combined with t-out 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><button block-handler-0=\\"click\\"><block-child-0/></button></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = [ctx['onClick'], ctx];
|
|
||||||
let b2 = safeOutput(ctx['html']);
|
|
||||||
return block1([d1], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-on t-on modifiers (native listener) t-on with .capture modifier 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div block-handler-0=\\"click.capture\\"><button block-handler-1=\\"click\\">Button</button></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = [\\"capture\\", ctx['onCapture'], ctx];
|
|
||||||
let d2 = [ctx['doSomething'], ctx];
|
|
||||||
return block1([d1, d2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-on t-on modifiers (native listener) t-on with empty handler (only modifiers) 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><button block-handler-0=\\"click.prevent\\">Button</button></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = [\\"prevent\\", , ctx];
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-on t-on modifiers (native listener) t-on with prevent and self modifiers (order matters) 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><button block-handler-0=\\"click.prevent.self\\"><span>Button</span></button></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = [\\"prevent\\",\\"self\\", ctx['onClick'], ctx];
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-on t-on modifiers (native listener) t-on with prevent and/or stop modifiers 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><button block-handler-0=\\"click.prevent\\">Button 1</button><button block-handler-1=\\"click.stop\\">Button 2</button><button block-handler-2=\\"click.prevent.stop\\">Button 3</button></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = [\\"prevent\\", ctx['onClickPrevented'], ctx];
|
|
||||||
let d2 = [\\"stop\\", ctx['onClickStopped'], ctx];
|
|
||||||
let d3 = [\\"prevent\\",\\"stop\\", ctx['onClickPreventedAndStopped'], ctx];
|
|
||||||
return block1([d1, d2, d3]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-on t-on modifiers (native listener) t-on with prevent modifier in t-foreach 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
let block3 = createBlock(\`<a href=\\"#\\" block-handler-0=\\"click.prevent\\"> Edit <block-text-1/></a>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
ctx = Object.create(ctx);
|
|
||||||
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['projects']);
|
|
||||||
for (let i1 = 0; i1 < l_block2; i1++) {
|
|
||||||
ctx[\`project\`] = v_block2[i1];
|
|
||||||
let key1 = ctx['project'];
|
|
||||||
const v1 = ctx['onEdit'];
|
|
||||||
const v2 = ctx['project'];
|
|
||||||
let d1 = [\\"prevent\\", ev=>v1(v2.id,ev), ctx];
|
|
||||||
let d2 = ctx['project'].name;
|
|
||||||
c_block2[i1] = withKey(block3([d1, d2]), key1);
|
|
||||||
}
|
|
||||||
let b2 = list(c_block2);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-on t-on modifiers (native listener) t-on with self and prevent modifiers (order matters) 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><button block-handler-0=\\"click.self.prevent\\"><span>Button</span></button></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = [\\"self\\",\\"prevent\\", ctx['onClick'], ctx];
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-on t-on modifiers (native listener) t-on with self modifier 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><button block-handler-0=\\"click\\"><span>Button</span></button><button block-handler-1=\\"click.self\\"><span>Button</span></button></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = [ctx['onClick'], ctx];
|
|
||||||
let d2 = [\\"self\\", ctx['onClickSelf'], ctx];
|
|
||||||
return block1([d1, d2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-on t-on modifiers (synthetic listener) basic support for synthetic 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div block-handler-0=\\"click.synthetic\\"><button block-handler-1=\\"click.synthetic\\">Button</button></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = [\\"synthetic\\", ctx['divClicked'], ctx];
|
|
||||||
let d2 = [\\"synthetic\\", ctx['btnClicked'], ctx];
|
|
||||||
return block1([d1, d2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-on t-on with inline statement (function call) 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<button block-handler-0=\\"click\\">Click</button>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const v1 = ctx['state'];
|
|
||||||
let d1 = [()=>v1.incrementCounter(2), ctx];
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-on t-on with inline statement 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<button block-handler-0=\\"click\\">Click</button>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const v1 = ctx['state'];
|
|
||||||
let d1 = [()=>v1.counter++, ctx];
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-on t-on with inline statement, part 2 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<button block-handler-0=\\"click\\">Toggle</button>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const v1 = ctx['state'];
|
|
||||||
let d1 = [()=>v1.flag=!v1.flag, ctx];
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-on t-on with inline statement, part 3 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<button block-handler-0=\\"click\\">Toggle</button>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const v1 = ctx['state'];
|
|
||||||
const v2 = ctx['someFunction'];
|
|
||||||
let d1 = [()=>v1.n=v2(3), ctx];
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-on t-on with t-call 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<p block-handler-0=\\"click\\">lucas</p>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = [ctx['update'], ctx];
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-on t-on with t-call 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
const callTemplate_2 = getTemplate(\`sub\`);
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2 = callTemplate_2.call(this, ctx, node, key + \`__1\`);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-on t-on, with arguments and t-call 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<p block-handler-0=\\"click\\">lucas</p>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const v1 = ctx['value'];
|
|
||||||
let d1 = [()=>this.update(v1), ctx];
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-on t-on, with arguments and t-call 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
const callTemplate_2 = getTemplate(\`sub\`);
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2 = callTemplate_2.call(this, ctx, node, key + \`__1\`);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
||||||
|
|
||||||
exports[`qweb parser simple t-foreach expression, t-key mandatory 1`] = `"\\"Directive t-foreach should always be used with a t-key!\\" (expression: t-foreach=\\"list\\" t-as=\\"item\\")"`;
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
||||||
|
|
||||||
exports[`memory t-foreach does not leak stuff in global scope 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<p><block-child-0/></p>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
ctx = Object.create(ctx);
|
|
||||||
const [k_block2, v_block2, l_block2, c_block2] = prepareList([3,2,1]);
|
|
||||||
for (let i1 = 0; i1 < l_block2; i1++) {
|
|
||||||
ctx[\`item\`] = v_block2[i1];
|
|
||||||
ctx[\`item_index\`] = i1;
|
|
||||||
let key1 = ctx['item_index'];
|
|
||||||
c_block2[i1] = withKey(text(ctx['item']), key1);
|
|
||||||
}
|
|
||||||
let b2 = list(c_block2);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
||||||
|
|
||||||
exports[`properly support svg add proper namespace to g tags 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<g block-ns=\\"http://www.w3.org/2000/svg\\"><circle cx=\\"50\\" cy=\\"50\\" r=\\"4\\" stroke=\\"green\\" stroke-width=\\"1\\" fill=\\"yellow\\"/> </g>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return block1();
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`properly support svg add proper namespace to svg 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<svg block-ns=\\"http://www.w3.org/2000/svg\\" width=\\"100px\\" height=\\"90px\\"><circle cx=\\"50\\" cy=\\"50\\" r=\\"4\\" stroke=\\"green\\" stroke-width=\\"1\\" fill=\\"yellow\\"/> </svg>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return block1();
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`properly support svg namespace to g tags not added if already in svg namespace 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<svg block-ns=\\"http://www.w3.org/2000/svg\\"><g/></svg>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return block1();
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`properly support svg namespace to svg tags added even if already in svg namespace 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<svg block-ns=\\"http://www.w3.org/2000/svg\\"><svg block-ns=\\"http://www.w3.org/2000/svg\\"/></svg>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return block1();
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
||||||
|
|
||||||
exports[`debugging t-debug 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
let block2 = createBlock(\`<span>hey</span>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
debugger;
|
|
||||||
let b2;
|
|
||||||
if (true) {
|
|
||||||
debugger;
|
|
||||||
b2 = block2();
|
|
||||||
}
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`debugging t-debug on sub template 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<p>coucou</p>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
debugger;
|
|
||||||
return block1();
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`debugging t-debug on sub template 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
const callTemplate_2 = getTemplate(\`sub\`);
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2 = callTemplate_2.call(this, ctx, node, key + \`__1\`);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`debugging t-log 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div/>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
ctx = Object.create(ctx);
|
|
||||||
ctx[isBoundary] = 1
|
|
||||||
setContextValue(ctx, \\"foo\\", 42);
|
|
||||||
console.log(ctx['foo']+3);
|
|
||||||
return block1();
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
@@ -1,73 +0,0 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
||||||
|
|
||||||
exports[`t-key can use t-key directive on a node 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const tKey_1 = ctx['beer'].id;
|
|
||||||
let d1 = ctx['beer'].name;
|
|
||||||
return toggler(tKey_1, block1([d1]));
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-key can use t-key directive on a node 2 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const tKey_1 = ctx['beer'].id;
|
|
||||||
let d1 = ctx['beer'].name;
|
|
||||||
return toggler(tKey_1, block1([d1]));
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-key can use t-key directive on a node as a function 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const tKey_1 = ctx['getKey'](ctx['beer']);
|
|
||||||
let d1 = ctx['beer'].name;
|
|
||||||
return toggler(tKey_1, block1([d1]));
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-key t-key directive in a list 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<ul><block-child-0/></ul>\`);
|
|
||||||
let block3 = createBlock(\`<li><block-text-0/></li>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
ctx = Object.create(ctx);
|
|
||||||
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['beers']);
|
|
||||||
for (let i1 = 0; i1 < l_block2; i1++) {
|
|
||||||
ctx[\`beer\`] = v_block2[i1];
|
|
||||||
let key1 = ctx['beer'].id;
|
|
||||||
let d1 = ctx['beer'].name;
|
|
||||||
c_block2[i1] = withKey(block3([d1]), key1);
|
|
||||||
}
|
|
||||||
let b2 = list(c_block2);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
@@ -1,432 +0,0 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
||||||
|
|
||||||
exports[`t-out literal 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2 = safeOutput('ok');
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-out literal, no outside html element 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return safeOutput('ok');
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-out multiple calls to t-out 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><div>Greeter</div><block-child-1/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2 = ctx[zero];
|
|
||||||
let b3 = ctx[zero];
|
|
||||||
return block1([], [b2, b3]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-out multiple calls to t-out 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
const callTemplate_2 = getTemplate(\`sub\`);
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
let block2 = createBlock(\`<span>coucou</span>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
ctx = Object.create(ctx);
|
|
||||||
ctx[isBoundary] = 1;
|
|
||||||
let b2 = block2();
|
|
||||||
ctx[zero] = b2;
|
|
||||||
let b3 = callTemplate_2.call(this, ctx, node, key + \`__1\`);
|
|
||||||
return block1([], [b3]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-out not escaping 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2 = safeOutput(ctx['var']);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-out t-out 0 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2 = ctx[zero];
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-out t-out 0 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
const callTemplate_2 = getTemplate(\`_basic-callee\`);
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
let block2 = createBlock(\`<div>zero</div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
ctx = Object.create(ctx);
|
|
||||||
ctx[isBoundary] = 1;
|
|
||||||
let b2 = block2();
|
|
||||||
ctx[zero] = b2;
|
|
||||||
let b3 = callTemplate_2.call(this, ctx, node, key + \`__1\`);
|
|
||||||
return block1([], [b3]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-out t-out and another sibling node 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><span>hello</span><block-child-0/></span>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2 = safeOutput(ctx['var']);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-out t-out bdom 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><span><block-child-0/></span></div>\`);
|
|
||||||
let block2 = createBlock(\`<ol>set</ol>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
ctx = Object.create(ctx);
|
|
||||||
ctx[isBoundary] = 1
|
|
||||||
let b2 = block2();
|
|
||||||
ctx[\`var\`] = b2;
|
|
||||||
let b3 = safeOutput(ctx['var']);
|
|
||||||
return block1([], [b3]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-out t-out block 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2 = safeOutput(ctx['bdom']);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-out t-out escaped 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2 = safeOutput(ctx['var']);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-out t-out markedup 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2 = safeOutput(ctx['var']);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-out t-out on a node with a body, as a default 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b3 = text(\`nope\`);
|
|
||||||
let b2 = withDefault(safeOutput(ctx['var']), b3);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-out t-out on a node with a dom node in body, as a default 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
|
||||||
let block3 = createBlock(\`<div>nope</div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b3 = block3();
|
|
||||||
let b2 = withDefault(safeOutput(ctx['var']), b3);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-out t-out switch escaped 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2 = safeOutput(ctx['var']);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-out t-out switch escaped on markup 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2 = safeOutput(ctx['var']);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-out t-out switch markup 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2 = safeOutput(ctx['var']);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-out t-out switch markup on bdom 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
|
|
||||||
let block2 = createBlock(\`<ol>set</ol>\`);
|
|
||||||
let block3 = createBlock(\`<span><block-child-0/></span>\`);
|
|
||||||
let block5 = createBlock(\`<span><block-child-0/></span>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
ctx = Object.create(ctx);
|
|
||||||
ctx[isBoundary] = 1
|
|
||||||
let b3,b5;
|
|
||||||
let b2 = block2();
|
|
||||||
ctx[\`bdom\`] = b2;
|
|
||||||
if (ctx['hasBdom']) {
|
|
||||||
let b4 = safeOutput(ctx['bdom']);
|
|
||||||
b3 = block3([], [b4]);
|
|
||||||
} else {
|
|
||||||
let b6 = safeOutput(ctx['var']);
|
|
||||||
b5 = block5([], [b6]);
|
|
||||||
}
|
|
||||||
return block1([], [b3, b5]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-out t-out switch markup on escaped 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2 = safeOutput(ctx['var']);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-out t-out with a <t/> in body 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return safeOutput(ctx['var']);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-out t-out with arbitrary object 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2 = safeOutput(ctx['var']);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-out t-out with arbitrary object 2 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2 = safeOutput(ctx['var']);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-out t-out with comment 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2 = safeOutput(ctx['var']);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-out t-out with just a t-set t-value in body 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return safeOutput(ctx['var']);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-out variable 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2 = safeOutput(ctx['var']);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-raw is deprecated should warn 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2 = safeOutput(ctx['var']);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-raw is deprecated t-out is actually called in t-raw's place 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2 = safeOutput(ctx['var']);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
@@ -1,598 +0,0 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
||||||
|
|
||||||
exports[`t-set evaluate value expression 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
ctx = Object.create(ctx);
|
|
||||||
ctx[isBoundary] = 1
|
|
||||||
setContextValue(ctx, \\"value\\", 1+2);
|
|
||||||
let d1 = ctx['value'];
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-set evaluate value expression, part 2 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
ctx = Object.create(ctx);
|
|
||||||
ctx[isBoundary] = 1
|
|
||||||
setContextValue(ctx, \\"value\\", ctx['somevariable']+2);
|
|
||||||
let d1 = ctx['value'];
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-set set from attribute literal (no outside div) 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
ctx = Object.create(ctx);
|
|
||||||
ctx[isBoundary] = 1
|
|
||||||
setContextValue(ctx, \\"value\\", 'ok');
|
|
||||||
return text(ctx['value']);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-set set from attribute literal 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
ctx = Object.create(ctx);
|
|
||||||
ctx[isBoundary] = 1
|
|
||||||
setContextValue(ctx, \\"value\\", 'ok');
|
|
||||||
let d1 = ctx['value'];
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-set set from attribute lookup 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
ctx = Object.create(ctx);
|
|
||||||
ctx[isBoundary] = 1
|
|
||||||
setContextValue(ctx, \\"stuff\\", ctx['value']);
|
|
||||||
let d1 = ctx['stuff'];
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-set set from body literal 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
ctx = Object.create(ctx);
|
|
||||||
ctx[isBoundary] = 1
|
|
||||||
setContextValue(ctx, \\"value\\", \`ok\`);
|
|
||||||
return text(ctx['value']);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-set set from body lookup 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
ctx = Object.create(ctx);
|
|
||||||
ctx[isBoundary] = 1
|
|
||||||
let b2 = text(ctx['value']);
|
|
||||||
ctx[\`stuff\`] = b2;
|
|
||||||
let d1 = ctx['stuff'];
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-set set from empty body 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
ctx = Object.create(ctx);
|
|
||||||
ctx[isBoundary] = 1
|
|
||||||
setContextValue(ctx, \\"stuff\\", null);
|
|
||||||
let d1 = ctx['stuff'];
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-set t-set and t-if 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
ctx = Object.create(ctx);
|
|
||||||
ctx[isBoundary] = 1
|
|
||||||
let b2;
|
|
||||||
setContextValue(ctx, \\"v\\", ctx['value']);
|
|
||||||
if (ctx['v']==='ok') {
|
|
||||||
b2 = text(\`grimbergen\`);
|
|
||||||
}
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-set t-set body is evaluated immediately 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
let block2 = createBlock(\`<span><block-text-0/></span>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
ctx = Object.create(ctx);
|
|
||||||
ctx[isBoundary] = 1
|
|
||||||
setContextValue(ctx, \\"v1\\", 'before');
|
|
||||||
let d1 = ctx['v1'];
|
|
||||||
let b2 = block2([d1]);
|
|
||||||
ctx[\`v2\`] = b2;
|
|
||||||
setContextValue(ctx, \\"v1\\", 'after');
|
|
||||||
let b3 = safeOutput(ctx['v2']);
|
|
||||||
return block1([], [b3]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-set t-set can't alter from within callee 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/><block-text-1/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
ctx = Object.create(ctx);
|
|
||||||
ctx[isBoundary] = 1
|
|
||||||
let d1 = ctx['iter'];
|
|
||||||
setContextValue(ctx, \\"iter\\", 'called');
|
|
||||||
let d2 = ctx['iter'];
|
|
||||||
return block1([d1, d2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-set t-set can't alter from within callee 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
const callTemplate_2 = getTemplate(\`sub\`);
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><p><block-text-0/></p><block-child-0/><p><block-text-1/></p></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
ctx = Object.create(ctx);
|
|
||||||
ctx[isBoundary] = 1
|
|
||||||
setContextValue(ctx, \\"iter\\", 'source');
|
|
||||||
let d1 = ctx['iter'];
|
|
||||||
let b2 = callTemplate_2.call(this, ctx, node, key + \`__1\`);
|
|
||||||
let d2 = ctx['iter'];
|
|
||||||
return block1([d1, d2], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-set t-set can't alter in t-call body 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/><block-text-1/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
ctx = Object.create(ctx);
|
|
||||||
ctx[isBoundary] = 1
|
|
||||||
let d1 = ctx['iter'];
|
|
||||||
setContextValue(ctx, \\"iter\\", 'called');
|
|
||||||
let d2 = ctx['iter'];
|
|
||||||
return block1([d1, d2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-set t-set can't alter in t-call body 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
const callTemplate_2 = getTemplate(\`sub\`);
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><p><block-text-0/></p><block-child-0/><p><block-text-1/></p></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
ctx = Object.create(ctx);
|
|
||||||
ctx[isBoundary] = 1
|
|
||||||
setContextValue(ctx, \\"iter\\", 'source');
|
|
||||||
let d1 = ctx['iter'];
|
|
||||||
ctx = Object.create(ctx);
|
|
||||||
ctx[isBoundary] = 1;
|
|
||||||
setContextValue(ctx, \\"iter\\", 'inCall');
|
|
||||||
let b2 = callTemplate_2.call(this, ctx, node, key + \`__1\`);
|
|
||||||
ctx = ctx.__proto__;
|
|
||||||
let d2 = ctx['iter'];
|
|
||||||
return block1([d1, d2], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-set t-set does not modify render context existing key values 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
ctx = Object.create(ctx);
|
|
||||||
ctx[isBoundary] = 1
|
|
||||||
setContextValue(ctx, \\"value\\", 35);
|
|
||||||
let d1 = ctx['value'];
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-set t-set evaluates an expression only once 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/><block-text-1/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
ctx = Object.create(ctx);
|
|
||||||
ctx[isBoundary] = 1
|
|
||||||
setContextValue(ctx, \\"v\\", ctx['value']+' artois');
|
|
||||||
let d1 = ctx['v'];
|
|
||||||
let d2 = ctx['v'];
|
|
||||||
return block1([d1, d2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-set t-set outside modified in t-foreach 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = 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 [k_block2, v_block2, l_block2, c_block2] = prepareList(['a','b']);
|
|
||||||
for (let i1 = 0; i1 < l_block2; i1++) {
|
|
||||||
ctx[\`val\`] = v_block2[i1];
|
|
||||||
let key1 = ctx['val'];
|
|
||||||
let d1 = ctx['iter'];
|
|
||||||
c_block2[i1] = withKey(block3([d1]), key1);
|
|
||||||
setContextValue(ctx, \\"iter\\", ctx['iter']+1);
|
|
||||||
}
|
|
||||||
ctx = ctx.__proto__;
|
|
||||||
let b2 = list(c_block2);
|
|
||||||
let d2 = ctx['iter'];
|
|
||||||
return block1([d2], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-set t-set outside modified in t-foreach increment-after operator 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = 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 [k_block2, v_block2, l_block2, c_block2] = prepareList(['a','b']);
|
|
||||||
for (let i1 = 0; i1 < l_block2; i1++) {
|
|
||||||
ctx[\`val\`] = v_block2[i1];
|
|
||||||
let key1 = ctx['val'];
|
|
||||||
let d1 = ctx['iter'];
|
|
||||||
c_block2[i1] = withKey(block3([d1]), key1);
|
|
||||||
setContextValue(ctx, \\"iter\\", ctx['iter']++);
|
|
||||||
}
|
|
||||||
ctx = ctx.__proto__;
|
|
||||||
let b2 = list(c_block2);
|
|
||||||
let d2 = ctx['iter'];
|
|
||||||
return block1([d2], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-set t-set outside modified in t-foreach increment-before operator 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = 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 [k_block2, v_block2, l_block2, c_block2] = prepareList(['a','b']);
|
|
||||||
for (let i1 = 0; i1 < l_block2; i1++) {
|
|
||||||
ctx[\`val\`] = v_block2[i1];
|
|
||||||
let key1 = ctx['val'];
|
|
||||||
let d1 = ctx['iter'];
|
|
||||||
c_block2[i1] = withKey(block3([d1]), key1);
|
|
||||||
setContextValue(ctx, \\"iter\\", ++ctx['iter']);
|
|
||||||
}
|
|
||||||
ctx = ctx.__proto__;
|
|
||||||
let b2 = list(c_block2);
|
|
||||||
let d2 = ctx['iter'];
|
|
||||||
return block1([d2], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-set t-set should reuse variable if possible 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = 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 [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['list']);
|
|
||||||
for (let i1 = 0; i1 < l_block2; i1++) {
|
|
||||||
ctx[\`elem\`] = v_block2[i1];
|
|
||||||
ctx[\`elem_index\`] = i1;
|
|
||||||
let key1 = ctx['elem_index'];
|
|
||||||
let d1 = ctx['v'];
|
|
||||||
setContextValue(ctx, \\"v\\", ctx['elem']);
|
|
||||||
c_block2[i1] = withKey(block3([d1]), key1);
|
|
||||||
}
|
|
||||||
let b2 = list(c_block2);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-set t-set with content and sub t-esc 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
ctx = Object.create(ctx);
|
|
||||||
ctx[isBoundary] = 1
|
|
||||||
let b3 = text(ctx['beep']);
|
|
||||||
let b4 = text(\` boop\`);
|
|
||||||
let b2 = multi([b3, b4]);
|
|
||||||
ctx[\`setvar\`] = b2;
|
|
||||||
let d1 = ctx['setvar'];
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-set t-set with t-value (falsy) and body 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
let block2 = createBlock(\`<span><block-text-0/></span>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
ctx = Object.create(ctx);
|
|
||||||
ctx[isBoundary] = 1
|
|
||||||
setContextValue(ctx, \\"v3\\", false);
|
|
||||||
setContextValue(ctx, \\"v1\\", 'before');
|
|
||||||
let d1 = ctx['v1'];
|
|
||||||
let b2 = block2([d1]);
|
|
||||||
ctx[\`v2\`] = withDefault(ctx['v3'], b2);
|
|
||||||
setContextValue(ctx, \\"v1\\", 'after');
|
|
||||||
setContextValue(ctx, \\"v3\\", true);
|
|
||||||
let b3 = safeOutput(ctx['v2']);
|
|
||||||
return block1([], [b3]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-set t-set with t-value (truthy) and body 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
let block2 = createBlock(\`<span><block-text-0/></span>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
ctx = Object.create(ctx);
|
|
||||||
ctx[isBoundary] = 1
|
|
||||||
setContextValue(ctx, \\"v3\\", 'Truthy');
|
|
||||||
setContextValue(ctx, \\"v1\\", 'before');
|
|
||||||
let d1 = ctx['v1'];
|
|
||||||
let b2 = block2([d1]);
|
|
||||||
ctx[\`v2\`] = withDefault(ctx['v3'], b2);
|
|
||||||
setContextValue(ctx, \\"v1\\", 'after');
|
|
||||||
setContextValue(ctx, \\"v3\\", false);
|
|
||||||
let b3 = safeOutput(ctx['v2']);
|
|
||||||
return block1([], [b3]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-set t-set, t-if, and mix of expression/body lookup, 1 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><block-child-0/><block-text-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
ctx = Object.create(ctx);
|
|
||||||
ctx[isBoundary] = 1
|
|
||||||
if (ctx['flag']) {
|
|
||||||
setContextValue(ctx, \\"ourvar\\", \`1\`);
|
|
||||||
} else {
|
|
||||||
setContextValue(ctx, \\"ourvar\\", 0);
|
|
||||||
}
|
|
||||||
let d1 = ctx['ourvar'];
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-set t-set, t-if, and mix of expression/body lookup, 2 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><block-child-0/><block-text-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
ctx = Object.create(ctx);
|
|
||||||
ctx[isBoundary] = 1
|
|
||||||
if (ctx['flag']) {
|
|
||||||
setContextValue(ctx, \\"ourvar\\", 1);
|
|
||||||
} else {
|
|
||||||
setContextValue(ctx, \\"ourvar\\", \`0\`);
|
|
||||||
}
|
|
||||||
let d1 = ctx['ourvar'];
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-set t-set, t-if, and mix of expression/body lookup, 3 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
ctx = Object.create(ctx);
|
|
||||||
ctx[isBoundary] = 1
|
|
||||||
let b2;
|
|
||||||
if (ctx['flag']) {
|
|
||||||
setContextValue(ctx, \\"ourvar\\", 1);
|
|
||||||
} else {
|
|
||||||
setContextValue(ctx, \\"ourvar\\", \`0\`);
|
|
||||||
}
|
|
||||||
b2 = text(ctx['ourvar']);
|
|
||||||
return multi([b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-set value priority (with non text body 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
|
||||||
let block2 = createBlock(\`<span>2</span>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
ctx = Object.create(ctx);
|
|
||||||
ctx[isBoundary] = 1
|
|
||||||
let b2 = block2();
|
|
||||||
ctx[\`value\`] = withDefault(1, b2);
|
|
||||||
let d1 = ctx['value'];
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-set value priority 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
ctx = Object.create(ctx);
|
|
||||||
ctx[isBoundary] = 1
|
|
||||||
setContextValue(ctx, \\"value\\", withDefault(1, \`2\`));
|
|
||||||
let d1 = ctx['value'];
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
@@ -1,128 +0,0 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
||||||
|
|
||||||
exports[`qweb t-tag can fallback if falsy tag 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = tag => createBlock(\`<\${tag || 'fallback'}/>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let tag1 = ctx['tag'];
|
|
||||||
return toggler(tag1, block1(tag1)());
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`qweb t-tag can update 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = tag => createBlock(\`<\${tag || 't'}/>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let tag1 = ctx['tag'];
|
|
||||||
return toggler(tag1, block1(tag1)());
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`qweb t-tag simple usecases 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = tag => createBlock(\`<\${tag || 't'}/>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let tag1 = 'div';
|
|
||||||
return toggler(tag1, block1(tag1)());
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`qweb t-tag simple usecases 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = tag => createBlock(\`<\${tag || 't'}>text</\${tag || 't'}>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let tag1 = ctx['tag'];
|
|
||||||
return toggler(tag1, block1(tag1)());
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`qweb t-tag with multiple attributes 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = tag => createBlock(\`<\${tag || 't'} class=\\"blueberry\\" taste=\\"raspberry\\">gooseberry</\${tag || 't'}>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let tag1 = ctx['tag'];
|
|
||||||
return toggler(tag1, block1(tag1)());
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`qweb t-tag with multiple child nodes 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = tag => createBlock(\`<\${tag || 't'}> pear <span>apple</span> strawberry </\${tag || 't'}>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let tag1 = ctx['tag'];
|
|
||||||
return toggler(tag1, block1(tag1)());
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`qweb t-tag with multiple t-tag in same template 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = tag => createBlock(\`<\${tag || 't'}><block-child-0/></\${tag || 't'}>\`);
|
|
||||||
let block2 = tag => createBlock(\`<\${tag || 't'}>baz</\${tag || 't'}>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let tag1 = ctx['outer'];
|
|
||||||
let tag2 = ctx['inner'];
|
|
||||||
let b2 = toggler(tag2, block2(tag2)());
|
|
||||||
return toggler(tag1, block1(tag1)([], [b2]));
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`qweb t-tag with multiple t-tag in same template, part 2 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block2 = tag => createBlock(\`<\${tag || 't'}>bar</\${tag || 't'}>\`);
|
|
||||||
let block3 = tag => createBlock(\`<\${tag || 't'}>baz</\${tag || 't'}>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let tag1 = ctx['brother'];
|
|
||||||
let b2 = toggler(tag1, block2(tag1)());
|
|
||||||
let tag2 = ctx['brother'];
|
|
||||||
let b3 = toggler(tag2, block3(tag2)());
|
|
||||||
return multi([b2, b3]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
@@ -1,91 +0,0 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
||||||
|
|
||||||
exports[`loading templates can initialize qweb with a string 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div>jupiler</div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return block1();
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`loading templates can initialize qweb with an XMLDocument 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div>jupiler</div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return block1();
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`loading templates can load a few templates from a xml string 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block2 = createBlock(\`<li>ok</li>\`);
|
|
||||||
let block3 = createBlock(\`<li>foo</li>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2 = block2();
|
|
||||||
let b3 = block3();
|
|
||||||
return multi([b2, b3]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`loading templates can load a few templates from a xml string 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<ul/>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return block1();
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`loading templates can load a few templates from an XMLDocument 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block2 = createBlock(\`<li>ok</li>\`);
|
|
||||||
let block3 = createBlock(\`<li>foo</li>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2 = block2();
|
|
||||||
let b3 = block3();
|
|
||||||
return multi([b2, b3]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`loading templates can load a few templates from an XMLDocument 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<ul/>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return block1();
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
||||||
|
|
||||||
exports[`translation support can set translatable attributes 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div tomato=\\"word\\" potato=\\"mot\\" title=\\"word\\">text</div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return block1();
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`translation support can translate node content 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div>mot</div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return block1();
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`translation support does not translate node content if disabled 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><span>mot</span><span>word</span></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return block1();
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`translation support some attributes are translated 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><p label=\\"mot\\">mot</p><p title=\\"mot\\">mot</p><p placeholder=\\"mot\\">mot</p><p alt=\\"mot\\">mot</p><p something=\\"word\\">mot</p></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return block1();
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`translation support translation is done on the trimmed text, with extra spaces readded after 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div> mot </div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return block1();
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
import { renderToString, snapshotEverything, TestContext } from "../helpers";
|
|
||||||
|
|
||||||
snapshotEverything();
|
|
||||||
|
|
||||||
describe("error handling", () => {
|
|
||||||
test("invalid xml", () => {
|
|
||||||
expect(() => renderToString("<div>")).toThrow("Invalid XML in template");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("nice warning if no template with given name", () => {
|
|
||||||
const context = new TestContext();
|
|
||||||
expect(() => context.renderToString("invalidname")).toThrow("Missing template");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("cannot add twice the same template", () => {
|
|
||||||
const context = new TestContext();
|
|
||||||
context.addTemplate("test", `<t></t>`);
|
|
||||||
expect(() => context.addTemplate("test", "<div/>", { allowDuplicate: true })).not.toThrow(
|
|
||||||
"already defined"
|
|
||||||
);
|
|
||||||
expect(() => context.addTemplate("test", "<div/>")).toThrow("already defined");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("addTemplates throw if parser error", () => {
|
|
||||||
const context = new TestContext();
|
|
||||||
expect(() => {
|
|
||||||
context.addTemplates("<templates><abc>></templates>");
|
|
||||||
}).toThrow("Invalid XML in template");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("nice error when t-on is evaluated with a missing event", () => {
|
|
||||||
expect(() => renderToString(`<div t-on="somemethod"></div>`)).toThrow(
|
|
||||||
"Missing event name with t-on directive"
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("error when unknown directive", () => {
|
|
||||||
expect(() => renderToString(`<div t-best-beer="rochefort 10">test</div>`)).toThrow(
|
|
||||||
"Unknown QWeb directive: 't-best-beer'"
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,567 +0,0 @@
|
|||||||
import { TemplateSet } from "../../src/app/template_set";
|
|
||||||
import { mount } from "../../src/blockdom";
|
|
||||||
import { makeTestFixture, renderToBdom, renderToString, snapshotEverything } from "../helpers";
|
|
||||||
import { markup } from "../../src/utils";
|
|
||||||
|
|
||||||
snapshotEverything();
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
// t-on
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
describe("t-on", () => {
|
|
||||||
function mountToFixture(template: string, ctx: any = {}, node?: any): HTMLDivElement {
|
|
||||||
if (!node) {
|
|
||||||
node = { component: ctx };
|
|
||||||
ctx.__owl__ = node;
|
|
||||||
}
|
|
||||||
const block = renderToBdom(template, ctx, node);
|
|
||||||
const fixture = makeTestFixture();
|
|
||||||
|
|
||||||
mount(block, fixture);
|
|
||||||
return fixture;
|
|
||||||
}
|
|
||||||
|
|
||||||
test("can bind event handler", () => {
|
|
||||||
const template = `<button t-on-click="add">Click</button>`;
|
|
||||||
let a = 1;
|
|
||||||
const fixture = mountToFixture(template, { add: () => (a = 3) });
|
|
||||||
expect(a).toBe(1);
|
|
||||||
fixture.querySelector("button")!.click();
|
|
||||||
expect(a).toBe(3);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("receive event in first argument", () => {
|
|
||||||
expect.assertions(2);
|
|
||||||
const template = `<button t-on-click="add">Click</button>`;
|
|
||||||
const fixture = mountToFixture(template, {
|
|
||||||
add: (ev: any) => {
|
|
||||||
expect(ev).toBeInstanceOf(Event);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
fixture.querySelector("button")!.click();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("can bind two event handlers", () => {
|
|
||||||
const template = `
|
|
||||||
<button t-on-click="handleClick" t-on-dblclick="handleDblClick">Click</button>`;
|
|
||||||
let steps: string[] = [];
|
|
||||||
const fixture = mountToFixture(template, {
|
|
||||||
handleClick() {
|
|
||||||
steps.push("click");
|
|
||||||
},
|
|
||||||
handleDblClick() {
|
|
||||||
steps.push("dblclick");
|
|
||||||
},
|
|
||||||
});
|
|
||||||
expect(steps).toEqual([]);
|
|
||||||
fixture.querySelector("button")!.click();
|
|
||||||
expect(steps).toEqual(["click"]);
|
|
||||||
fixture.querySelector("button")!.dispatchEvent(new Event("dblclick", { bubbles: true }));
|
|
||||||
expect(steps).toEqual(["click", "dblclick"]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("can bind handlers with arguments", () => {
|
|
||||||
const template = `<button t-on-click="() => add(5)">Click</button>`;
|
|
||||||
let a = 1;
|
|
||||||
const fixture = mountToFixture(template, { add: (n: number) => (a = a + n) });
|
|
||||||
expect(a).toBe(1);
|
|
||||||
fixture.querySelector("button")!.click();
|
|
||||||
expect(a).toBe(6);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("can bind handlers with object arguments", () => {
|
|
||||||
const template = `<button t-on-click="() => add({val: 5})">Click</button>`;
|
|
||||||
let a = 1;
|
|
||||||
const fixture = mountToFixture(template, { add: ({ val }: any) => (a = a + val) });
|
|
||||||
expect(a).toBe(1);
|
|
||||||
fixture.querySelector("button")!.click();
|
|
||||||
expect(a).toBe(6);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("can bind handlers with empty object", () => {
|
|
||||||
expect.assertions(2);
|
|
||||||
const template = `<button t-on-click="() => doSomething({})">Click</button>`;
|
|
||||||
const fixture = mountToFixture(template, {
|
|
||||||
doSomething(arg: any) {
|
|
||||||
expect(arg).toEqual({});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
fixture.querySelector("button")!.click();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("can bind handlers with empty object (with non empty inner string)", () => {
|
|
||||||
expect.assertions(2);
|
|
||||||
const template = `<button t-on-click="() => doSomething({ })">Click</button>`;
|
|
||||||
const fixture = mountToFixture(template, {
|
|
||||||
doSomething(arg: any) {
|
|
||||||
expect(arg).toEqual({});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
fixture.querySelector("button")!.click();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("can bind handlers with empty object (with non empty inner string)", () => {
|
|
||||||
expect.assertions(2);
|
|
||||||
const template = `
|
|
||||||
<ul>
|
|
||||||
<li t-foreach="['someval']" t-as="action" t-key="action_index">
|
|
||||||
<a t-on-click="() => activate(action)">link</a>
|
|
||||||
</li>
|
|
||||||
</ul>`;
|
|
||||||
const fixture = mountToFixture(template, {
|
|
||||||
activate(action: string) {
|
|
||||||
expect(action).toBe("someval");
|
|
||||||
},
|
|
||||||
});
|
|
||||||
fixture.querySelector("a")!.click();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("handler is bound to proper owner", () => {
|
|
||||||
expect.assertions(2);
|
|
||||||
const template = `<button t-on-click="add">Click</button>`;
|
|
||||||
let owner = {
|
|
||||||
add() {
|
|
||||||
expect(this).toBe(owner);
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const fixture = mountToFixture(template, owner);
|
|
||||||
fixture.querySelector("button")!.click();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("handler is bound to proper owner, part 2", () => {
|
|
||||||
expect.assertions(2);
|
|
||||||
const template = `
|
|
||||||
<t t-foreach="[1]" t-as="value" t-key="value">
|
|
||||||
<button t-on-click="add">Click</button>
|
|
||||||
</t>`;
|
|
||||||
let owner = {
|
|
||||||
add() {
|
|
||||||
expect(this).toBe(owner);
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const fixture = mountToFixture(template, owner);
|
|
||||||
fixture.querySelector("button")!.click();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("handler is bound to proper owner, part 3", () => {
|
|
||||||
expect.assertions(3);
|
|
||||||
const context = new TemplateSet();
|
|
||||||
const sub = `<button t-on-click="add">Click</button>`;
|
|
||||||
const main = `<t t-call="sub"/>`;
|
|
||||||
context.addTemplate("sub", sub);
|
|
||||||
context.addTemplate("main", main);
|
|
||||||
|
|
||||||
let owner: any = {
|
|
||||||
add() {
|
|
||||||
expect(this).toBe(owner);
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const node = { component: owner };
|
|
||||||
owner.__owl__ = node;
|
|
||||||
const fixture = makeTestFixture();
|
|
||||||
const render = context.getTemplate("main");
|
|
||||||
const bdom = render(owner, node);
|
|
||||||
mount(bdom, fixture);
|
|
||||||
fixture.querySelector("button")!.click();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("handler is bound to proper owner, part 4", () => {
|
|
||||||
expect.assertions(3);
|
|
||||||
const context = new TemplateSet();
|
|
||||||
const sub = `<button t-on-click="add">Click</button>`;
|
|
||||||
const main = `
|
|
||||||
<t t-foreach="[1]" t-as="value" t-key="value">
|
|
||||||
<t t-call="sub"/>
|
|
||||||
</t>`;
|
|
||||||
context.addTemplate("sub", sub);
|
|
||||||
context.addTemplate("main", main);
|
|
||||||
|
|
||||||
let owner: any = {
|
|
||||||
add() {
|
|
||||||
expect(this).toBe(owner);
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const node = { component: owner };
|
|
||||||
owner.__owl__ = node;
|
|
||||||
const fixture = makeTestFixture();
|
|
||||||
const render = context.getTemplate("main");
|
|
||||||
const bdom = render(owner, node);
|
|
||||||
mount(bdom, fixture);
|
|
||||||
fixture.querySelector("button")!.click();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("t-on with inline statement", () => {
|
|
||||||
const template = `<button t-on-click="() => state.counter++">Click</button>`;
|
|
||||||
let owner = { state: { counter: 0 } };
|
|
||||||
const fixture = mountToFixture(template, owner);
|
|
||||||
expect(owner.state.counter).toBe(0);
|
|
||||||
fixture.querySelector("button")!.click();
|
|
||||||
expect(owner.state.counter).toBe(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("t-on with inline statement (function call)", () => {
|
|
||||||
const template = `<button t-on-click="() => state.incrementCounter(2)">Click</button>`;
|
|
||||||
let owner = {
|
|
||||||
state: {
|
|
||||||
counter: 0,
|
|
||||||
incrementCounter: (inc: number) => {
|
|
||||||
owner.state.counter += inc;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const fixture = mountToFixture(template, owner);
|
|
||||||
expect(owner.state.counter).toBe(0);
|
|
||||||
fixture.querySelector("button")!.click();
|
|
||||||
expect(owner.state.counter).toBe(2);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("t-on with inline statement, part 2", () => {
|
|
||||||
const template = `<button t-on-click="() => state.flag = !state.flag">Toggle</button>`;
|
|
||||||
let owner = {
|
|
||||||
state: {
|
|
||||||
flag: true,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const fixture = mountToFixture(template, owner);
|
|
||||||
expect(owner.state.flag).toBe(true);
|
|
||||||
fixture.querySelector("button")!.click();
|
|
||||||
expect(owner.state.flag).toBe(false);
|
|
||||||
fixture.querySelector("button")!.click();
|
|
||||||
expect(owner.state.flag).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("t-on with inline statement, part 3", () => {
|
|
||||||
const template = `<button t-on-click="() => state.n = someFunction(3)">Toggle</button>`;
|
|
||||||
let owner = {
|
|
||||||
someFunction(n: number) {
|
|
||||||
return n + 1;
|
|
||||||
},
|
|
||||||
state: {
|
|
||||||
n: 11,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const fixture = mountToFixture(template, owner);
|
|
||||||
expect(owner.state.n).toBe(11);
|
|
||||||
fixture.querySelector("button")!.click();
|
|
||||||
expect(owner.state.n).toBe(4);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("t-on with t-call", async () => {
|
|
||||||
expect.assertions(3);
|
|
||||||
const app = new TemplateSet();
|
|
||||||
const sub = `<p t-on-click="update">lucas</p>`;
|
|
||||||
const main = `<div><t t-call="sub"/></div>`;
|
|
||||||
app.addTemplate("sub", sub);
|
|
||||||
app.addTemplate("main", main);
|
|
||||||
|
|
||||||
let owner: any = {
|
|
||||||
update() {
|
|
||||||
expect(this).toBe(owner);
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const node = { component: owner };
|
|
||||||
owner.__owl__ = node;
|
|
||||||
|
|
||||||
const fixture = makeTestFixture();
|
|
||||||
const render = app.getTemplate("main");
|
|
||||||
const bdom = render(owner, node);
|
|
||||||
mount(bdom, fixture);
|
|
||||||
fixture.querySelector("p")!.click();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("t-on, with arguments and t-call", async () => {
|
|
||||||
expect.assertions(4);
|
|
||||||
const app = new TemplateSet();
|
|
||||||
const sub = `<p t-on-click="() => this.update(value)">lucas</p>`;
|
|
||||||
const main = `<div><t t-call="sub"/></div>`;
|
|
||||||
app.addTemplate("sub", sub);
|
|
||||||
app.addTemplate("main", main);
|
|
||||||
|
|
||||||
let owner: any = {
|
|
||||||
update(val: number) {
|
|
||||||
expect(this).toBe(owner);
|
|
||||||
expect(val).toBe(444);
|
|
||||||
},
|
|
||||||
value: 444,
|
|
||||||
};
|
|
||||||
|
|
||||||
const node = { component: owner };
|
|
||||||
owner.__owl__ = node;
|
|
||||||
|
|
||||||
const fixture = makeTestFixture();
|
|
||||||
const render = app.getTemplate("main");
|
|
||||||
const bdom = render.call(owner, owner, node);
|
|
||||||
mount(bdom, fixture);
|
|
||||||
fixture.querySelector("p")!.click();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("nice error when t-on is evaluated with a missing event", () => {
|
|
||||||
const template = `<div t-on="somemethod"></div>`;
|
|
||||||
expect(() => renderToString(template, { someMethod() {} })).toThrow(
|
|
||||||
"Missing event name with t-on directive"
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("t-on modifiers (native listener)", () => {
|
|
||||||
test("basic support for native listener", () => {
|
|
||||||
const template = `<div class="myClass" t-on-click="divClicked">
|
|
||||||
<button t-on-click="btnClicked">Button</button>
|
|
||||||
</div>`;
|
|
||||||
|
|
||||||
const steps: string[] = [];
|
|
||||||
|
|
||||||
const owner = {
|
|
||||||
divClicked(ev: Event) {
|
|
||||||
expect(ev.currentTarget).toBe(div);
|
|
||||||
steps.push("divClicked");
|
|
||||||
},
|
|
||||||
btnClicked(ev: Event) {
|
|
||||||
expect(ev.currentTarget).toBe(button);
|
|
||||||
steps.push("btnClicked");
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const node = mountToFixture(template, owner);
|
|
||||||
const div = node.querySelector(".myClass");
|
|
||||||
const button = (<HTMLElement>node).getElementsByTagName("button")[0];
|
|
||||||
button.click();
|
|
||||||
expect(steps).toEqual(["btnClicked", "divClicked"]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("t-on with prevent and/or stop modifiers", async () => {
|
|
||||||
expect.assertions(7);
|
|
||||||
const template = `<div>
|
|
||||||
<button t-on-click.prevent="onClickPrevented">Button 1</button>
|
|
||||||
<button t-on-click.stop="onClickStopped">Button 2</button>
|
|
||||||
<button t-on-click.prevent.stop="onClickPreventedAndStopped">Button 3</button>
|
|
||||||
</div>`;
|
|
||||||
|
|
||||||
let owner = {
|
|
||||||
onClickPrevented(e: Event) {
|
|
||||||
expect(e.defaultPrevented).toBe(true);
|
|
||||||
expect(e.cancelBubble).toBe(false);
|
|
||||||
},
|
|
||||||
onClickStopped(e: Event) {
|
|
||||||
expect(e.defaultPrevented).toBe(false);
|
|
||||||
expect(e.cancelBubble).toBe(true);
|
|
||||||
},
|
|
||||||
onClickPreventedAndStopped(e: Event) {
|
|
||||||
expect(e.defaultPrevented).toBe(true);
|
|
||||||
expect(e.cancelBubble).toBe(true);
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const node = mountToFixture(template, owner);
|
|
||||||
|
|
||||||
const buttons = (<HTMLElement>node).getElementsByTagName("button");
|
|
||||||
buttons[0].click();
|
|
||||||
buttons[1].click();
|
|
||||||
buttons[2].click();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("t-on with self modifier", async () => {
|
|
||||||
expect.assertions(2);
|
|
||||||
const template = `<div>
|
|
||||||
<button t-on-click="onClick"><span>Button</span></button>
|
|
||||||
<button t-on-click.self="onClickSelf"><span>Button</span></button>
|
|
||||||
</div>`;
|
|
||||||
let steps: string[] = [];
|
|
||||||
let owner = {
|
|
||||||
onClick(e: Event) {
|
|
||||||
steps.push("onClick");
|
|
||||||
},
|
|
||||||
onClickSelf(e: Event) {
|
|
||||||
steps.push("onClickSelf");
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const node = mountToFixture(template, owner);
|
|
||||||
|
|
||||||
const buttons = (<HTMLElement>node).getElementsByTagName("button");
|
|
||||||
const spans = (<HTMLElement>node).getElementsByTagName("span");
|
|
||||||
spans[0].click();
|
|
||||||
spans[1].click();
|
|
||||||
buttons[0].click();
|
|
||||||
buttons[1].click();
|
|
||||||
|
|
||||||
expect(steps).toEqual(["onClick", "onClick", "onClickSelf"]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("t-on with self and prevent modifiers (order matters)", async () => {
|
|
||||||
expect.assertions(2);
|
|
||||||
const template = `<div>
|
|
||||||
<button t-on-click.self.prevent="onClick"><span>Button</span></button>
|
|
||||||
</div>`;
|
|
||||||
let steps: boolean[] = [];
|
|
||||||
let owner = {
|
|
||||||
onClick() {},
|
|
||||||
};
|
|
||||||
const node = mountToFixture(template, owner);
|
|
||||||
(<HTMLElement>node).addEventListener("click", function (e) {
|
|
||||||
steps.push(e.defaultPrevented);
|
|
||||||
});
|
|
||||||
|
|
||||||
const button = (<HTMLElement>node).getElementsByTagName("button")[0];
|
|
||||||
const span = (<HTMLElement>node).getElementsByTagName("span")[0];
|
|
||||||
span.click();
|
|
||||||
button.click();
|
|
||||||
|
|
||||||
expect(steps).toEqual([false, true]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("t-on with prevent and self modifiers (order matters)", async () => {
|
|
||||||
expect.assertions(2);
|
|
||||||
const template = `<div>
|
|
||||||
<button t-on-click.prevent.self="onClick"><span>Button</span></button>
|
|
||||||
</div>`;
|
|
||||||
let steps: boolean[] = [];
|
|
||||||
let owner = {
|
|
||||||
onClick() {},
|
|
||||||
};
|
|
||||||
const node = mountToFixture(template, owner);
|
|
||||||
(<HTMLElement>node).addEventListener("click", function (e) {
|
|
||||||
steps.push(e.defaultPrevented);
|
|
||||||
});
|
|
||||||
|
|
||||||
const button = (<HTMLElement>node).getElementsByTagName("button")[0];
|
|
||||||
const span = (<HTMLElement>node).getElementsByTagName("span")[0];
|
|
||||||
span.click();
|
|
||||||
button.click();
|
|
||||||
|
|
||||||
expect(steps).toEqual([true, true]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("t-on with prevent modifier in t-foreach", async () => {
|
|
||||||
expect.assertions(5);
|
|
||||||
const template = `<div>
|
|
||||||
<t t-foreach="projects" t-as="project" t-key="project">
|
|
||||||
<a href="#" t-on-click.prevent="ev => onEdit(project.id, ev)">
|
|
||||||
Edit <t t-esc="project.name"/>
|
|
||||||
</a>
|
|
||||||
</t>
|
|
||||||
</div>`;
|
|
||||||
const steps: string[] = [];
|
|
||||||
const owner = {
|
|
||||||
projects: [
|
|
||||||
{ id: 1, name: "Project 1" },
|
|
||||||
{ id: 2, name: "Project 2" },
|
|
||||||
],
|
|
||||||
|
|
||||||
onEdit(projectId: string, ev: Event) {
|
|
||||||
expect(ev.defaultPrevented).toBe(true);
|
|
||||||
steps.push(projectId);
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const node = mountToFixture(template, owner);
|
|
||||||
expect(node.innerHTML).toBe(
|
|
||||||
`<div><a href="#"> Edit Project 1</a><a href="#"> Edit Project 2</a></div>`
|
|
||||||
);
|
|
||||||
|
|
||||||
const links = node.querySelectorAll("a")!;
|
|
||||||
links[0].click();
|
|
||||||
links[1].click();
|
|
||||||
|
|
||||||
expect(steps).toEqual([1, 2]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("t-on with empty handler (only modifiers)", () => {
|
|
||||||
expect.assertions(2);
|
|
||||||
const template = `<div>
|
|
||||||
<button t-on-click.prevent="">Button</button>
|
|
||||||
</div>`;
|
|
||||||
const node = mountToFixture(template, {});
|
|
||||||
|
|
||||||
node.addEventListener("click", (e) => {
|
|
||||||
expect(e.defaultPrevented).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
const button = (<HTMLElement>node).getElementsByTagName("button")[0];
|
|
||||||
button.click();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("t-on combined with t-esc", async () => {
|
|
||||||
expect.assertions(3);
|
|
||||||
const template = `<div><button t-on-click="onClick" t-esc="text"/></div>`;
|
|
||||||
const steps: string[] = [];
|
|
||||||
const owner = {
|
|
||||||
text: "Click here",
|
|
||||||
onClick() {
|
|
||||||
steps.push("onClick");
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const node = mountToFixture(template, owner);
|
|
||||||
expect(node.innerHTML).toBe(`<div><button>Click here</button></div>`);
|
|
||||||
|
|
||||||
node.querySelector("button")!.click();
|
|
||||||
|
|
||||||
expect(steps).toEqual(["onClick"]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("t-on combined with t-out", async () => {
|
|
||||||
expect.assertions(3);
|
|
||||||
const template = `<div><button t-on-click="onClick" t-out="html"/></div>`;
|
|
||||||
const steps: string[] = [];
|
|
||||||
const owner = {
|
|
||||||
html: markup("Click <b>here</b>"),
|
|
||||||
onClick() {
|
|
||||||
steps.push("onClick");
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const node = mountToFixture(template, owner);
|
|
||||||
expect(node.innerHTML).toBe(`<div><button>Click <b>here</b></button></div>`);
|
|
||||||
|
|
||||||
node.querySelector("button")!.click();
|
|
||||||
|
|
||||||
expect(steps).toEqual(["onClick"]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("t-on with .capture modifier", () => {
|
|
||||||
expect.assertions(2);
|
|
||||||
const template = `<div t-on-click.capture="onCapture">
|
|
||||||
<button t-on-click="doSomething">Button</button>
|
|
||||||
</div>`;
|
|
||||||
|
|
||||||
const steps: string[] = [];
|
|
||||||
const owner = {
|
|
||||||
onCapture() {
|
|
||||||
steps.push("captured");
|
|
||||||
},
|
|
||||||
doSomething() {
|
|
||||||
steps.push("normal");
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const node = mountToFixture(template, owner);
|
|
||||||
|
|
||||||
const button = (<HTMLElement>node).getElementsByTagName("button")[0];
|
|
||||||
button.click();
|
|
||||||
expect(steps).toEqual(["captured", "normal"]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("t-on modifiers (synthetic listener)", () => {
|
|
||||||
test("basic support for synthetic", () => {
|
|
||||||
const template = `<div t-on-click.synthetic="divClicked">
|
|
||||||
<button t-on-click.synthetic="btnClicked">Button</button>
|
|
||||||
</div>`;
|
|
||||||
|
|
||||||
const steps: string[] = [];
|
|
||||||
|
|
||||||
const owner = {
|
|
||||||
divClicked(ev: Event) {
|
|
||||||
expect(ev.currentTarget).toBe(document);
|
|
||||||
steps.push("divClicked");
|
|
||||||
},
|
|
||||||
btnClicked(ev: Event) {
|
|
||||||
expect(ev.currentTarget).toBe(document);
|
|
||||||
steps.push("btnClicked");
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const node = mountToFixture(template, owner);
|
|
||||||
const button = (<HTMLElement>node).getElementsByTagName("button")[0];
|
|
||||||
button.click();
|
|
||||||
expect(steps).toEqual(["btnClicked", "divClicked"]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
import { renderToString, snapshotEverything } from "../helpers";
|
|
||||||
|
|
||||||
snapshotEverything();
|
|
||||||
|
|
||||||
describe("memory", () => {
|
|
||||||
test("t-foreach does not leak stuff in global scope", () => {
|
|
||||||
const initialNumberOfGlobals = Object.keys(window).length;
|
|
||||||
const template = `<p><t t-foreach="[3, 2, 1]" t-as="item" t-key="item_index"><t t-esc="item"/></t></p>`;
|
|
||||||
expect(renderToString(template)).toBe("<p>321</p>");
|
|
||||||
expect(Object.keys(window).length).toBe(initialNumberOfGlobals);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
import { renderToString, snapshotEverything } from "../helpers";
|
|
||||||
|
|
||||||
// NB: check the snapshots to see where the SVG namespaces are added
|
|
||||||
snapshotEverything();
|
|
||||||
|
|
||||||
describe("properly support svg", () => {
|
|
||||||
test("add proper namespace to svg", () => {
|
|
||||||
const template = `<svg width="100px" height="90px"><circle cx="50" cy="50" r="4" stroke="green" stroke-width="1" fill="yellow"/> </svg>`;
|
|
||||||
expect(renderToString(template)).toBe(
|
|
||||||
`<svg width=\"100px\" height=\"90px\"><circle cx=\"50\" cy=\"50\" r=\"4\" stroke=\"green\" stroke-width=\"1\" fill=\"yellow\"></circle> </svg>`
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("add proper namespace to g tags", () => {
|
|
||||||
const template = `<g><circle cx="50" cy="50" r="4" stroke="green" stroke-width="1" fill="yellow"/> </g>`;
|
|
||||||
expect(renderToString(template)).toBe(
|
|
||||||
`<g><circle cx=\"50\" cy=\"50\" r=\"4\" stroke=\"green\" stroke-width=\"1\" fill=\"yellow\"></circle> </g>`
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("namespace to g tags not added if already in svg namespace", () => {
|
|
||||||
const template = `<svg><g/></svg>`;
|
|
||||||
expect(renderToString(template)).toBe(`<svg><g></g></svg>`);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("namespace to svg tags added even if already in svg namespace", () => {
|
|
||||||
const template = `<svg><svg/></svg>`;
|
|
||||||
expect(renderToString(template)).toBe(`<svg><svg></svg></svg>`);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
import { renderToString, renderToBdom, snapshotEverything, makeTestFixture } from "../helpers";
|
|
||||||
import { mount, patch } from "../../src/blockdom/index";
|
|
||||||
|
|
||||||
snapshotEverything();
|
|
||||||
|
|
||||||
describe("t-key", () => {
|
|
||||||
test("can use t-key directive on a node", () => {
|
|
||||||
const template = `<div t-key="beer.id"><t t-esc="beer.name"/></div>`;
|
|
||||||
expect(renderToString(template, { beer: { id: 12, name: "Chimay Rouge" } })).toBe(
|
|
||||||
"<div>Chimay Rouge</div>"
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("can use t-key directive on a node as a function", () => {
|
|
||||||
const template = `<div t-key="getKey(beer)"><t t-esc="beer.name"/></div>`;
|
|
||||||
const getKey = (arg: any) => arg.id;
|
|
||||||
expect(renderToString(template, { getKey, beer: { id: 12, name: "Chimay Rouge" } })).toBe(
|
|
||||||
"<div>Chimay Rouge</div>"
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("can use t-key directive on a node 2", async () => {
|
|
||||||
const template = `<div t-key="beer.id"><t t-esc="beer.name"/></div>`;
|
|
||||||
const bd = renderToBdom(template, { beer: { id: 12, name: "Chimay Rouge" } });
|
|
||||||
const fixture = makeTestFixture();
|
|
||||||
await mount(bd, fixture);
|
|
||||||
const div = fixture.firstChild;
|
|
||||||
|
|
||||||
expect((div as HTMLElement).outerHTML).toBe("<div>Chimay Rouge</div>");
|
|
||||||
const bd2 = renderToBdom(template, { beer: { id: 13, name: "Chimay Rouge" } });
|
|
||||||
await patch(bd, bd2);
|
|
||||||
expect(div !== fixture.firstChild).toBeTruthy();
|
|
||||||
expect((div as HTMLElement).outerHTML).toBe("<div>Chimay Rouge</div>");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("t-key directive in a list", () => {
|
|
||||||
const template = `<ul>
|
|
||||||
<li t-foreach="beers" t-as="beer" t-key="beer.id"><t t-esc="beer.name"/></li>
|
|
||||||
</ul>`;
|
|
||||||
expect(
|
|
||||||
renderToString(template, {
|
|
||||||
beers: [{ id: 12, name: "Chimay Rouge" }],
|
|
||||||
})
|
|
||||||
).toBe("<ul><li>Chimay Rouge</li></ul>");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,239 +0,0 @@
|
|||||||
import {
|
|
||||||
renderToString,
|
|
||||||
renderToBdom,
|
|
||||||
snapshotEverything,
|
|
||||||
TestContext,
|
|
||||||
makeTestFixture,
|
|
||||||
} from "../helpers";
|
|
||||||
import { mount, patch } from "../../src/blockdom";
|
|
||||||
import { createBlock } from "../../src/blockdom/index";
|
|
||||||
import { markup } from "../../src/utils";
|
|
||||||
|
|
||||||
snapshotEverything();
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
// t-out
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
describe("t-out", () => {
|
|
||||||
let fixture: HTMLElement;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
fixture = makeTestFixture();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("literal", () => {
|
|
||||||
const template = `<span><t t-out="'ok'"/></span>`;
|
|
||||||
expect(renderToString(template)).toBe("<span>ok</span>");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("literal, no outside html element", () => {
|
|
||||||
const template = `<t t-out="'ok'"/>`;
|
|
||||||
expect(renderToString(template)).toBe("ok");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("variable", () => {
|
|
||||||
const template = `<span><t t-out="var"/></span>`;
|
|
||||||
expect(renderToString(template, { var: "ok" })).toBe("<span>ok</span>");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("not escaping", () => {
|
|
||||||
const template = `<div><t t-out="var"/></div>`;
|
|
||||||
expect(renderToString(template, { var: markup("<ok></ok>") })).toBe("<div><ok></ok></div>");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("t-out and another sibling node", () => {
|
|
||||||
const template = `<span><span>hello</span><t t-out="var"/></span>`;
|
|
||||||
expect(renderToString(template, { var: markup("<ok>world</ok>") })).toBe(
|
|
||||||
"<span><span>hello</span><ok>world</ok></span>"
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("t-out with comment", () => {
|
|
||||||
const template = `<span><t t-out="var"/></span>`;
|
|
||||||
expect(renderToString(template, { var: markup("<p>text<!-- top secret --></p>") })).toBe(
|
|
||||||
"<span><p>text<!-- top secret --></p></span>"
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("t-out on a node with a body, as a default", () => {
|
|
||||||
const template = `<span t-out="var">nope</span>`;
|
|
||||||
expect(renderToString(template)).toBe("<span>nope</span>");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("t-out with a <t/> in body", () => {
|
|
||||||
const template = `<t t-out="var"><t></t></t>`;
|
|
||||||
expect(renderToString(template, { var: "coucou" })).toBe("coucou");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("t-out with just a t-set t-value in body", () => {
|
|
||||||
const template = `<t t-out="var"><t t-set="a" t-value="1" /></t>`;
|
|
||||||
expect(renderToString(template, { var: "coucou" })).toBe("coucou");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("t-out on a node with a dom node in body, as a default", () => {
|
|
||||||
const template = `<span t-out="var"><div>nope</div></span>`;
|
|
||||||
expect(renderToString(template)).toBe("<span><div>nope</div></span>");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("multiple calls to t-out", () => {
|
|
||||||
const context = new TestContext();
|
|
||||||
const sub = `
|
|
||||||
<div>
|
|
||||||
<t t-out="0"/>
|
|
||||||
<div>Greeter</div>
|
|
||||||
<t t-out="0"/>
|
|
||||||
</div>`;
|
|
||||||
|
|
||||||
const main = `
|
|
||||||
<div>
|
|
||||||
<t t-call="sub">
|
|
||||||
<span>coucou</span>
|
|
||||||
</t>
|
|
||||||
</div>`;
|
|
||||||
|
|
||||||
context.addTemplate("sub", sub);
|
|
||||||
context.addTemplate("main", main);
|
|
||||||
const expected =
|
|
||||||
"<div><div><span>coucou</span><div>Greeter</div><span>coucou</span></div></div>";
|
|
||||||
expect(context.renderToString("main")).toBe(expected);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("t-out escaped", () => {
|
|
||||||
const template = `<span t-out="var" />`;
|
|
||||||
expect(renderToString(template, { var: "<div>nope</div>" })).toBe(
|
|
||||||
"<span><div>nope</div></span>"
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("t-out markedup", () => {
|
|
||||||
const template = `<span t-out="var" />`;
|
|
||||||
expect(renderToString(template, { var: markup("<div>nope</div>") })).toBe(
|
|
||||||
"<span><div>nope</div></span>"
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("t-out switch escaped", () => {
|
|
||||||
const template = `<span t-out="var" />`;
|
|
||||||
const node = renderToBdom(template, { var: "<div>nope</div>" });
|
|
||||||
mount(node, fixture);
|
|
||||||
|
|
||||||
expect(fixture.innerHTML).toBe("<span><div>nope</div></span>");
|
|
||||||
patch(node, renderToBdom(template, { var: "<li>yep</li>" }));
|
|
||||||
|
|
||||||
expect(fixture.innerHTML).toBe("<span><li>yep</li></span>");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("t-out switch markup", () => {
|
|
||||||
const template = `<span t-out="var" />`;
|
|
||||||
const node = renderToBdom(template, { var: markup("<div>nope</div>") });
|
|
||||||
mount(node, fixture);
|
|
||||||
|
|
||||||
expect(fixture.innerHTML).toBe("<span><div>nope</div></span>");
|
|
||||||
patch(node, renderToBdom(template, { var: markup("<li>yep</li>") }));
|
|
||||||
|
|
||||||
expect(fixture.innerHTML).toBe("<span><li>yep</li></span>");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("t-out switch markup on escaped", () => {
|
|
||||||
const template = `<span t-out="var" />`;
|
|
||||||
const node = renderToBdom(template, { var: "<div>nope</div>" });
|
|
||||||
mount(node, fixture);
|
|
||||||
|
|
||||||
expect(fixture.innerHTML).toBe("<span><div>nope</div></span>");
|
|
||||||
patch(node, renderToBdom(template, { var: markup("<li>yep</li>") }));
|
|
||||||
|
|
||||||
expect(fixture.innerHTML).toBe("<span><li>yep</li></span>");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("t-out switch escaped on markup", () => {
|
|
||||||
const template = `<span t-out="var" />`;
|
|
||||||
const node = renderToBdom(template, { var: markup("<div>nope</div>") });
|
|
||||||
mount(node, fixture);
|
|
||||||
|
|
||||||
expect(fixture.innerHTML).toBe("<span><div>nope</div></span>");
|
|
||||||
patch(node, renderToBdom(template, { var: "<li>yep</li>" }));
|
|
||||||
|
|
||||||
expect(fixture.innerHTML).toBe("<span><li>yep</li></span>");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("t-out block", () => {
|
|
||||||
const block = createBlock("<div>block</div>");
|
|
||||||
const template = `<span t-out="bdom"/>`;
|
|
||||||
expect(renderToString(template, { bdom: block() })).toBe("<span><div>block</div></span>");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("t-out bdom", () => {
|
|
||||||
const template = `<div><t t-set="var"><ol>set</ol></t><span t-out="var" /></div>`;
|
|
||||||
expect(renderToString(template)).toBe("<div><span><ol>set</ol></span></div>");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("t-out switch markup on bdom", () => {
|
|
||||||
const template = `<div>
|
|
||||||
<t t-set="bdom"><ol>set</ol></t>
|
|
||||||
<t t-if="hasBdom">
|
|
||||||
<span t-out="bdom" />
|
|
||||||
</t>
|
|
||||||
<t t-else="">
|
|
||||||
<span t-out="var" />
|
|
||||||
</t>
|
|
||||||
</div>`;
|
|
||||||
|
|
||||||
const node = renderToBdom(template, { hasBdom: true, var: markup("<li>yep</li>") });
|
|
||||||
mount(node, fixture);
|
|
||||||
|
|
||||||
expect(fixture.innerHTML).toBe("<div><span><ol>set</ol></span></div>");
|
|
||||||
patch(node, renderToBdom(template, { hasBdom: false, var: markup("<li>yep</li>") }));
|
|
||||||
|
|
||||||
expect(fixture.innerHTML).toBe("<div><span><li>yep</li></span></div>");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("t-out 0", () => {
|
|
||||||
const context = new TestContext();
|
|
||||||
context.addTemplate("_basic-callee", `<div><t t-out="0" /></div>`);
|
|
||||||
context.addTemplate("caller", `<div><t t-call="_basic-callee"><div>zero</div></t></div>`);
|
|
||||||
const node = context.getTemplate("caller")({}, null, "");
|
|
||||||
mount(node, fixture);
|
|
||||||
expect(fixture.innerHTML).toBe("<div><div><div>zero</div></div></div>");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("t-out with arbitrary object", () => {
|
|
||||||
const template = `<div t-out="var" />`;
|
|
||||||
const node = renderToBdom(template, { var: { someKey: "someValue" } });
|
|
||||||
expect(() => mount(node, fixture)).toThrow();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("t-out with arbitrary object 2", () => {
|
|
||||||
const template = `<div t-out="var" />`;
|
|
||||||
const node = renderToBdom(template, { var: ["someValue"] });
|
|
||||||
expect(() => mount(node, fixture)).toThrow();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("t-raw is deprecated", () => {
|
|
||||||
test("should warn", () => {
|
|
||||||
const template = `<div t-raw="var" />`;
|
|
||||||
const warn = console.warn;
|
|
||||||
const steps: string[] = [];
|
|
||||||
console.warn = (msg: any) => steps.push(msg);
|
|
||||||
|
|
||||||
expect(renderToString(template, { var: "<div>escaped</div>" })).toBe(
|
|
||||||
"<div><div>escaped</div></div>"
|
|
||||||
);
|
|
||||||
expect(steps).toEqual([
|
|
||||||
't-raw has been deprecated in favor of t-out. If the value to render is not wrapped by the "markup" function, it will be escaped',
|
|
||||||
]);
|
|
||||||
console.warn = warn;
|
|
||||||
});
|
|
||||||
|
|
||||||
test("t-out is actually called in t-raw's place", () => {
|
|
||||||
const template = `<div t-raw="var" />`;
|
|
||||||
const warn = console.warn;
|
|
||||||
console.warn = (msg: any) => msg;
|
|
||||||
|
|
||||||
expect(renderToString(template, { var: markup("<div>raw</div>") })).toBe(
|
|
||||||
"<div><div>raw</div></div>"
|
|
||||||
);
|
|
||||||
console.warn = warn;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
import { mount, patch } from "../../src/blockdom";
|
|
||||||
import { makeTestFixture, renderToBdom, renderToString, snapshotEverything } from "../helpers";
|
|
||||||
|
|
||||||
snapshotEverything();
|
|
||||||
|
|
||||||
let fixture: HTMLElement;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
fixture = makeTestFixture();
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
fixture.remove();
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("qweb t-tag", () => {
|
|
||||||
test("simple usecases", () => {
|
|
||||||
expect(renderToString(`<t t-tag="'div'"></t>`)).toBe("<div></div>");
|
|
||||||
expect(renderToString(`<t t-tag="tag">text</t>`, { tag: "span" })).toBe("<span>text</span>");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("with multiple child nodes", () => {
|
|
||||||
const template = `
|
|
||||||
<t t-tag="tag">
|
|
||||||
pear
|
|
||||||
<span>apple</span>
|
|
||||||
strawberry
|
|
||||||
</t>`;
|
|
||||||
expect(renderToString(template, { tag: "div" })).toBe(
|
|
||||||
"<div> pear <span>apple</span> strawberry </div>"
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("with multiple attributes", () => {
|
|
||||||
const template = `<t t-tag="tag" class="blueberry" taste="raspberry">gooseberry</t>`;
|
|
||||||
const expected = `<div class=\"blueberry\" taste=\"raspberry\">gooseberry</div>`;
|
|
||||||
expect(renderToString(template, { tag: "div" })).toBe(expected);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("can fallback if falsy tag", () => {
|
|
||||||
const template = `<fallback t-tag="tag"/>`;
|
|
||||||
expect(renderToString(template, { tag: "div" })).toBe(`<div></div>`);
|
|
||||||
expect(renderToString(template, { tag: "" })).toBe(`<fallback></fallback>`);
|
|
||||||
expect(renderToString(template, { tag: undefined })).toBe(`<fallback></fallback>`);
|
|
||||||
expect(renderToString(template, { tag: null })).toBe(`<fallback></fallback>`);
|
|
||||||
expect(renderToString(template, { tag: false })).toBe(`<fallback></fallback>`);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("with multiple t-tag in same template", () => {
|
|
||||||
const template = `<t t-tag="outer"><t t-tag="inner">baz</t></t>`;
|
|
||||||
expect(renderToString(template, { outer: "foo", inner: "bar" })).toBe(
|
|
||||||
`<foo><bar>baz</bar></foo>`
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("with multiple t-tag in same template, part 2", () => {
|
|
||||||
const template = `<t t-tag="brother">bar</t><t t-tag="brother">baz</t>`;
|
|
||||||
expect(renderToString(template, { brother: "foo" })).toBe(`<foo>bar</foo><foo>baz</foo>`);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("can update", () => {
|
|
||||||
const template = `<t t-tag="tag"></t>`;
|
|
||||||
const bdom = renderToBdom(template, { tag: "yop" });
|
|
||||||
mount(bdom, fixture);
|
|
||||||
expect(fixture.innerHTML).toBe("<yop></yop>");
|
|
||||||
patch(bdom, renderToBdom(template, { tag: "gnap" }));
|
|
||||||
expect(fixture.innerHTML).toBe("<gnap></gnap>");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
import { snapshotEverything, TestContext } from "../helpers";
|
|
||||||
|
|
||||||
snapshotEverything();
|
|
||||||
|
|
||||||
describe("loading templates", () => {
|
|
||||||
test("can initialize qweb with a string", () => {
|
|
||||||
const templates = `<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<templates id="template" xml:space="preserve">
|
|
||||||
<div t-name="hey">jupiler</div>
|
|
||||||
</templates>`;
|
|
||||||
const context = new TestContext();
|
|
||||||
context.addTemplates(templates);
|
|
||||||
expect(context.renderToString("hey")).toBe("<div>jupiler</div>");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("can initialize qweb with an XMLDocument", () => {
|
|
||||||
const data = `<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<templates id="template" xml:space="preserve">
|
|
||||||
<div t-name="hey">jupiler</div>
|
|
||||||
</templates>`;
|
|
||||||
const xml = new DOMParser().parseFromString(data, "text/xml");
|
|
||||||
const context = new TestContext();
|
|
||||||
context.addTemplates(xml);
|
|
||||||
expect(context.renderToString("hey")).toBe("<div>jupiler</div>");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("can load a few templates from a xml string", () => {
|
|
||||||
const data = `<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<templates id="template" xml:space="preserve">
|
|
||||||
|
|
||||||
<t t-name="items"><li>ok</li><li>foo</li></t>
|
|
||||||
|
|
||||||
<ul t-name="main"><t t-call="items"/></ul>
|
|
||||||
</templates>`;
|
|
||||||
const context = new TestContext();
|
|
||||||
context.addTemplates(data);
|
|
||||||
const result = context.renderToString("main");
|
|
||||||
expect(result).toBe("<ul><li>ok</li><li>foo</li></ul>");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("can load a few templates from an XMLDocument", () => {
|
|
||||||
const data = `<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<templates id="template" xml:space="preserve">
|
|
||||||
|
|
||||||
<t t-name="items"><li>ok</li><li>foo</li></t>
|
|
||||||
|
|
||||||
<ul t-name="main"><t t-call="items"/></ul>
|
|
||||||
</templates>`;
|
|
||||||
const xml = new DOMParser().parseFromString(data, "text/xml");
|
|
||||||
const context = new TestContext();
|
|
||||||
context.addTemplates(xml);
|
|
||||||
const result = context.renderToString("main");
|
|
||||||
expect(result).toBe("<ul><li>ok</li><li>foo</li></ul>");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("does not crash if string does not have templates", () => {
|
|
||||||
const data = "";
|
|
||||||
const context = new TestContext();
|
|
||||||
context.addTemplates(data);
|
|
||||||
expect(Object.keys(context.rawTemplates)).toEqual([]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("does not crash if XMLDocument does not have templates", () => {
|
|
||||||
const data = "";
|
|
||||||
const xml = new DOMParser().parseFromString(data, "text/xml");
|
|
||||||
const context = new TestContext();
|
|
||||||
context.addTemplates(xml);
|
|
||||||
expect(Object.keys(context.rawTemplates)).toEqual([]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,116 +0,0 @@
|
|||||||
import { App, Component } from "../../src";
|
|
||||||
import { makeTestFixture, snapshotApp } from "../helpers";
|
|
||||||
import { xml } from "../../src/tags";
|
|
||||||
|
|
||||||
let fixture: HTMLElement;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
fixture = makeTestFixture();
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("translation support", () => {
|
|
||||||
test("can translate node content", async () => {
|
|
||||||
class SomeComponent extends Component {
|
|
||||||
static template = xml`<div>word</div>`;
|
|
||||||
}
|
|
||||||
|
|
||||||
const app = new App(SomeComponent);
|
|
||||||
app.configure({
|
|
||||||
translateFn: (expr: string) => (expr === "word" ? "mot" : expr),
|
|
||||||
});
|
|
||||||
const comp = await app.mount(fixture);
|
|
||||||
|
|
||||||
const el = comp.el as HTMLElement;
|
|
||||||
|
|
||||||
expect(el.outerHTML).toBe("<div>mot</div>");
|
|
||||||
snapshotApp(app);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("does not translate node content if disabled", async () => {
|
|
||||||
class SomeComponent extends Component {
|
|
||||||
static template = xml`
|
|
||||||
<div>
|
|
||||||
<span>word</span>
|
|
||||||
<span t-translation="off">word</span>
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
|
|
||||||
const app = new App(SomeComponent);
|
|
||||||
app.configure({
|
|
||||||
translateFn: (expr: string) => (expr === "word" ? "mot" : expr),
|
|
||||||
});
|
|
||||||
const comp = await app.mount(fixture);
|
|
||||||
|
|
||||||
const el = comp.el as HTMLElement;
|
|
||||||
|
|
||||||
expect(el.outerHTML).toBe("<div><span>mot</span><span>word</span></div>");
|
|
||||||
snapshotApp(app);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("some attributes are translated", async () => {
|
|
||||||
class SomeComponent extends Component {
|
|
||||||
static template = xml`
|
|
||||||
<div>
|
|
||||||
<p label="word">word</p>
|
|
||||||
<p title="word">word</p>
|
|
||||||
<p placeholder="word">word</p>
|
|
||||||
<p alt="word">word</p>
|
|
||||||
<p something="word">word</p>
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
|
|
||||||
const app = new App(SomeComponent);
|
|
||||||
app.configure({
|
|
||||||
translateFn: (expr: string) => (expr === "word" ? "mot" : expr),
|
|
||||||
});
|
|
||||||
const comp = await app.mount(fixture);
|
|
||||||
|
|
||||||
const el = comp.el as HTMLElement;
|
|
||||||
|
|
||||||
expect(el.outerHTML).toBe(
|
|
||||||
'<div><p label="mot">mot</p><p title="mot">mot</p><p placeholder="mot">mot</p><p alt="mot">mot</p><p something="word">mot</p></div>'
|
|
||||||
);
|
|
||||||
snapshotApp(app);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("can set translatable attributes", async () => {
|
|
||||||
class SomeComponent extends Component {
|
|
||||||
static template = xml`
|
|
||||||
<div tomato="word" potato="word" title="word">text</div>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
|
|
||||||
const app = new App(SomeComponent);
|
|
||||||
app.configure({
|
|
||||||
translateFn: (expr: string) => (expr === "word" ? "mot" : expr),
|
|
||||||
translatableAttributes: ["potato"],
|
|
||||||
});
|
|
||||||
const comp = await app.mount(fixture);
|
|
||||||
|
|
||||||
const el = comp.el as HTMLElement;
|
|
||||||
expect(el.outerHTML).toBe('<div tomato="word" potato="mot" title="word">text</div>');
|
|
||||||
snapshotApp(app);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("translation is done on the trimmed text, with extra spaces readded after", async () => {
|
|
||||||
class SomeComponent extends Component {
|
|
||||||
static template = xml`
|
|
||||||
<div> word </div>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
|
|
||||||
const translateFn = jest.fn((expr: string) => (expr === "word" ? "mot" : expr));
|
|
||||||
|
|
||||||
const app = new App(SomeComponent);
|
|
||||||
app.configure({ translateFn });
|
|
||||||
const comp = await app.mount(fixture);
|
|
||||||
|
|
||||||
const el = comp.el as HTMLElement;
|
|
||||||
|
|
||||||
expect(el.outerHTML).toBe("<div> mot </div>");
|
|
||||||
expect(translateFn).toHaveBeenCalledWith("word");
|
|
||||||
snapshotApp(app);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -4,7 +4,7 @@ exports[`app destroy remove the widget from the DOM 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div/>\`);
|
let block1 = createBlock(\`<div/>\`);
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ exports[`basics Multi root component 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block2 = createBlock(\`<span>1</span>\`);
|
let block2 = createBlock(\`<span>1</span>\`);
|
||||||
let block4 = createBlock(\`<span>2</span>\`);
|
let block4 = createBlock(\`<span>2</span>\`);
|
||||||
@@ -22,7 +22,7 @@ exports[`basics a class component inside a class component, no external dom 1`]
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div>simple vnode</div>\`);
|
let block1 = createBlock(\`<div>simple vnode</div>\`);
|
||||||
|
|
||||||
@@ -36,7 +36,7 @@ exports[`basics a class component inside a class component, no external dom 2`]
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
return component(\`Child\`, {}, key + \`__1\`, node, ctx);
|
return component(\`Child\`, {}, key + \`__1\`, node, ctx);
|
||||||
@@ -48,7 +48,7 @@ exports[`basics a component cannot be mounted in a detached node 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div/>\`);
|
let block1 = createBlock(\`<div/>\`);
|
||||||
|
|
||||||
@@ -62,7 +62,7 @@ exports[`basics a component inside a component 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div>simple vnode</div>\`);
|
let block1 = createBlock(\`<div>simple vnode</div>\`);
|
||||||
|
|
||||||
@@ -76,7 +76,7 @@ exports[`basics a component inside a component 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
||||||
|
|
||||||
@@ -91,14 +91,14 @@ exports[`basics can be clicked on and updated 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/><button block-handler-1=\\"click\\">Inc</button></div>\`);
|
let block1 = createBlock(\`<div><block-text-0/><button block-handler-1=\\"click\\">Inc</button></div>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let d1 = ctx['state'].counter;
|
let d1 = ctx['state'].counter;
|
||||||
const v1 = ctx['state'];
|
const v1 = ctx['state'];
|
||||||
let d2 = [()=>v1.counter++, ctx];
|
let d2 = (e) => {const res = (() => { return v1.counter++ })(); if (typeof res === 'function') { res(e) }};
|
||||||
return block1([d1, d2]);
|
return block1([d1, d2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
@@ -108,7 +108,7 @@ exports[`basics can handle empty props 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
||||||
|
|
||||||
@@ -123,7 +123,7 @@ exports[`basics can handle empty props 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
|
||||||
@@ -134,39 +134,11 @@ exports[`basics can handle empty props 2`] = `
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`basics can inject values in tagged templates 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = ctx['state'].n;
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`basics can inject values in tagged templates 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
const callTemplate_2 = getTemplate(\`__template__9\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return callTemplate_2.call(this, ctx, node, key + \`__1\`);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`basics can mount a component with just some text 1`] = `
|
exports[`basics can mount a component with just some text 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
return text(\`just text\`);
|
return text(\`just text\`);
|
||||||
@@ -178,7 +150,7 @@ exports[`basics can mount a component with no text 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
return text(\`\`);
|
return text(\`\`);
|
||||||
@@ -190,7 +162,7 @@ exports[`basics can mount a simple component 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span>simple vnode</span>\`);
|
let block1 = createBlock(\`<span>simple vnode</span>\`);
|
||||||
|
|
||||||
@@ -204,7 +176,7 @@ exports[`basics can mount a simple component with multiple roots 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block2 = createBlock(\`<span/>\`);
|
let block2 = createBlock(\`<span/>\`);
|
||||||
let block3 = createBlock(\`<div/>\`);
|
let block3 = createBlock(\`<div/>\`);
|
||||||
@@ -221,7 +193,7 @@ exports[`basics can mount a simple component with props 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
||||||
|
|
||||||
@@ -236,7 +208,7 @@ exports[`basics cannot mount on a documentFragment 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div>content</div>\`);
|
let block1 = createBlock(\`<div>content</div>\`);
|
||||||
|
|
||||||
@@ -250,7 +222,7 @@ exports[`basics child can be updated 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
return text(ctx['props'].value);
|
return text(ctx['props'].value);
|
||||||
@@ -262,7 +234,7 @@ exports[`basics child can be updated 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
return component(\`Child\`, {value: ctx['state'].counter}, key + \`__1\`, node, ctx);
|
return component(\`Child\`, {value: ctx['state'].counter}, key + \`__1\`, node, ctx);
|
||||||
@@ -274,7 +246,7 @@ exports[`basics class component with dynamic text 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span>My value: <block-text-0/></span>\`);
|
let block1 = createBlock(\`<span>My value: <block-text-0/></span>\`);
|
||||||
|
|
||||||
@@ -289,7 +261,7 @@ exports[`basics class parent, class child component with props 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
||||||
|
|
||||||
@@ -304,7 +276,7 @@ exports[`basics class parent, class child component with props 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
return component(\`Child\`, {value: 42}, key + \`__1\`, node, ctx);
|
return component(\`Child\`, {value: 42}, key + \`__1\`, node, ctx);
|
||||||
@@ -316,7 +288,7 @@ exports[`basics component with dynamic content can be updated 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
||||||
|
|
||||||
@@ -331,7 +303,7 @@ exports[`basics do not remove previously rendered dom if not necessary 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div/>\`);
|
let block1 = createBlock(\`<div/>\`);
|
||||||
|
|
||||||
@@ -345,7 +317,7 @@ exports[`basics do not remove previously rendered dom if not necessary, variatio
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><h1>h1</h1><span><block-text-0/></span></div>\`);
|
let block1 = createBlock(\`<div><h1>h1</h1><span><block-text-0/></span></div>\`);
|
||||||
|
|
||||||
@@ -360,7 +332,7 @@ exports[`basics has no el after creation 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span>simple</span>\`);
|
let block1 = createBlock(\`<span>simple</span>\`);
|
||||||
|
|
||||||
@@ -374,7 +346,7 @@ exports[`basics higher order components parent and child 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div>a</div>\`);
|
let block1 = createBlock(\`<div>a</div>\`);
|
||||||
|
|
||||||
@@ -388,7 +360,7 @@ exports[`basics higher order components parent and child 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span>b</span>\`);
|
let block1 = createBlock(\`<span>b</span>\`);
|
||||||
|
|
||||||
@@ -402,7 +374,7 @@ exports[`basics higher order components parent and child 3`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let b2,b3;
|
let b2,b3;
|
||||||
@@ -420,7 +392,7 @@ exports[`basics higher order components parent and child 4`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
return component(\`Child\`, {child: ctx['state'].child}, key + \`__1\`, node, ctx);
|
return component(\`Child\`, {child: ctx['state'].child}, key + \`__1\`, node, ctx);
|
||||||
@@ -428,50 +400,11 @@ exports[`basics higher order components parent and child 4`] = `
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`basics list of two sub components inside other nodes 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<span>asdf</span>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return block1();
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`basics list of two sub components inside other nodes 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
let block3 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
ctx = Object.create(ctx);
|
|
||||||
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['state'].blips);
|
|
||||||
for (let i1 = 0; i1 < l_block2; i1++) {
|
|
||||||
ctx[\`blip\`] = v_block2[i1];
|
|
||||||
let key1 = ctx['blip'].id;
|
|
||||||
let b4 = component(\`SubWidget\`, {}, key + \`__1__\${key1}\`, node, ctx);
|
|
||||||
let b5 = component(\`SubWidget\`, {}, key + \`__2__\${key1}\`, node, ctx);
|
|
||||||
c_block2[i1] = withKey(block3([], [b4, b5]), key1);
|
|
||||||
}
|
|
||||||
let b2 = list(c_block2);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`basics parent, child and grandchild 1`] = `
|
exports[`basics parent, child and grandchild 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div>hey</div>\`);
|
let block1 = createBlock(\`<div>hey</div>\`);
|
||||||
|
|
||||||
@@ -485,7 +418,7 @@ exports[`basics parent, child and grandchild 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
return component(\`GrandChild\`, {}, key + \`__1\`, node, ctx);
|
return component(\`GrandChild\`, {}, key + \`__1\`, node, ctx);
|
||||||
@@ -497,7 +430,7 @@ exports[`basics parent, child and grandchild 3`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
return component(\`Child\`, {}, key + \`__1\`, node, ctx);
|
return component(\`Child\`, {}, key + \`__1\`, node, ctx);
|
||||||
@@ -509,7 +442,7 @@ exports[`basics props is set on root component 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span>simple vnode</span>\`);
|
let block1 = createBlock(\`<span>simple vnode</span>\`);
|
||||||
|
|
||||||
@@ -523,7 +456,7 @@ exports[`basics reconciliation alg is not confused in some specific situation 1`
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span>child</span>\`);
|
let block1 = createBlock(\`<span>child</span>\`);
|
||||||
|
|
||||||
@@ -537,53 +470,23 @@ exports[`basics reconciliation alg is not confused in some specific situation 2`
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let b2 = component(\`Child\`, {}, key + \`__1\`, node, ctx);
|
let b2 = component(\`Child\`, {}, key + \`__1\`, node, ctx);
|
||||||
const tKey_2 = 4;
|
let b3 = component(\`Child\`, {}, key + \`__2\`, node, ctx);
|
||||||
let b3 = toggler(tKey_2, component(\`Child\`, {}, tKey_2 + key + \`__3\`, node, ctx));
|
|
||||||
return block1([], [b2, b3]);
|
return block1([], [b2, b3]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`basics rerendering a widget with a sub widget 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/><button block-handler-1=\\"click\\">Inc</button></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = ctx['state'].counter;
|
|
||||||
const v1 = ctx['state'];
|
|
||||||
let d2 = [()=>v1.counter++, ctx];
|
|
||||||
return block1([d1, d2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`basics rerendering a widget with a sub widget 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return component(\`Counter\`, {}, key + \`__1\`, node, ctx);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`basics same t-keys in two different places 1`] = `
|
exports[`basics same t-keys in two different places 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
||||||
|
|
||||||
@@ -598,15 +501,13 @@ exports[`basics same t-keys in two different places 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><div><block-child-0/></div><div><block-child-1/></div></div>\`);
|
let block1 = createBlock(\`<div><div><block-child-0/></div><div><block-child-1/></div></div>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
const tKey_1 = 1;
|
let b2 = component(\`Child\`, {blip: '1'}, key + \`__1\`, node, ctx);
|
||||||
let b2 = toggler(tKey_1, component(\`Child\`, {blip: '1'}, tKey_1 + key + \`__2\`, node, ctx));
|
let b3 = component(\`Child\`, {blip: '2'}, key + \`__2\`, node, ctx);
|
||||||
const tKey_3 = 1;
|
|
||||||
let b3 = toggler(tKey_3, component(\`Child\`, {blip: '2'}, tKey_3 + key + \`__4\`, node, ctx));
|
|
||||||
return block1([], [b2, b3]);
|
return block1([], [b2, b3]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
@@ -616,7 +517,7 @@ exports[`basics simple component with a dynamic text 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
||||||
|
|
||||||
@@ -631,7 +532,7 @@ exports[`basics simple component, useState 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
||||||
|
|
||||||
@@ -646,7 +547,7 @@ exports[`basics some simple sanity checks (el/status) 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span>simple vnode</span>\`);
|
let block1 = createBlock(\`<span>simple vnode</span>\`);
|
||||||
|
|
||||||
@@ -656,52 +557,11 @@ exports[`basics some simple sanity checks (el/status) 1`] = `
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`basics sub components between t-ifs 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<span>child</span>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return block1();
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`basics sub components between t-ifs 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><block-child-1/><span><block-child-2/></span><block-child-3/></div>\`);
|
|
||||||
let block2 = createBlock(\`<h1>hey</h1>\`);
|
|
||||||
let block3 = createBlock(\`<h2>noo</h2>\`);
|
|
||||||
let block5 = createBlock(\`<span>test</span>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2,b3,b4,b5;
|
|
||||||
if (ctx['state'].flag) {
|
|
||||||
b2 = block2();
|
|
||||||
} else {
|
|
||||||
b3 = block3();
|
|
||||||
}
|
|
||||||
b4 = component(\`Child\`, {}, key + \`__1\`, node, ctx);
|
|
||||||
if (ctx['state'].flag) {
|
|
||||||
b5 = block5();
|
|
||||||
}
|
|
||||||
return block1([], [b2, b3, b4, b5]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`basics t-elif works with t-component 1`] = `
|
exports[`basics t-elif works with t-component 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span>hey</span>\`);
|
let block1 = createBlock(\`<span>hey</span>\`);
|
||||||
|
|
||||||
@@ -715,7 +575,7 @@ exports[`basics t-elif works with t-component 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
|
||||||
let block2 = createBlock(\`<div>somediv</div>\`);
|
let block2 = createBlock(\`<div>somediv</div>\`);
|
||||||
@@ -736,7 +596,7 @@ exports[`basics t-else with empty string works with t-component 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span>hey</span>\`);
|
let block1 = createBlock(\`<span>hey</span>\`);
|
||||||
|
|
||||||
@@ -750,7 +610,7 @@ exports[`basics t-else with empty string works with t-component 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
|
||||||
let block2 = createBlock(\`<div>somediv</div>\`);
|
let block2 = createBlock(\`<div>somediv</div>\`);
|
||||||
@@ -771,7 +631,7 @@ exports[`basics t-else works with t-component 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span>hey</span>\`);
|
let block1 = createBlock(\`<span>hey</span>\`);
|
||||||
|
|
||||||
@@ -785,7 +645,7 @@ exports[`basics t-else works with t-component 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
|
||||||
let block2 = createBlock(\`<div>somediv</div>\`);
|
let block2 = createBlock(\`<div>somediv</div>\`);
|
||||||
@@ -806,7 +666,7 @@ exports[`basics t-if works with t-component 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span>hey</span>\`);
|
let block1 = createBlock(\`<span>hey</span>\`);
|
||||||
|
|
||||||
@@ -820,7 +680,7 @@ exports[`basics t-if works with t-component 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
|
||||||
@@ -838,7 +698,7 @@ exports[`basics t-key on a component with t-if, and a sibling component 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span>child</span>\`);
|
let block1 = createBlock(\`<span>child</span>\`);
|
||||||
|
|
||||||
@@ -852,17 +712,16 @@ exports[`basics t-key on a component with t-if, and a sibling component 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><block-child-0/><block-child-1/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let b2,b3;
|
let b2,b3;
|
||||||
if (false) {
|
if (false) {
|
||||||
const tKey_1 = 'str';
|
b2 = component(\`Child\`, {}, key + \`__1\`, node, ctx);
|
||||||
b2 = toggler(tKey_1, component(\`Child\`, {}, tKey_1 + key + \`__2\`, node, ctx));
|
|
||||||
}
|
}
|
||||||
b3 = component(\`Child\`, {}, key + \`__3\`, node, ctx);
|
b3 = component(\`Child\`, {}, key + \`__2\`, node, ctx);
|
||||||
return block1([], [b2, b3]);
|
return block1([], [b2, b3]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
@@ -872,7 +731,7 @@ exports[`basics text after a conditional component 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<p>simple vnode</p>\`);
|
let block1 = createBlock(\`<p>simple vnode</p>\`);
|
||||||
|
|
||||||
@@ -886,7 +745,7 @@ exports[`basics text after a conditional component 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><span><block-text-0/></span></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/><span><block-text-0/></span></div>\`);
|
||||||
|
|
||||||
@@ -905,7 +764,7 @@ exports[`basics three level of components with collapsing root nodes 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div>2</div>\`);
|
let block1 = createBlock(\`<div>2</div>\`);
|
||||||
|
|
||||||
@@ -919,7 +778,7 @@ exports[`basics three level of components with collapsing root nodes 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
return component(\`GrandChild\`, {}, key + \`__1\`, node, ctx);
|
return component(\`GrandChild\`, {}, key + \`__1\`, node, ctx);
|
||||||
@@ -931,7 +790,7 @@ exports[`basics three level of components with collapsing root nodes 3`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
return component(\`Child\`, {}, key + \`__1\`, node, ctx);
|
return component(\`Child\`, {}, key + \`__1\`, node, ctx);
|
||||||
@@ -943,7 +802,7 @@ exports[`basics throws if mounting on target=null 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span>simple vnode</span>\`);
|
let block1 = createBlock(\`<span>simple vnode</span>\`);
|
||||||
|
|
||||||
@@ -957,7 +816,7 @@ exports[`basics two child components 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div>simple vnode</div>\`);
|
let block1 = createBlock(\`<div>simple vnode</div>\`);
|
||||||
|
|
||||||
@@ -971,7 +830,7 @@ exports[`basics two child components 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let b2 = component(\`Child\`, {}, key + \`__1\`, node, ctx);
|
let b2 = component(\`Child\`, {}, key + \`__1\`, node, ctx);
|
||||||
@@ -981,96 +840,21 @@ exports[`basics two child components 2`] = `
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`basics update props of component without concrete own node 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div class=\\"widget-subkey\\"><block-text-0/>__<block-text-1/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = ctx['props'].key;
|
|
||||||
let d2 = ctx['props'].subKey;
|
|
||||||
return block1([d1, d2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`basics update props of component without concrete own node 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const tKey_1 = ctx['props'].subKey;
|
|
||||||
return toggler(tKey_1, component(\`Custom\`, {key: ctx['props'].key,subKey: ctx['props'].subKey}, tKey_1 + key + \`__2\`, node, ctx));
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`basics update props of component without concrete own node 3`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const tKey_1 = ctx['childProps'].key;
|
|
||||||
let b2 = toggler(tKey_1, component(\`Child\`, ctx['childProps'], tKey_1 + key + \`__2\`, node, ctx));
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`basics updating a component with t-foreach as root 1`] = `
|
exports[`basics updating a component with t-foreach as root 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
ctx = Object.create(ctx);
|
ctx = Object.create(ctx);
|
||||||
const [k_block1, v_block1, l_block1, c_block1] = prepareList(ctx['items']);
|
const [k1, v1, l1, c1] = prepareList(ctx['items']);
|
||||||
for (let i1 = 0; i1 < l_block1; i1++) {
|
for (let i1 = 0; i1 < l1; i1++) {
|
||||||
ctx[\`item\`] = v_block1[i1];
|
ctx[\`item\`] = v1[i1];
|
||||||
let key1 = ctx['item'];
|
let key1 = ctx['item'];
|
||||||
c_block1[i1] = withKey(text(ctx['item']), key1);
|
c1[i1] = withKey(text(ctx['item']), key1);
|
||||||
}
|
}
|
||||||
return list(c_block1);
|
return list(c1);
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`basics updating widget immediately 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<span>abc<block-child-0/></span>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2;
|
|
||||||
if (ctx['props'].flag) {
|
|
||||||
b2 = text(\`def\`);
|
|
||||||
}
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`basics updating widget immediately 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return component(\`Child\`, {flag: ctx['state'].flag}, key + \`__1\`, node, ctx);
|
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
@@ -1079,7 +863,7 @@ exports[`basics widget after a t-foreach 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div/>\`);
|
let block1 = createBlock(\`<div/>\`);
|
||||||
|
|
||||||
@@ -1093,21 +877,21 @@ exports[`basics widget after a t-foreach 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
ctx = Object.create(ctx);
|
ctx = Object.create(ctx);
|
||||||
const [k_block2, v_block2, l_block2, c_block2] = prepareList(Array(2));
|
const [k2, v2, l2, c2] = prepareList(Array(2));
|
||||||
for (let i1 = 0; i1 < l_block2; i1++) {
|
for (let i1 = 0; i1 < l2; i1++) {
|
||||||
ctx[\`elem\`] = v_block2[i1];
|
ctx[\`elem\`] = v2[i1];
|
||||||
ctx[\`elem_index\`] = i1;
|
ctx[\`elem_index\`] = i1;
|
||||||
let key1 = ctx['elem_index'];
|
let key1 = ctx['elem_index'];
|
||||||
c_block2[i1] = withKey(text(\`txt\`), key1);
|
c2[i1] = withKey(text(\`txt\`), key1);
|
||||||
}
|
}
|
||||||
ctx = ctx.__proto__;
|
ctx = ctx.__proto__;
|
||||||
let b2 = list(c_block2);
|
let b2 = list(c2);
|
||||||
let b4 = component(\`SomeComponent\`, {}, key + \`__1\`, node, ctx);
|
let b4 = component(\`SomeComponent\`, {}, key + \`__1\`, node, ctx);
|
||||||
return block1([], [b2, b4]);
|
return block1([], [b2, b4]);
|
||||||
}
|
}
|
||||||
@@ -1118,7 +902,7 @@ exports[`basics zero or one child components 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div>simple vnode</div>\`);
|
let block1 = createBlock(\`<div>simple vnode</div>\`);
|
||||||
|
|
||||||
@@ -1132,7 +916,7 @@ exports[`basics zero or one child components 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let b2;
|
let b2;
|
||||||
@@ -1143,113 +927,3 @@ exports[`basics zero or one child components 2`] = `
|
|||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`mount targets can mount a component (with default position='last-child') 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div>app</div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return block1();
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`mount targets can mount a component (with position='first-child') 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div>app</div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return block1();
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`mount targets default mount option is 'last-child' 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div>app</div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return block1();
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`support svg components add proper namespace to svg 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<g block-ns=\\"http://www.w3.org/2000/svg\\"><circle cx=\\"50\\" cy=\\"50\\" r=\\"4\\" stroke=\\"green\\" stroke-width=\\"1\\" fill=\\"yellow\\"/></g>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return block1();
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`support svg components add proper namespace to svg 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<svg block-ns=\\"http://www.w3.org/2000/svg\\"><block-child-0/></svg>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2 = component(\`GComp\`, {}, key + \`__1\`, node, ctx);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-out in components can render list of t-out 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = 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['state'].items);
|
|
||||||
for (let i1 = 0; i1 < l_block2; i1++) {
|
|
||||||
ctx[\`item\`] = v_block2[i1];
|
|
||||||
let key1 = ctx['item'];
|
|
||||||
let b4 = text(ctx['item']);
|
|
||||||
let b5 = safeOutput(ctx['item']);
|
|
||||||
c_block2[i1] = withKey(multi([b4, b5]), key1);
|
|
||||||
}
|
|
||||||
let b2 = list(c_block2);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-out in components update properly on state changes 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2 = safeOutput(ctx['state'].value);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ exports[`async rendering destroying a widget before start is over 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div/>\`);
|
let block1 = createBlock(\`<div/>\`);
|
||||||
|
|
||||||
@@ -14,51 +14,11 @@ exports[`async rendering destroying a widget before start is over 1`] = `
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`calling render in destroy 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = ctx['props'].fromA;
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`calling render in destroy 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return component(\`C\`, {fromA: ctx['props'].fromA}, key + \`__1\`, node, ctx);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`calling render in destroy 3`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const tKey_1 = ctx['key'];
|
|
||||||
return toggler(tKey_1, component(\`B\`, {fromA: ctx['state']}, tKey_1 + key + \`__2\`, node, ctx));
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`change state and call manually render: no unnecessary rendering 1`] = `
|
exports[`change state and call manually render: no unnecessary rendering 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
||||||
|
|
||||||
@@ -73,7 +33,7 @@ exports[`changing state before first render does not trigger a render (with pare
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
||||||
|
|
||||||
@@ -88,7 +48,7 @@ exports[`changing state before first render does not trigger a render (with pare
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
|
||||||
@@ -106,7 +66,7 @@ exports[`changing state before first render does not trigger a render 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
||||||
|
|
||||||
@@ -121,7 +81,7 @@ exports[`concurrent renderings scenario 1 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-text-0/><block-text-1/></span>\`);
|
let block1 = createBlock(\`<span><block-text-0/><block-text-1/></span>\`);
|
||||||
|
|
||||||
@@ -137,7 +97,7 @@ exports[`concurrent renderings scenario 1 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<p><block-child-0/></p>\`);
|
let block1 = createBlock(\`<p><block-child-0/></p>\`);
|
||||||
|
|
||||||
@@ -152,7 +112,7 @@ exports[`concurrent renderings scenario 1 3`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
|
||||||
@@ -167,7 +127,7 @@ exports[`concurrent renderings scenario 2 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-text-0/><block-text-1/></span>\`);
|
let block1 = createBlock(\`<span><block-text-0/><block-text-1/></span>\`);
|
||||||
|
|
||||||
@@ -183,7 +143,7 @@ exports[`concurrent renderings scenario 2 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<p><block-child-0/></p>\`);
|
let block1 = createBlock(\`<p><block-child-0/></p>\`);
|
||||||
|
|
||||||
@@ -198,7 +158,7 @@ exports[`concurrent renderings scenario 2 3`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-text-0/><block-child-0/></div>\`);
|
||||||
|
|
||||||
@@ -214,7 +174,7 @@ exports[`concurrent renderings scenario 2bis 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-text-0/><block-text-1/></span>\`);
|
let block1 = createBlock(\`<span><block-text-0/><block-text-1/></span>\`);
|
||||||
|
|
||||||
@@ -230,7 +190,7 @@ exports[`concurrent renderings scenario 2bis 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<p><block-child-0/></p>\`);
|
let block1 = createBlock(\`<p><block-child-0/></p>\`);
|
||||||
|
|
||||||
@@ -245,7 +205,7 @@ exports[`concurrent renderings scenario 2bis 3`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
|
||||||
@@ -260,7 +220,7 @@ exports[`concurrent renderings scenario 3 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<i><block-text-0/><block-text-1/></i>\`);
|
let block1 = createBlock(\`<i><block-text-0/><block-text-1/></i>\`);
|
||||||
|
|
||||||
@@ -276,7 +236,7 @@ exports[`concurrent renderings scenario 3 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
||||||
|
|
||||||
@@ -291,7 +251,7 @@ exports[`concurrent renderings scenario 3 3`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<p><block-child-0/></p>\`);
|
let block1 = createBlock(\`<p><block-child-0/></p>\`);
|
||||||
|
|
||||||
@@ -306,7 +266,7 @@ exports[`concurrent renderings scenario 3 4`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
|
||||||
@@ -321,7 +281,7 @@ exports[`concurrent renderings scenario 4 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<i><block-text-0/><block-text-1/></i>\`);
|
let block1 = createBlock(\`<i><block-text-0/><block-text-1/></i>\`);
|
||||||
|
|
||||||
@@ -337,7 +297,7 @@ exports[`concurrent renderings scenario 4 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
||||||
|
|
||||||
@@ -352,7 +312,7 @@ exports[`concurrent renderings scenario 4 3`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<p><block-child-0/></p>\`);
|
let block1 = createBlock(\`<p><block-child-0/></p>\`);
|
||||||
|
|
||||||
@@ -367,7 +327,7 @@ exports[`concurrent renderings scenario 4 4`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
|
||||||
@@ -382,7 +342,7 @@ exports[`concurrent renderings scenario 5 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<p><block-text-0/></p>\`);
|
let block1 = createBlock(\`<p><block-text-0/></p>\`);
|
||||||
|
|
||||||
@@ -397,7 +357,7 @@ exports[`concurrent renderings scenario 5 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
|
||||||
@@ -412,7 +372,7 @@ exports[`concurrent renderings scenario 6 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<p><block-text-0/></p>\`);
|
let block1 = createBlock(\`<p><block-text-0/></p>\`);
|
||||||
|
|
||||||
@@ -427,7 +387,7 @@ exports[`concurrent renderings scenario 6 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
|
||||||
@@ -442,7 +402,7 @@ exports[`concurrent renderings scenario 7 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<p><block-text-0/><block-text-1/></p>\`);
|
let block1 = createBlock(\`<p><block-text-0/><block-text-1/></p>\`);
|
||||||
|
|
||||||
@@ -458,7 +418,7 @@ exports[`concurrent renderings scenario 7 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
|
||||||
@@ -473,7 +433,7 @@ exports[`concurrent renderings scenario 8 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<p><block-text-0/><block-text-1/></p>\`);
|
let block1 = createBlock(\`<p><block-text-0/><block-text-1/></p>\`);
|
||||||
|
|
||||||
@@ -489,7 +449,7 @@ exports[`concurrent renderings scenario 8 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
|
||||||
@@ -504,7 +464,7 @@ exports[`concurrent renderings scenario 9 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-text-0/><block-text-1/></span>\`);
|
let block1 = createBlock(\`<span><block-text-0/><block-text-1/></span>\`);
|
||||||
|
|
||||||
@@ -520,7 +480,7 @@ exports[`concurrent renderings scenario 9 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<p><block-child-0/></p>\`);
|
let block1 = createBlock(\`<p><block-child-0/></p>\`);
|
||||||
|
|
||||||
@@ -535,7 +495,7 @@ exports[`concurrent renderings scenario 9 3`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<b><block-text-0/></b>\`);
|
let block1 = createBlock(\`<b><block-text-0/></b>\`);
|
||||||
|
|
||||||
@@ -550,7 +510,7 @@ exports[`concurrent renderings scenario 9 4`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/><block-child-0/><block-child-1/></div>\`);
|
let block1 = createBlock(\`<div><block-text-0/><block-child-0/><block-child-1/></div>\`);
|
||||||
|
|
||||||
@@ -567,7 +527,7 @@ exports[`concurrent renderings scenario 10 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
||||||
|
|
||||||
@@ -582,7 +542,7 @@ exports[`concurrent renderings scenario 10 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<p><block-child-0/></p>\`);
|
let block1 = createBlock(\`<p><block-child-0/></p>\`);
|
||||||
|
|
||||||
@@ -600,7 +560,7 @@ exports[`concurrent renderings scenario 10 3`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
|
||||||
@@ -615,7 +575,7 @@ exports[`concurrent renderings scenario 11 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-text-0/>|<block-text-1/></span>\`);
|
let block1 = createBlock(\`<span><block-text-0/>|<block-text-1/></span>\`);
|
||||||
|
|
||||||
@@ -631,7 +591,7 @@ exports[`concurrent renderings scenario 11 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
|
||||||
@@ -646,7 +606,7 @@ exports[`concurrent renderings scenario 12 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
||||||
|
|
||||||
@@ -661,7 +621,7 @@ exports[`concurrent renderings scenario 12 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
|
||||||
@@ -676,7 +636,7 @@ exports[`concurrent renderings scenario 13 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
||||||
|
|
||||||
@@ -691,7 +651,7 @@ exports[`concurrent renderings scenario 13 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
|
||||||
|
|
||||||
@@ -710,7 +670,7 @@ exports[`concurrent renderings scenario 14 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<p><span><block-text-0/></span><span><block-text-1/></span><span><block-text-2/></span></p>\`);
|
let block1 = createBlock(\`<p><span><block-text-0/></span><span><block-text-1/></span><span><block-text-2/></span></p>\`);
|
||||||
|
|
||||||
@@ -727,7 +687,7 @@ exports[`concurrent renderings scenario 14 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<p><block-child-0/></p>\`);
|
let block1 = createBlock(\`<p><block-child-0/></p>\`);
|
||||||
|
|
||||||
@@ -742,7 +702,7 @@ exports[`concurrent renderings scenario 14 3`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<p><block-child-0/></p>\`);
|
let block1 = createBlock(\`<p><block-child-0/></p>\`);
|
||||||
|
|
||||||
@@ -757,7 +717,7 @@ exports[`concurrent renderings scenario 15 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<p><span><block-text-0/></span><span><block-text-1/></span><span><block-text-2/></span></p>\`);
|
let block1 = createBlock(\`<p><span><block-text-0/></span><span><block-text-1/></span><span><block-text-2/></span></p>\`);
|
||||||
|
|
||||||
@@ -774,7 +734,7 @@ exports[`concurrent renderings scenario 15 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<p><block-child-0/></p>\`);
|
let block1 = createBlock(\`<p><block-child-0/></p>\`);
|
||||||
|
|
||||||
@@ -789,7 +749,7 @@ exports[`concurrent renderings scenario 15 3`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<p><block-child-0/></p>\`);
|
let block1 = createBlock(\`<p><block-child-0/></p>\`);
|
||||||
|
|
||||||
@@ -804,7 +764,7 @@ exports[`concurrent renderings scenario 16 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<ul>DDD</ul>\`);
|
let block1 = createBlock(\`<ul>DDD</ul>\`);
|
||||||
|
|
||||||
@@ -818,7 +778,7 @@ exports[`concurrent renderings scenario 16 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<p><span><block-text-0/></span><span><block-text-1/></span><span><block-text-2/></span><block-child-0/></p>\`);
|
let block1 = createBlock(\`<p><span><block-text-0/></span><span><block-text-1/></span><span><block-text-2/></span><block-child-0/></p>\`);
|
||||||
|
|
||||||
@@ -839,7 +799,7 @@ exports[`concurrent renderings scenario 16 3`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<p><block-child-0/></p>\`);
|
let block1 = createBlock(\`<p><block-child-0/></p>\`);
|
||||||
|
|
||||||
@@ -854,7 +814,7 @@ exports[`concurrent renderings scenario 16 4`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<p><block-child-0/></p>\`);
|
let block1 = createBlock(\`<p><block-child-0/></p>\`);
|
||||||
|
|
||||||
@@ -869,7 +829,7 @@ exports[`creating two async components, scenario 1 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
||||||
|
|
||||||
@@ -884,7 +844,7 @@ exports[`creating two async components, scenario 1 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span>b</span>\`);
|
let block1 = createBlock(\`<span>b</span>\`);
|
||||||
|
|
||||||
@@ -898,7 +858,7 @@ exports[`creating two async components, scenario 1 3`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let b2,b3;
|
let b2,b3;
|
||||||
@@ -917,7 +877,7 @@ exports[`creating two async components, scenario 2 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span>a<block-text-0/></span>\`);
|
let block1 = createBlock(\`<span>a<block-text-0/></span>\`);
|
||||||
|
|
||||||
@@ -932,7 +892,7 @@ exports[`creating two async components, scenario 2 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span>b<block-text-0/></span>\`);
|
let block1 = createBlock(\`<span>b<block-text-0/></span>\`);
|
||||||
|
|
||||||
@@ -947,7 +907,7 @@ exports[`creating two async components, scenario 2 3`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
|
||||||
|
|
||||||
@@ -966,7 +926,7 @@ exports[`creating two async components, scenario 3 (patching in the same frame)
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span>a<block-text-0/></span>\`);
|
let block1 = createBlock(\`<span>a<block-text-0/></span>\`);
|
||||||
|
|
||||||
@@ -981,7 +941,7 @@ exports[`creating two async components, scenario 3 (patching in the same frame)
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span>b<block-text-0/></span>\`);
|
let block1 = createBlock(\`<span>b<block-text-0/></span>\`);
|
||||||
|
|
||||||
@@ -996,7 +956,7 @@ exports[`creating two async components, scenario 3 (patching in the same frame)
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
|
||||||
|
|
||||||
@@ -1015,7 +975,7 @@ exports[`destroying/recreating a subwidget with different props (if start is not
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span>child:<block-text-0/></span>\`);
|
let block1 = createBlock(\`<span>child:<block-text-0/></span>\`);
|
||||||
|
|
||||||
@@ -1030,7 +990,7 @@ exports[`destroying/recreating a subwidget with different props (if start is not
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
|
||||||
@@ -1044,35 +1004,11 @@ exports[`destroying/recreating a subwidget with different props (if start is not
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`parent and child rendered at exact same time 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return text(ctx['props'].value);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`parent and child rendered at exact same time 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return component(\`Child\`, {value: ctx['state'].value}, key + \`__1\`, node, ctx);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`properly behave when destroyed/unmounted while rendering 1`] = `
|
exports[`properly behave when destroyed/unmounted while rendering 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div/>\`);
|
let block1 = createBlock(\`<div/>\`);
|
||||||
|
|
||||||
@@ -1086,7 +1022,7 @@ exports[`properly behave when destroyed/unmounted while rendering 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
|
||||||
@@ -1101,7 +1037,7 @@ exports[`properly behave when destroyed/unmounted while rendering 3`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
|
||||||
@@ -1119,7 +1055,7 @@ exports[`render method wait until rendering is done 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
||||||
|
|
||||||
@@ -1134,7 +1070,7 @@ exports[`rendering component again in next microtick 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div>Child</div>\`);
|
let block1 = createBlock(\`<div>Child</div>\`);
|
||||||
|
|
||||||
@@ -1148,14 +1084,14 @@ exports[`rendering component again in next microtick 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><button block-handler-0=\\"click\\">Click</button><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><button block-handler-0=\\"click\\">Click</button><block-child-0/></div>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let b2;
|
let b2;
|
||||||
let d1 = [ctx['onClick'], ctx];
|
let d1 = [ctx, 'onClick'];
|
||||||
if (ctx['env'].config.flag) {
|
if (ctx['env'].flag) {
|
||||||
b2 = component(\`Child\`, {}, key + \`__1\`, node, ctx);
|
b2 = component(\`Child\`, {}, key + \`__1\`, node, ctx);
|
||||||
}
|
}
|
||||||
return block1([d1], [b2]);
|
return block1([d1], [b2]);
|
||||||
@@ -1167,7 +1103,7 @@ exports[`two renderings initiated between willPatch and patched 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<abc><block-text-0/></abc>\`);
|
let block1 = createBlock(\`<abc><block-text-0/></abc>\`);
|
||||||
|
|
||||||
@@ -1182,15 +1118,14 @@ exports[`two renderings initiated between willPatch and patched 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let b2;
|
let b2;
|
||||||
if (ctx['state'].flag) {
|
if (ctx['state'].flag) {
|
||||||
const tKey_1 = 'panel_'+ctx['state'].panel;
|
b2 = component(\`Panel\`, {val: ctx['state'].panel}, key + \`__1\`, node, ctx);
|
||||||
b2 = toggler(tKey_1, component(\`Panel\`, {val: ctx['state'].panel}, tKey_1 + key + \`__2\`, node, ctx));
|
|
||||||
}
|
}
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
}
|
}
|
||||||
@@ -1201,7 +1136,7 @@ exports[`update a sub-component twice in the same frame 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
||||||
|
|
||||||
@@ -1216,7 +1151,7 @@ exports[`update a sub-component twice in the same frame 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
|
||||||
@@ -1231,7 +1166,7 @@ exports[`update a sub-component twice in the same frame, 2 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
||||||
|
|
||||||
@@ -1246,7 +1181,7 @@ exports[`update a sub-component twice in the same frame, 2 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
|
||||||
|
|||||||
@@ -1,22 +1,10 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`basics display a nice error if it cannot find component 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return component(\`SomeMispelledComponent\`, {}, key + \`__1\`, node, ctx);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`basics no component catching error lead to full app destruction 1`] = `
|
exports[`basics no component catching error lead to full app destruction 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div>hey<block-text-0/></div>\`);
|
let block1 = createBlock(\`<div>hey<block-text-0/></div>\`);
|
||||||
|
|
||||||
@@ -31,7 +19,7 @@ exports[`basics no component catching error lead to full app destruction 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
|
||||||
@@ -41,756 +29,3 @@ exports[`basics no component catching error lead to full app destruction 2`] = `
|
|||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`basics simple catchError 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = ctx['a'].b.c;
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`basics simple catchError 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2,b3;
|
|
||||||
if (ctx['error']) {
|
|
||||||
b2 = text(\`Error\`);
|
|
||||||
} else {
|
|
||||||
b3 = component(\`Boom\`, {}, key + \`__1\`, node, ctx);
|
|
||||||
}
|
|
||||||
return block1([], [b2, b3]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`can catch errors can catch an error in a component render function 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div>hey<block-text-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = ctx['props'].flag&&ctx['state'].this.will.crash;
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`can catch errors can catch an error in a component render function 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><block-child-1/><block-child-1/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2,b3;
|
|
||||||
if (ctx['state'].error) {
|
|
||||||
b2 = text(\`Error handled\`);
|
|
||||||
} else {
|
|
||||||
b3 = callSlot(ctx, node, key, 'default', false, {});
|
|
||||||
}
|
|
||||||
return block1([], [b2, b3]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`can catch errors can catch an error in a component render function 3`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
function slot1(ctx, node, key) {
|
|
||||||
return component(\`ErrorComponent\`, {flag: ctx['state'].flag}, key + \`__2\`, node, ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b3 = component(\`ErrorBoundary\`, {slots: {'default': {__render: slot1, __ctx: ctx}}}, key + \`__3\`, node, ctx);
|
|
||||||
return block1([], [b3]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`can catch errors can catch an error in the constructor call of a component render function 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div>Some text</div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return block1();
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`can catch errors can catch an error in the constructor call of a component render function 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><block-child-1/><block-child-1/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2,b3;
|
|
||||||
if (ctx['state'].error) {
|
|
||||||
b2 = text(\`Error handled\`);
|
|
||||||
} else {
|
|
||||||
b3 = callSlot(ctx, node, key, 'default', false, {});
|
|
||||||
}
|
|
||||||
return block1([], [b2, b3]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`can catch errors can catch an error in the constructor call of a component render function 2 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div>classic</div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return block1();
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`can catch errors can catch an error in the constructor call of a component render function 2 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div>Some text</div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return block1();
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`can catch errors can catch an error in the constructor call of a component render function 2 3`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><block-child-1/><block-child-1/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2,b3;
|
|
||||||
if (ctx['state'].error) {
|
|
||||||
b2 = text(\`Error handled\`);
|
|
||||||
} else {
|
|
||||||
b3 = callSlot(ctx, node, key, 'default', false, {});
|
|
||||||
}
|
|
||||||
return block1([], [b2, b3]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`can catch errors can catch an error in the constructor call of a component render function 2 4`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
function slot1(ctx, node, key) {
|
|
||||||
let b3 = component(\`ClassicCompoent\`, {}, key + \`__2\`, node, ctx);
|
|
||||||
let b4 = component(\`ErrorComponent\`, {}, key + \`__3\`, node, ctx);
|
|
||||||
return multi([b3, b4]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b5 = component(\`ErrorBoundary\`, {slots: {'default': {__render: slot1, __ctx: ctx}}}, key + \`__4\`, node, ctx);
|
|
||||||
return block1([], [b5]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`can catch errors can catch an error in the constructor call of a component render function 3`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
function slot1(ctx, node, key) {
|
|
||||||
return component(\`ErrorComponent\`, {}, key + \`__2\`, node, ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b3 = component(\`ErrorBoundary\`, {slots: {'default': {__render: slot1, __ctx: ctx}}}, key + \`__3\`, node, ctx);
|
|
||||||
return block1([], [b3]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`can catch errors can catch an error in the initial call of a component render function (parent mounted) 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div>hey<block-text-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = ctx['state'].this.will.crash;
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`can catch errors can catch an error in the initial call of a component render function (parent mounted) 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><block-child-1/><block-child-1/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2,b3;
|
|
||||||
if (ctx['state'].error) {
|
|
||||||
b2 = text(\`Error handled\`);
|
|
||||||
} else {
|
|
||||||
b3 = callSlot(ctx, node, key, 'default', false, {});
|
|
||||||
}
|
|
||||||
return block1([], [b2, b3]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`can catch errors can catch an error in the initial call of a component render function (parent mounted) 3`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
function slot1(ctx, node, key) {
|
|
||||||
return component(\`ErrorComponent\`, {}, key + \`__2\`, node, ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b3 = component(\`ErrorBoundary\`, {slots: {'default': {__render: slot1, __ctx: ctx}}}, key + \`__3\`, node, ctx);
|
|
||||||
return block1([], [b3]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`can catch errors can catch an error in the initial call of a component render function (parent updated) 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div>hey<block-text-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = ctx['state'].this.will.crash;
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`can catch errors can catch an error in the initial call of a component render function (parent updated) 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><block-child-1/><block-child-1/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2,b3;
|
|
||||||
if (ctx['state'].error) {
|
|
||||||
b2 = text(\`Error handled\`);
|
|
||||||
} else {
|
|
||||||
b3 = callSlot(ctx, node, key, 'default', false, {});
|
|
||||||
}
|
|
||||||
return block1([], [b2, b3]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`can catch errors can catch an error in the initial call of a component render function (parent updated) 3`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
function slot1(ctx, node, key) {
|
|
||||||
return component(\`ErrorComponent\`, {}, key + \`__2\`, node, ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b3;
|
|
||||||
if (ctx['state'].flag) {
|
|
||||||
b3 = component(\`ErrorBoundary\`, {slots: {'default': {__render: slot1, __ctx: ctx}}}, key + \`__3\`, node, ctx);
|
|
||||||
}
|
|
||||||
return block1([], [b3]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`can catch errors can catch an error in the mounted call 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div>Some text</div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return block1();
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`can catch errors can catch an error in the mounted call 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><block-child-1/><block-child-1/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2,b3;
|
|
||||||
if (ctx['state'].error) {
|
|
||||||
b2 = text(\`Error handled\`);
|
|
||||||
} else {
|
|
||||||
b3 = callSlot(ctx, node, key, 'default', false, {});
|
|
||||||
}
|
|
||||||
return block1([], [b2, b3]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`can catch errors can catch an error in the mounted call 3`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
function slot1(ctx, node, key) {
|
|
||||||
return component(\`ErrorComponent\`, {}, key + \`__2\`, node, ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b3 = component(\`ErrorBoundary\`, {slots: {'default': {__render: slot1, __ctx: ctx}}}, key + \`__3\`, node, ctx);
|
|
||||||
return block1([], [b3]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`can catch errors can catch an error in the willPatch call 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = ctx['props'].message;
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`can catch errors can catch an error in the willPatch call 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><block-child-1/><block-child-1/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2,b3;
|
|
||||||
if (ctx['state'].error) {
|
|
||||||
b2 = text(\`Error handled\`);
|
|
||||||
} else {
|
|
||||||
b3 = callSlot(ctx, node, key, 'default', false, {});
|
|
||||||
}
|
|
||||||
return block1([], [b2, b3]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`can catch errors can catch an error in the willPatch call 3`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><span><block-text-0/></span><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
function slot1(ctx, node, key) {
|
|
||||||
return component(\`ErrorComponent\`, {message: ctx['state'].message}, key + \`__2\`, node, ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = ctx['state'].message;
|
|
||||||
let b3 = component(\`ErrorBoundary\`, {slots: {'default': {__render: slot1, __ctx: ctx}}}, key + \`__3\`, node, ctx);
|
|
||||||
return block1([d1], [b3]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`can catch errors can catch an error in the willStart call 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div>Some text</div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return block1();
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`can catch errors can catch an error in the willStart call 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><block-child-1/><block-child-1/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2,b3;
|
|
||||||
if (ctx['state'].error) {
|
|
||||||
b2 = text(\`Error handled\`);
|
|
||||||
} else {
|
|
||||||
b3 = callSlot(ctx, node, key, 'default', false, {});
|
|
||||||
}
|
|
||||||
return block1([], [b2, b3]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`can catch errors can catch an error in the willStart call 3`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
function slot1(ctx, node, key) {
|
|
||||||
return component(\`ErrorComponent\`, {}, key + \`__2\`, node, ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b3 = component(\`ErrorBoundary\`, {slots: {'default': {__render: slot1, __ctx: ctx}}}, key + \`__3\`, node, ctx);
|
|
||||||
return block1([], [b3]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`can catch errors can catch an error origination from a child's willStart function 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div>classic</div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return block1();
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`can catch errors can catch an error origination from a child's willStart function 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div>Some text</div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return block1();
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`can catch errors can catch an error origination from a child's willStart function 3`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><block-child-1/><block-child-1/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2,b3;
|
|
||||||
if (ctx['state'].error) {
|
|
||||||
b2 = text(\`Error handled\`);
|
|
||||||
} else {
|
|
||||||
b3 = callSlot(ctx, node, key, 'default', false, {});
|
|
||||||
}
|
|
||||||
return block1([], [b2, b3]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`can catch errors can catch an error origination from a child's willStart function 4`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
function slot1(ctx, node, key) {
|
|
||||||
let b3 = component(\`ClassicCompoent\`, {}, key + \`__2\`, node, ctx);
|
|
||||||
let b4 = component(\`ErrorComponent\`, {}, key + \`__3\`, node, ctx);
|
|
||||||
return multi([b3, b4]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b5 = component(\`ErrorBoundary\`, {slots: {'default': {__render: slot1, __ctx: ctx}}}, key + \`__4\`, node, ctx);
|
|
||||||
return block1([], [b5]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`can catch errors catchError in catchError 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = ctx['a'].b.c;
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`can catch errors catchError in catchError 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2 = component(\`Boom\`, {}, key + \`__1\`, node, ctx);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`can catch errors catchError in catchError 3`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2,b3;
|
|
||||||
if (ctx['error']) {
|
|
||||||
b2 = text(\`Error\`);
|
|
||||||
} else {
|
|
||||||
b3 = component(\`Child\`, {}, key + \`__1\`, node, ctx);
|
|
||||||
}
|
|
||||||
return block1([], [b2, b3]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`errors and promises a rendering error in a sub component will reject the mount promise 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = this.will.crash;
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`errors and promises a rendering error in a sub component will reject the mount promise 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2 = component(\`Child\`, {}, key + \`__1\`, node, ctx);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`errors and promises a rendering error will reject the mount promise 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = this.will.crash;
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`errors and promises a rendering error will reject the render promise (with sub components) 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<span/>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return block1();
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`errors and promises a rendering error will reject the render promise (with sub components) 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><block-text-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2 = component(\`Child\`, {}, key + \`__1\`, node, ctx);
|
|
||||||
let d1 = ctx['x'].y;
|
|
||||||
return block1([d1], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`errors and promises a rendering error will reject the render promise 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2;
|
|
||||||
if (ctx['flag']) {
|
|
||||||
b2 = text(this.will.crash);
|
|
||||||
}
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`errors and promises an error in mounted call will reject the mount promise 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div>abc</div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return block1();
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`errors and promises an error in patched call will reject the render promise 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = ctx['val'];
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`errors and promises an error in willPatch call will reject the render promise 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = ctx['val'];
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`errors and promises errors in mounted and in willUnmount 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div/>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return block1();
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|||||||
@@ -1,10 +1,40 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`event handling can set handler on sub component 1`] = `
|
||||||
|
"function anonymous(bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div>simple vnode</div>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
return block1();
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`event handling can set handler on sub component 2`] = `
|
||||||
|
"function anonymous(bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
let assign = Object.assign;
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
let h2 = [\`click\`, ctx, 'inc'];
|
||||||
|
let b2 = assign(component(\`Child\`, {}, key + \`__1\`, node, ctx), {handlers: [h2]});
|
||||||
|
let b3 = text(ctx['state'].value);
|
||||||
|
return multi([b2, b3]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`event handling handler receive the event as argument 1`] = `
|
exports[`event handling handler receive the event as argument 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div>simple vnode</div>\`);
|
let block1 = createBlock(\`<div>simple vnode</div>\`);
|
||||||
|
|
||||||
@@ -18,41 +48,14 @@ exports[`event handling handler receive the event as argument 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
let assign = Object.assign;
|
||||||
let block1 = createBlock(\`<span block-handler-0=\\"click\\"><block-child-0/><block-text-1/></span>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let d1 = [ctx['inc'], ctx];
|
let h2 = [\`click\`, ctx, 'inc'];
|
||||||
let b2 = component(\`Child\`, {}, key + \`__1\`, node, ctx);
|
let b2 = assign(component(\`Child\`, {}, key + \`__1\`, node, ctx), {handlers: [h2]});
|
||||||
let d2 = ctx['state'].value;
|
let b3 = text(ctx['state'].value);
|
||||||
return block1([d1, d2], [b2]);
|
return multi([b2, b3]);
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`event handling objects from scope are properly captured by t-on 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
let block3 = createBlock(\`<div class=\\"item\\" block-handler-0=\\"click\\"/>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
ctx = Object.create(ctx);
|
|
||||||
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['items']);
|
|
||||||
for (let i1 = 0; i1 < l_block2; i1++) {
|
|
||||||
ctx[\`item\`] = v_block2[i1];
|
|
||||||
let key1 = ctx['item'];
|
|
||||||
const v1 = ctx['onClick'];
|
|
||||||
const v2 = ctx['item'];
|
|
||||||
let d1 = [ev=>v1(v2.val,ev), ctx];
|
|
||||||
c_block2[i1] = withKey(block3([d1]), key1);
|
|
||||||
}
|
|
||||||
let b2 = list(c_block2);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
@@ -61,40 +64,15 @@ exports[`event handling support for callable expression in event handler 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/><input type=\\"text\\" block-handler-1=\\"input\\"/></div>\`);
|
let block1 = createBlock(\`<div><block-text-0/><input type=\\"text\\" block-handler-1=\\"input\\"/></div>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let d1 = ctx['state'].value;
|
let d1 = ctx['state'].value;
|
||||||
let d2 = [ctx['obj'].onInput, ctx];
|
const v1 = ctx['obj'];
|
||||||
|
let d2 = (e) => {const res = (() => { return v1.onInput })(); if (typeof res === 'function') { res(e) }};
|
||||||
return block1([d1, d2]);
|
return block1([d1, d2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`event handling t-on with handler bound to dynamic argument on a t-foreach 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
let block3 = createBlock(\`<div class=\\"item\\" block-handler-0=\\"click\\"/>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
ctx = Object.create(ctx);
|
|
||||||
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['items']);
|
|
||||||
for (let i1 = 0; i1 < l_block2; i1++) {
|
|
||||||
ctx[\`item\`] = v_block2[i1];
|
|
||||||
let key1 = ctx['item'];
|
|
||||||
const v1 = ctx['onClick'];
|
|
||||||
const v2 = ctx['item'];
|
|
||||||
let d1 = [ev=>v1(v2,ev), ctx];
|
|
||||||
c_block2[i1] = withKey(block3([d1]), key1);
|
|
||||||
}
|
|
||||||
let b2 = list(c_block2);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ exports[`basics basic use 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span>child<block-text-0/></span>\`);
|
let block1 = createBlock(\`<span>child<block-text-0/></span>\`);
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ exports[`basics basic use 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
return component(\`Child\`, {p: 1}, key + \`__1\`, node, ctx);
|
return component(\`Child\`, {p: 1}, key + \`__1\`, node, ctx);
|
||||||
@@ -31,7 +31,7 @@ exports[`basics can select a sub widget 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span>CHILD 1</span>\`);
|
let block1 = createBlock(\`<span>CHILD 1</span>\`);
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ exports[`basics can select a sub widget 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div>CHILD 2</div>\`);
|
let block1 = createBlock(\`<div>CHILD 2</div>\`);
|
||||||
|
|
||||||
@@ -59,14 +59,14 @@ exports[`basics can select a sub widget 3`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let b2,b3;
|
let b2,b3;
|
||||||
if (ctx['env'].options.flag) {
|
if (ctx['env'].flag) {
|
||||||
b2 = component(\`Child\`, {}, key + \`__1\`, node, ctx);
|
b2 = component(\`Child\`, {}, key + \`__1\`, node, ctx);
|
||||||
}
|
}
|
||||||
if (!ctx['env'].options.flag) {
|
if (!ctx['env'].flag) {
|
||||||
b3 = component(\`OtherChild\`, {}, key + \`__2\`, node, ctx);
|
b3 = component(\`OtherChild\`, {}, key + \`__2\`, node, ctx);
|
||||||
}
|
}
|
||||||
return multi([b2, b3]);
|
return multi([b2, b3]);
|
||||||
@@ -78,7 +78,7 @@ exports[`basics can select a sub widget, part 2 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span>CHILD 1</span>\`);
|
let block1 = createBlock(\`<span>CHILD 1</span>\`);
|
||||||
|
|
||||||
@@ -92,7 +92,7 @@ exports[`basics can select a sub widget, part 2 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div>CHILD 2</div>\`);
|
let block1 = createBlock(\`<div>CHILD 2</div>\`);
|
||||||
|
|
||||||
@@ -106,7 +106,7 @@ exports[`basics can select a sub widget, part 2 3`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let b2,b3;
|
let b2,b3;
|
||||||
@@ -125,12 +125,12 @@ exports[`basics sub widget is interactive 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><button block-handler-0=\\"click\\">click</button>child<block-text-1/></span>\`);
|
let block1 = createBlock(\`<span><button block-handler-0=\\"click\\">click</button>child<block-text-1/></span>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let d1 = [ctx['inc'], ctx];
|
let d1 = [ctx, 'inc'];
|
||||||
let d2 = ctx['state'].val;
|
let d2 = ctx['state'].val;
|
||||||
return block1([d1, d2]);
|
return block1([d1, d2]);
|
||||||
}
|
}
|
||||||
@@ -141,7 +141,7 @@ exports[`basics sub widget is interactive 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
return component(\`Child\`, {p: 1}, key + \`__1\`, node, ctx);
|
return component(\`Child\`, {p: 1}, key + \`__1\`, node, ctx);
|
||||||
@@ -153,7 +153,7 @@ exports[`basics top level sub widget with a parent 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span>Hello</span>\`);
|
let block1 = createBlock(\`<span>Hello</span>\`);
|
||||||
|
|
||||||
@@ -167,7 +167,7 @@ exports[`basics top level sub widget with a parent 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
return component(\`ComponentC\`, {}, key + \`__1\`, node, ctx);
|
return component(\`ComponentC\`, {}, key + \`__1\`, node, ctx);
|
||||||
@@ -179,7 +179,7 @@ exports[`basics top level sub widget with a parent 3`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
|
||||||
|
|||||||
@@ -1,261 +0,0 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
||||||
|
|
||||||
exports[`hooks autofocus hook input in a t-if 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><input block-ref=\\"0\\"/><block-child-0/></div>\`);
|
|
||||||
let block2 = createBlock(\`<input block-ref=\\"0\\"/>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const refs = ctx.__owl__.refs;
|
|
||||||
let b2;
|
|
||||||
let d1 = (el) => refs[\`input1\`] = el;
|
|
||||||
if (ctx['state'].flag) {
|
|
||||||
let d2 = (el) => refs[\`input2\`] = el;
|
|
||||||
b2 = block2([d2]);
|
|
||||||
}
|
|
||||||
return block1([d1], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`hooks autofocus hook simple input 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><input block-ref=\\"0\\"/><input block-ref=\\"1\\"/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const refs = ctx.__owl__.refs;
|
|
||||||
let d1 = (el) => refs[\`input1\`] = el;
|
|
||||||
let d2 = (el) => refs[\`input2\`] = el;
|
|
||||||
return block1([d1, d2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`hooks can use onWillStart, onWillUpdateProps 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = ctx['props'].value;
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`hooks can use onWillStart, onWillUpdateProps 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return component(\`MyComponent\`, {value: ctx['state'].value}, key + \`__1\`, node, ctx);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`hooks can use useComponent 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div/>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return block1();
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`hooks can use useEnv 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = ctx['env'].val;
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`hooks mounted callbacks should be called in reverse order from willUnmount callbacks 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div>hey<block-text-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = ctx['state'].value;
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`hooks parent and child env 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = ctx['env'].val;
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`hooks parent and child env 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2 = text(ctx['env'].val);
|
|
||||||
let b3 = component(\`Child\`, {}, key + \`__1\`, node, ctx);
|
|
||||||
return multi([b2, b3]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`hooks two different call to willPatch/patched should work 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div>hey<block-text-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = ctx['state'].value;
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`hooks use sub env does not pollute user env 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = ctx['env'].val;
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`hooks useEffect hook dependencies prevent effects from rerunning when unchanged 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div/>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return block1();
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`hooks useEffect hook effect runs on mount, is reapplied on patch, and is cleaned up on unmount and before reapplying 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div/>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return block1();
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`hooks useEffect hook effect with empty dependency list never reruns 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = ctx['state'].value;
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`hooks useExternalListener 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = ctx['props'].value;
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`hooks useExternalListener 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2;
|
|
||||||
if (ctx['state'].flag) {
|
|
||||||
b2 = component(\`MyComponent\`, {}, key + \`__1\`, node, ctx);
|
|
||||||
}
|
|
||||||
return multi([b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`hooks useRef hook: basic use 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><button block-ref=\\"0\\"><block-text-1/></button></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const refs = ctx.__owl__.refs;
|
|
||||||
let d1 = (el) => refs[\`button\`] = el;
|
|
||||||
let d2 = ctx['value'];
|
|
||||||
return block1([d1, d2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
@@ -4,7 +4,7 @@ exports[`lifecycle hooks basic checks for a component 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span>test</span>\`);
|
let block1 = createBlock(\`<span>test</span>\`);
|
||||||
|
|
||||||
@@ -14,104 +14,11 @@ exports[`lifecycle hooks basic checks for a component 1`] = `
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`lifecycle hooks component semantics 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div>B</div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return block1();
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`lifecycle hooks component semantics 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div>D</div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return block1();
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`lifecycle hooks component semantics 3`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div>E</div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return block1();
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`lifecycle hooks component semantics 4`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div>F</div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return block1();
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`lifecycle hooks component semantics 5`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div>C<block-child-0/><block-child-1/><block-child-2/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2,b3,b4;
|
|
||||||
b2 = component(\`D\`, {}, key + \`__1\`, node, ctx);
|
|
||||||
if (ctx['state'].flag) {
|
|
||||||
b3 = component(\`E\`, {}, key + \`__2\`, node, ctx);
|
|
||||||
} else {
|
|
||||||
b4 = component(\`F\`, {}, key + \`__3\`, node, ctx);
|
|
||||||
}
|
|
||||||
return block1([], [b2, b3, b4]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`lifecycle hooks component semantics 6`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div>A<block-child-0/><block-child-1/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2 = component(\`B\`, {}, key + \`__1\`, node, ctx);
|
|
||||||
let b3 = component(\`C\`, {}, key + \`__2\`, node, ctx);
|
|
||||||
return block1([], [b2, b3]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`lifecycle hooks components are unmounted and destroyed if no longer in DOM 1`] = `
|
exports[`lifecycle hooks components are unmounted and destroyed if no longer in DOM 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div/>\`);
|
let block1 = createBlock(\`<div/>\`);
|
||||||
|
|
||||||
@@ -125,7 +32,7 @@ exports[`lifecycle hooks components are unmounted and destroyed if no longer in
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let b2;
|
let b2;
|
||||||
@@ -141,7 +48,7 @@ exports[`lifecycle hooks components are unmounted and destroyed if no longer in
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
||||||
|
|
||||||
@@ -156,7 +63,7 @@ exports[`lifecycle hooks components are unmounted and destroyed if no longer in
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block2 = createBlock(\`<div><block-child-0/></div>\`);
|
let block2 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
|
||||||
@@ -175,7 +82,7 @@ exports[`lifecycle hooks hooks are called in proper order in widget creation/des
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div/>\`);
|
let block1 = createBlock(\`<div/>\`);
|
||||||
|
|
||||||
@@ -189,7 +96,7 @@ exports[`lifecycle hooks hooks are called in proper order in widget creation/des
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
|
||||||
@@ -204,7 +111,7 @@ exports[`lifecycle hooks lifecycle semantics 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div/>\`);
|
let block1 = createBlock(\`<div/>\`);
|
||||||
|
|
||||||
@@ -218,7 +125,7 @@ exports[`lifecycle hooks lifecycle semantics 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
|
||||||
@@ -233,7 +140,7 @@ exports[`lifecycle hooks lifecycle semantics, part 2 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div/>\`);
|
let block1 = createBlock(\`<div/>\`);
|
||||||
|
|
||||||
@@ -247,7 +154,7 @@ exports[`lifecycle hooks lifecycle semantics, part 2 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
return component(\`GrandChild\`, {}, key + \`__1\`, node, ctx);
|
return component(\`GrandChild\`, {}, key + \`__1\`, node, ctx);
|
||||||
@@ -259,7 +166,7 @@ exports[`lifecycle hooks lifecycle semantics, part 2 3`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let b2;
|
let b2;
|
||||||
@@ -275,7 +182,7 @@ exports[`lifecycle hooks lifecycle semantics, part 3 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div/>\`);
|
let block1 = createBlock(\`<div/>\`);
|
||||||
|
|
||||||
@@ -289,7 +196,7 @@ exports[`lifecycle hooks lifecycle semantics, part 3 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
return component(\`GrandChild\`, {}, key + \`__1\`, node, ctx);
|
return component(\`GrandChild\`, {}, key + \`__1\`, node, ctx);
|
||||||
@@ -301,7 +208,7 @@ exports[`lifecycle hooks lifecycle semantics, part 3 3`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let b2;
|
let b2;
|
||||||
@@ -317,7 +224,7 @@ exports[`lifecycle hooks lifecycle semantics, part 4 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div/>\`);
|
let block1 = createBlock(\`<div/>\`);
|
||||||
|
|
||||||
@@ -331,7 +238,7 @@ exports[`lifecycle hooks lifecycle semantics, part 4 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
return component(\`GrandChild\`, {}, key + \`__1\`, node, ctx);
|
return component(\`GrandChild\`, {}, key + \`__1\`, node, ctx);
|
||||||
@@ -343,7 +250,7 @@ exports[`lifecycle hooks lifecycle semantics, part 4 3`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let b2;
|
let b2;
|
||||||
@@ -359,7 +266,7 @@ exports[`lifecycle hooks lifecycle semantics, part 5 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div/>\`);
|
let block1 = createBlock(\`<div/>\`);
|
||||||
|
|
||||||
@@ -373,7 +280,7 @@ exports[`lifecycle hooks lifecycle semantics, part 5 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let b2;
|
let b2;
|
||||||
@@ -389,7 +296,7 @@ exports[`lifecycle hooks lifecycle semantics, part 6 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div/>\`);
|
let block1 = createBlock(\`<div/>\`);
|
||||||
|
|
||||||
@@ -403,7 +310,7 @@ exports[`lifecycle hooks lifecycle semantics, part 6 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
return component(\`Child\`, {value: ctx['state'].value}, key + \`__1\`, node, ctx);
|
return component(\`Child\`, {value: ctx['state'].value}, key + \`__1\`, node, ctx);
|
||||||
@@ -415,7 +322,7 @@ exports[`lifecycle hooks mounted hook is called if mounted in DOM 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div/>\`);
|
let block1 = createBlock(\`<div/>\`);
|
||||||
|
|
||||||
@@ -425,41 +332,11 @@ exports[`lifecycle hooks mounted hook is called if mounted in DOM 1`] = `
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`lifecycle hooks mounted hook is called on every mount, not just the first one 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div>child</div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return block1();
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`lifecycle hooks mounted hook is called on every mount, not just the first one 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2;
|
|
||||||
if (ctx['state'].hasChild) {
|
|
||||||
b2 = component(\`Child\`, {}, key + \`__1\`, node, ctx);
|
|
||||||
}
|
|
||||||
return multi([b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`lifecycle hooks mounted hook is called on subcomponents, in proper order 1`] = `
|
exports[`lifecycle hooks mounted hook is called on subcomponents, in proper order 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div/>\`);
|
let block1 = createBlock(\`<div/>\`);
|
||||||
|
|
||||||
@@ -473,7 +350,7 @@ exports[`lifecycle hooks mounted hook is called on subcomponents, in proper orde
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
|
||||||
@@ -488,7 +365,7 @@ exports[`lifecycle hooks mounted hook is called on subsubcomponents, in proper o
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div/>\`);
|
let block1 = createBlock(\`<div/>\`);
|
||||||
|
|
||||||
@@ -502,7 +379,7 @@ exports[`lifecycle hooks mounted hook is called on subsubcomponents, in proper o
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
|
||||||
@@ -517,7 +394,7 @@ exports[`lifecycle hooks mounted hook is called on subsubcomponents, in proper o
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
|
||||||
@@ -531,27 +408,27 @@ exports[`lifecycle hooks mounted hook is called on subsubcomponents, in proper o
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`lifecycle hooks onWillRender 1`] = `
|
exports[`lifecycle hooks onRender 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<button block-handler-0=\\"click\\"><block-text-1/></button>\`);
|
let block1 = createBlock(\`<button block-handler-0=\\"click\\"><block-text-1/></button>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let d1 = [ctx['increment'], ctx];
|
let d1 = [ctx, 'increment'];
|
||||||
let d2 = ctx['state'].value;
|
let d2 = ctx['state'].value;
|
||||||
return block1([d1, d2]);
|
return block1([d1, d2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`lifecycle hooks onWillRender 2`] = `
|
exports[`lifecycle hooks onRender 2`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
return component(\`Child\`, {}, key + \`__1\`, node, ctx);
|
return component(\`Child\`, {}, key + \`__1\`, node, ctx);
|
||||||
@@ -563,7 +440,7 @@ exports[`lifecycle hooks patched hook is called after updateProps 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div/>\`);
|
let block1 = createBlock(\`<div/>\`);
|
||||||
|
|
||||||
@@ -577,7 +454,7 @@ exports[`lifecycle hooks patched hook is called after updateProps 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
|
||||||
@@ -592,22 +469,7 @@ exports[`lifecycle hooks patched hook is called after updating State 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = ctx['state'].a;
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`lifecycle hooks sub widget (inside sub node): hooks are correctly called 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div/>\`);
|
let block1 = createBlock(\`<div/>\`);
|
||||||
|
|
||||||
@@ -617,27 +479,11 @@ exports[`lifecycle hooks sub widget (inside sub node): hooks are correctly calle
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`lifecycle hooks sub widget (inside sub node): hooks are correctly called 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2;
|
|
||||||
if (ctx['state'].flag) {
|
|
||||||
b2 = component(\`Child\`, {}, key + \`__1\`, node, ctx);
|
|
||||||
}
|
|
||||||
return multi([b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`lifecycle hooks willPatch, patched hook are called on subsubcomponents, in proper order 1`] = `
|
exports[`lifecycle hooks willPatch, patched hook are called on subsubcomponents, in proper order 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
||||||
|
|
||||||
@@ -652,7 +498,7 @@ exports[`lifecycle hooks willPatch, patched hook are called on subsubcomponents,
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
|
||||||
@@ -667,7 +513,7 @@ exports[`lifecycle hooks willPatch, patched hook are called on subsubcomponents,
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
|
||||||
@@ -682,7 +528,7 @@ exports[`lifecycle hooks willStart hook is called on sub component 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div/>\`);
|
let block1 = createBlock(\`<div/>\`);
|
||||||
|
|
||||||
@@ -696,7 +542,7 @@ exports[`lifecycle hooks willStart hook is called on sub component 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
return component(\`Child\`, {}, key + \`__1\`, node, ctx);
|
return component(\`Child\`, {}, key + \`__1\`, node, ctx);
|
||||||
@@ -708,7 +554,7 @@ exports[`lifecycle hooks willStart is called 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span>simple vnode</span>\`);
|
let block1 = createBlock(\`<span>simple vnode</span>\`);
|
||||||
|
|
||||||
@@ -722,7 +568,7 @@ exports[`lifecycle hooks willStart is called with component as this 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span>simple vnode</span>\`);
|
let block1 = createBlock(\`<span>simple vnode</span>\`);
|
||||||
|
|
||||||
@@ -736,7 +582,7 @@ exports[`lifecycle hooks willStart, mounted on subwidget rendered after main is
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div/>\`);
|
let block1 = createBlock(\`<div/>\`);
|
||||||
|
|
||||||
@@ -750,7 +596,7 @@ exports[`lifecycle hooks willStart, mounted on subwidget rendered after main is
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
|
||||||
let block3 = createBlock(\`<div/>\`);
|
let block3 = createBlock(\`<div/>\`);
|
||||||
@@ -771,7 +617,7 @@ exports[`lifecycle hooks willUpdateProps hook is called 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
||||||
|
|
||||||
@@ -786,7 +632,7 @@ exports[`lifecycle hooks willUpdateProps hook is called 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
return component(\`Child\`, {n: ctx['state'].n}, key + \`__1\`, node, ctx);
|
return component(\`Child\`, {n: ctx['state'].n}, key + \`__1\`, node, ctx);
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ exports[`basics accept ES6-like syntax for props (with getters) 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ exports[`basics accept ES6-like syntax for props (with getters) 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
|
||||||
@@ -30,47 +30,11 @@ exports[`basics accept ES6-like syntax for props (with getters) 2`] = `
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`basics arrow functions as prop correctly capture their scope 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<button block-handler-0=\\"click\\"/>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = [ctx['props'].onClick, ctx];
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`basics arrow functions as prop correctly capture their scope 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
ctx = Object.create(ctx);
|
|
||||||
const [k_block1, v_block1, l_block1, c_block1] = prepareList(ctx['items']);
|
|
||||||
for (let i1 = 0; i1 < l_block1; i1++) {
|
|
||||||
ctx[\`item\`] = v_block1[i1];
|
|
||||||
let key1 = ctx['item'].val;
|
|
||||||
const v1 = ctx['onClick'];
|
|
||||||
const v2 = ctx['item'];
|
|
||||||
c_block1[i1] = withKey(component(\`Child\`, {onClick: ev=>v1(v2.val,ev)}, key + \`__3__\${key1}\`, node, ctx), key1);
|
|
||||||
}
|
|
||||||
return list(c_block1);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`basics explicit object prop 1`] = `
|
exports[`basics explicit object prop 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
||||||
|
|
||||||
@@ -85,7 +49,7 @@ exports[`basics explicit object prop 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
|
||||||
@@ -96,88 +60,33 @@ exports[`basics explicit object prop 2`] = `
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`basics prop names can contain - 1`] = `
|
exports[`basics t-set with a body expression can be passed in props, and then t-raw 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = ctx['props']['prop-name'];
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`basics prop names can contain - 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return component(\`Child\`, {'prop-name': 7}, key + \`__1\`, node, ctx);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`basics support prop names that aren't valid bare object property names 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<button block-handler-0=\\"click\\"/>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let d1 = [ctx['props'].onClick, ctx];
|
|
||||||
return block1([d1]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`basics support prop names that aren't valid bare object property names 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return component(\`Child\`, {'some-dashed-prop': 5,'a.b': 'keyword prop'}, key + \`__1\`, node, ctx);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`basics t-set with a body expression can be passed in props, and then t-out 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-text-0/><block-child-0/></span>\`);
|
let block1 = createBlock(\`<span><block-text-0/><block-child-0/></span>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let d1 = ctx['props'].val;
|
let d1 = ctx['props'].val;
|
||||||
let b2 = safeOutput(ctx['props'].val);
|
let b2 = html(ctx['props'].val);
|
||||||
return block1([d1], [b2]);
|
return block1([d1], [b2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`basics t-set with a body expression can be passed in props, and then t-out 2`] = `
|
exports[`basics t-set with a body expression can be passed in props, and then t-raw 2`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
let block2 = createBlock(\`<p>43</p>\`);
|
let block2 = createBlock(\`<p>43</p>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
ctx = Object.create(ctx);
|
ctx = Object.create(ctx);
|
||||||
ctx[isBoundary] = 1
|
|
||||||
let b2 = block2();
|
let b2 = block2();
|
||||||
ctx[\`abc\`] = b2;
|
ctx[\`abc\`] = b2;
|
||||||
let b3 = component(\`Child\`, {val: ctx['abc']}, key + \`__1\`, node, ctx);
|
let b3 = component(\`Child\`, {val: ctx['abc']}, key + \`__1\`, node, ctx);
|
||||||
@@ -190,7 +99,7 @@ exports[`basics t-set with a body expression can be used as textual prop 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
||||||
|
|
||||||
@@ -205,14 +114,13 @@ exports[`basics t-set with a body expression can be used as textual prop 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
ctx = Object.create(ctx);
|
ctx = Object.create(ctx);
|
||||||
ctx[isBoundary] = 1
|
ctx[\`abc\`] = \`42\`;
|
||||||
setContextValue(ctx, \\"abc\\", \`42\`);
|
|
||||||
let b2 = component(\`Child\`, {val: ctx['abc']}, key + \`__1\`, node, ctx);
|
let b2 = component(\`Child\`, {val: ctx['abc']}, key + \`__1\`, node, ctx);
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
}
|
}
|
||||||
@@ -223,7 +131,7 @@ exports[`basics t-set works 1`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
||||||
|
|
||||||
@@ -238,40 +146,15 @@ exports[`basics t-set works 2`] = `
|
|||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
ctx = Object.create(ctx);
|
ctx = Object.create(ctx);
|
||||||
ctx[isBoundary] = 1
|
ctx[\`val\`] = 42;
|
||||||
setContextValue(ctx, \\"val\\", 42);
|
|
||||||
let b2 = component(\`Child\`, {val: ctx['val']}, key + \`__1\`, node, ctx);
|
let b2 = component(\`Child\`, {val: ctx['val']}, key + \`__1\`, node, ctx);
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`basics template string in prop 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return text(\`\`);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`basics template string in prop 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
return component(\`Child\`, {propName: \`1\${ctx['someVal']}3\`}, key + \`__1\`, node, ctx);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|||||||
@@ -1,526 +0,0 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
||||||
|
|
||||||
exports[`default props can set default required boolean values 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const props1 = {}
|
|
||||||
helpers.validateProps(\`SubComp\`, props1, ctx)
|
|
||||||
let b2 = component(\`SubComp\`, props1, key + \`__2\`, node, ctx);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`default props can set default values 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const props1 = {}
|
|
||||||
helpers.validateProps(\`SubComp\`, props1, ctx)
|
|
||||||
let b2 = component(\`SubComp\`, props1, key + \`__2\`, node, ctx);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`default props default values are also set whenever component is updated 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const props1 = {p: ctx['state'].p}
|
|
||||||
helpers.validateProps(\`SubComp\`, props1, ctx)
|
|
||||||
let b2 = component(\`SubComp\`, props1, key + \`__2\`, node, ctx);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`props validation can validate a prop with multiple types 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const props1 = {p: ctx['p']}
|
|
||||||
helpers.validateProps(\`SubComp\`, props1, ctx)
|
|
||||||
let b2 = component(\`SubComp\`, props1, key + \`__2\`, node, ctx);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`props validation can validate a prop with multiple types 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const props1 = {p: ctx['p']}
|
|
||||||
helpers.validateProps(\`SubComp\`, props1, ctx)
|
|
||||||
let b2 = component(\`SubComp\`, props1, key + \`__2\`, node, ctx);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`props validation can validate an array with given primitive type 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const props1 = {p: ctx['p']}
|
|
||||||
helpers.validateProps(\`SubComp\`, props1, ctx)
|
|
||||||
let b2 = component(\`SubComp\`, props1, key + \`__2\`, node, ctx);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`props validation can validate an array with given primitive type 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const props1 = {p: ctx['p']}
|
|
||||||
helpers.validateProps(\`SubComp\`, props1, ctx)
|
|
||||||
let b2 = component(\`SubComp\`, props1, key + \`__2\`, node, ctx);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`props validation can validate an array with multiple sub element types 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const props1 = {p: ctx['p']}
|
|
||||||
helpers.validateProps(\`SubComp\`, props1, ctx)
|
|
||||||
let b2 = component(\`SubComp\`, props1, key + \`__2\`, node, ctx);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`props validation can validate an array with multiple sub element types 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const props1 = {p: ctx['p']}
|
|
||||||
helpers.validateProps(\`SubComp\`, props1, ctx)
|
|
||||||
let b2 = component(\`SubComp\`, props1, key + \`__2\`, node, ctx);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`props validation can validate an array with multiple sub element types 3`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const props1 = {p: ctx['p']}
|
|
||||||
helpers.validateProps(\`SubComp\`, props1, ctx)
|
|
||||||
let b2 = component(\`SubComp\`, props1, key + \`__2\`, node, ctx);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`props validation can validate an object with simple shape 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const props1 = {p: ctx['p']}
|
|
||||||
helpers.validateProps(\`SubComp\`, props1, ctx)
|
|
||||||
let b2 = component(\`SubComp\`, props1, key + \`__2\`, node, ctx);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`props validation can validate an optional props 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const props1 = {p: ctx['p']}
|
|
||||||
helpers.validateProps(\`SubComp\`, props1, ctx)
|
|
||||||
let b2 = component(\`SubComp\`, props1, key + \`__2\`, node, ctx);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`props validation can validate an optional props 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const props1 = {p: ctx['p']}
|
|
||||||
helpers.validateProps(\`SubComp\`, props1, ctx)
|
|
||||||
let b2 = component(\`SubComp\`, props1, key + \`__2\`, node, ctx);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`props validation can validate recursively complicated prop def 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const props1 = {p: ctx['p']}
|
|
||||||
helpers.validateProps(\`SubComp\`, props1, ctx)
|
|
||||||
let b2 = component(\`SubComp\`, props1, key + \`__2\`, node, ctx);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`props validation can validate recursively complicated prop def 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const props1 = {p: ctx['p']}
|
|
||||||
helpers.validateProps(\`SubComp\`, props1, ctx)
|
|
||||||
let b2 = component(\`SubComp\`, props1, key + \`__2\`, node, ctx);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`props validation default values are applied before validating props at update 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const props1 = {p: ctx['state'].p}
|
|
||||||
helpers.validateProps(\`SubComp\`, props1, ctx)
|
|
||||||
let b2 = component(\`SubComp\`, props1, key + \`__2\`, node, ctx);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`props validation props are validated in dev mode (code snapshot) 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const props1 = {message: 1}
|
|
||||||
helpers.validateProps(\`Child\`, props1, ctx)
|
|
||||||
let b2 = component(\`Child\`, props1, key + \`__2\`, node, ctx);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`props validation props are validated whenever component is updated 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const props1 = {p: ctx['state'].p}
|
|
||||||
helpers.validateProps(\`SubComp\`, props1, ctx)
|
|
||||||
let b2 = component(\`SubComp\`, props1, key + \`__2\`, node, ctx);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`props validation validate simple types 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const props1 = {p: ctx['p']}
|
|
||||||
helpers.validateProps(\`SubComp\`, props1, ctx)
|
|
||||||
let b2 = component(\`SubComp\`, props1, key + \`__2\`, node, ctx);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`props validation validate simple types 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const props1 = {p: ctx['p']}
|
|
||||||
helpers.validateProps(\`SubComp\`, props1, ctx)
|
|
||||||
let b2 = component(\`SubComp\`, props1, key + \`__2\`, node, ctx);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`props validation validate simple types 3`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const props1 = {p: ctx['p']}
|
|
||||||
helpers.validateProps(\`SubComp\`, props1, ctx)
|
|
||||||
let b2 = component(\`SubComp\`, props1, key + \`__2\`, node, ctx);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`props validation validate simple types 4`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const props1 = {p: ctx['p']}
|
|
||||||
helpers.validateProps(\`SubComp\`, props1, ctx)
|
|
||||||
let b2 = component(\`SubComp\`, props1, key + \`__2\`, node, ctx);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`props validation validate simple types 5`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const props1 = {p: ctx['p']}
|
|
||||||
helpers.validateProps(\`SubComp\`, props1, ctx)
|
|
||||||
let b2 = component(\`SubComp\`, props1, key + \`__2\`, node, ctx);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`props validation validate simple types 6`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const props1 = {p: ctx['p']}
|
|
||||||
helpers.validateProps(\`SubComp\`, props1, ctx)
|
|
||||||
let b2 = component(\`SubComp\`, props1, key + \`__2\`, node, ctx);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`props validation validate simple types, alternate form 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const props1 = {p: ctx['p']}
|
|
||||||
helpers.validateProps(\`SubComp\`, props1, ctx)
|
|
||||||
let b2 = component(\`SubComp\`, props1, key + \`__2\`, node, ctx);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`props validation validate simple types, alternate form 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const props1 = {p: ctx['p']}
|
|
||||||
helpers.validateProps(\`SubComp\`, props1, ctx)
|
|
||||||
let b2 = component(\`SubComp\`, props1, key + \`__2\`, node, ctx);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`props validation validate simple types, alternate form 3`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const props1 = {p: ctx['p']}
|
|
||||||
helpers.validateProps(\`SubComp\`, props1, ctx)
|
|
||||||
let b2 = component(\`SubComp\`, props1, key + \`__2\`, node, ctx);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`props validation validate simple types, alternate form 4`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const props1 = {p: ctx['p']}
|
|
||||||
helpers.validateProps(\`SubComp\`, props1, ctx)
|
|
||||||
let b2 = component(\`SubComp\`, props1, key + \`__2\`, node, ctx);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`props validation validate simple types, alternate form 5`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const props1 = {p: ctx['p']}
|
|
||||||
helpers.validateProps(\`SubComp\`, props1, ctx)
|
|
||||||
let b2 = component(\`SubComp\`, props1, key + \`__2\`, node, ctx);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`props validation validate simple types, alternate form 6`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
const props1 = {p: ctx['p']}
|
|
||||||
helpers.validateProps(\`SubComp\`, props1, ctx)
|
|
||||||
let b2 = component(\`SubComp\`, props1, key + \`__2\`, node, ctx);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`props validation validation is only done in dev mode 1`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let b2 = component(\`SubComp\`, {}, key + \`__1\`, node, ctx);
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user