mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
Compare commits
407 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3ae81e9bee | |||
| 56cfc6403d | |||
| 276c8a0295 | |||
| 0717fe241d | |||
| 1291f1f175 | |||
| 6c0a3525c8 | |||
| 13241422e9 | |||
| 8f2c7f24d7 | |||
| fed9cc467f | |||
| 33174b301b | |||
| ea5d2be502 | |||
| 4a761a7403 | |||
| 8702db03fb | |||
| b2685b6709 | |||
| c30678f3ea | |||
| 6ca6717965 | |||
| ad4adb930e | |||
| cea82e945d | |||
| a69f8a39e7 | |||
| 316eb06279 | |||
| df59ec49ae | |||
| 2a008a8679 | |||
| 3d40533de1 | |||
| 39329f80b2 | |||
| 203ac7ac66 | |||
| 530c2f9e4c | |||
| ef8baa23d7 | |||
| acfcc5677a | |||
| f6e8aff725 | |||
| 4a5316ced5 | |||
| 9a5edb4590 | |||
| 3d49daedcd | |||
| 620e41daa1 | |||
| de84075c11 | |||
| 9fe8e93980 | |||
| bd199971bd | |||
| 6f23b18cab | |||
| 2c244aa31a | |||
| ba1a270c93 | |||
| d546244fc3 | |||
| a1f22829c1 | |||
| 64bad25762 | |||
| 7ab34c5ca5 | |||
| 669fd622ec | |||
| ab72cdddde | |||
| 17fb33475c | |||
| ab29b896eb | |||
| d5ed25cd19 | |||
| c4f0f17b9b | |||
| d27455e9f2 | |||
| 6ef38676c4 | |||
| b51756f356 | |||
| cfdf7caa50 | |||
| a5a6a592c1 | |||
| d0d7482b0f | |||
| 8fe4c0c76e | |||
| c1afaeb92a | |||
| 3883cec079 | |||
| 9cb74d619b | |||
| a93f015795 | |||
| 02a187d80b | |||
| d3b0d1971e | |||
| b90aa0e23a | |||
| 163366997c | |||
| 588b655c11 | |||
| f5d5273c25 | |||
| 9fd662fdce | |||
| 7786077921 | |||
| 30bc605c84 | |||
| d1118455aa | |||
| f8073cb153 | |||
| 6c72e0a143 | |||
| 382e3e4010 | |||
| 76c389a7a8 | |||
| b9ba0abf41 | |||
| 4ca37be7f3 | |||
| d6667ddf2e | |||
| 6f86beeaf3 | |||
| 7f580a4e1d | |||
| c7459ef87b | |||
| 5772b4e9e4 | |||
| e57e2ee378 | |||
| 2e03332acd | |||
| c16d7d52b1 | |||
| 9c4c3e3b83 | |||
| 55ac43c1db | |||
| d046913a01 | |||
| 0e6059467f | |||
| 51538c2fea | |||
| 83d4471048 | |||
| 8a967e5b2d | |||
| 385e118e58 | |||
| a3111eb9ca | |||
| 1fc88f626f | |||
| 5d5a530505 | |||
| c7bd0ab85c | |||
| 31b57cbb40 | |||
| 31fce0926c | |||
| b56a9c24cf | |||
| 6dcdb77eab | |||
| a7daef380a | |||
| 22a79cdedd | |||
| e4b810c027 | |||
| b10a700381 | |||
| 2b4d8874c7 | |||
| 98b58b505b | |||
| 586033fd95 | |||
| 1fe0bf08b1 | |||
| 4779707923 | |||
| d917af4614 | |||
| 4c77132ae2 | |||
| 114f21586e | |||
| 32d8b23b9d | |||
| a83731007a | |||
| 5c71744e19 | |||
| d09771b04b | |||
| 7137130c38 | |||
| 0cd66c8518 | |||
| 5d9cff0331 | |||
| 41f1262eb7 | |||
| 41344ef4ec | |||
| 7d14db7d31 | |||
| 1179e84971 | |||
| 24b1ea7604 | |||
| 3e4ebb6378 | |||
| 859748aed9 | |||
| fd13277e1d | |||
| 7fb166bd50 | |||
| decf42c742 | |||
| 989b0d6709 | |||
| 9b93521da4 | |||
| de240b1ebc | |||
| 55dbc01a1b | |||
| e3b1566943 | |||
| 828be28653 | |||
| d80fad760c | |||
| 7611ea6033 | |||
| c7d515a6b3 | |||
| d277039b14 | |||
| 77ff5ee895 | |||
| 47c6d6cc3c | |||
| 0625b5883a | |||
| 53ab54b1ec | |||
| 4770b91faa | |||
| c356351de2 | |||
| f04423da23 | |||
| b3062d29f1 | |||
| 56086242bb | |||
| 998ecbb337 | |||
| 50355e6a3d | |||
| 67f86a4ab8 | |||
| 14d2328c88 | |||
| e4fdd32f22 | |||
| 8d1d0a2244 | |||
| 0457e5d4ed | |||
| 8920b4b93a | |||
| 6908102a72 | |||
| d6348b8310 | |||
| 79738e00c7 | |||
| 2a1b99be2d | |||
| 8a472231cf | |||
| bb373e6a7a | |||
| d735213758 | |||
| 076b0d774e | |||
| f405fe9323 | |||
| 1ae9d514b9 | |||
| 592d9a458e | |||
| 0dbd2bd463 | |||
| 8ec7a6f9bf | |||
| 12b8ce963e | |||
| bb9d65e95b | |||
| 73c339fff1 | |||
| 406be446a5 | |||
| bd2aa8a72f | |||
| 3536f41f00 | |||
| 804ad3c35e | |||
| 4a922ed82d | |||
| a6f0985d43 | |||
| 6aee1355c8 | |||
| 921ced7c90 | |||
| 1da930cb25 | |||
| cc8e11c9c9 | |||
| 3196b585fd | |||
| ea2ccc5a03 | |||
| 960808aeb2 | |||
| 1fb1d37e32 | |||
| 24ce8613c5 | |||
| 2c1226d737 | |||
| 140818b5f9 | |||
| 83de53d283 | |||
| 50aac42bdc | |||
| bd98d4d0d0 | |||
| 4d68dac24d | |||
| 722abd6d5f | |||
| a7305a5cdb | |||
| ff734c706c | |||
| add5fdd737 | |||
| a221411938 | |||
| bb6479f44f | |||
| aa95149997 | |||
| e4b4ee471f | |||
| 3af5e57825 | |||
| 979712f84e | |||
| 93f2c1d766 | |||
| 0728c8333d | |||
| 6639d361c3 | |||
| 72962f1dd1 | |||
| a4d9aae9a7 | |||
| 1e8576ad40 | |||
| 753d82149e | |||
| 700030cc7d | |||
| d828f39a2d | |||
| 0a73154985 | |||
| d88eb34d4f | |||
| a8d88d4009 | |||
| 6d9ed0d62f | |||
| b33471e819 | |||
| 3fb65b3a89 | |||
| 09d192999a | |||
| 466cf50b73 | |||
| 96620d3e8e | |||
| 176c89b278 | |||
| 38941bc26f | |||
| ce8ddd1cbf | |||
| 81f44ee5d3 | |||
| 99b5e9ec55 | |||
| 4f35f03986 | |||
| eab0caa6cb | |||
| 5a2c769eab | |||
| 89d63ff29a | |||
| a2e8abc243 | |||
| dfd0dcedb8 | |||
| ad743c205c | |||
| 7c78442e43 | |||
| 0d13c362d3 | |||
| 374dbb2fd9 | |||
| 2a5f37cf4b | |||
| cfb6b9f958 | |||
| 82f6923a21 | |||
| cccb379377 | |||
| 82c7c24438 | |||
| 41ad5db2e3 | |||
| 42a140a8e3 | |||
| 7711733a23 | |||
| 281b32965e | |||
| cec451fd15 | |||
| 6a7703ea82 | |||
| 4a03a60084 | |||
| a6bdca082a | |||
| 90167c5436 | |||
| c221721d7f | |||
| 38f39b6755 | |||
| 1775467434 | |||
| 52d0526ddd | |||
| 4b170b9b45 | |||
| 3e1fe07ba7 | |||
| 5bf47500d5 | |||
| 75ad0835e9 | |||
| 3d6a5eb828 | |||
| aceaeef8cc | |||
| 06fc3a2c77 | |||
| 92cc4375f8 | |||
| 9f2e2bcc66 | |||
| c7af885f43 | |||
| bd5637c0a3 | |||
| 3c98ef8cb1 | |||
| aad6b806ba | |||
| 772c275bd4 | |||
| 416deeb865 | |||
| 7e40fa300a | |||
| cc1eea0945 | |||
| bf9cceb56f | |||
| 7eaecac0b5 | |||
| ddc358f48a | |||
| e2819323ee | |||
| 983b9f996d | |||
| fd295b3be3 | |||
| e675f7ff5b | |||
| 702fb3b253 | |||
| 63fbcf99fd | |||
| 14a6289f60 | |||
| 894deed13b | |||
| 6f435c36d8 | |||
| 5dddf8f9a3 | |||
| 463eb4bb86 | |||
| b66d5231d3 | |||
| 3c12519277 | |||
| c1a973a4d8 | |||
| e91e50a812 | |||
| 2e176f135d | |||
| 49c7585998 | |||
| f32b1deb2c | |||
| 1da3ecdbee | |||
| a1c619f094 | |||
| eceb3e6280 | |||
| 8a1ac13975 | |||
| 779003e715 | |||
| 8c600fa539 | |||
| bcc4fe2a27 | |||
| bb4948f3dc | |||
| cc4480e001 | |||
| 7143c2e39b | |||
| a8d8310b8e | |||
| 0bbea351a6 | |||
| 2601a176c4 | |||
| 05a57d6da5 | |||
| e6e6c31632 | |||
| 3f66d9fe6c | |||
| 5d8141a67c | |||
| 6459d8d289 | |||
| 2943ca3921 | |||
| 4866ed8e8a | |||
| 93b88cad8d | |||
| b90180a9e0 | |||
| 8239a5d2cd | |||
| a073568667 | |||
| 7143dd3ff5 | |||
| c0cf2c9e3d | |||
| db9658c140 | |||
| eb2c41aa91 | |||
| a45ca98dac | |||
| ced777f0be | |||
| 7df0a4e93f | |||
| f3555cfae0 | |||
| 629b379ea9 | |||
| a400fc5e69 | |||
| 5d4a38ad0f | |||
| 093218a067 | |||
| ed3e6dcbb6 | |||
| cb107cef7d | |||
| aecc320c29 | |||
| e580ec00fe | |||
| ee5f6c7569 | |||
| c627b0add8 | |||
| b902edc1be | |||
| 1761af9c24 | |||
| db93ef08ff | |||
| 03787cfb39 | |||
| 10745c52d0 | |||
| 2b90e3a688 | |||
| b2ea241270 | |||
| 81e5b24f2f | |||
| 717fd3b6ab | |||
| 3fa1bb62f6 | |||
| 201f06c187 | |||
| ae30d9db7d | |||
| af80cefa76 | |||
| 1f6e84d141 | |||
| 1658d15b87 | |||
| c1439814bf | |||
| d5fbaff9f7 | |||
| 8c16790471 | |||
| 9b8c582b32 | |||
| 1700a6fba3 | |||
| 7513b1e507 | |||
| e0c0306acd | |||
| bca6afeb90 | |||
| 756d32daa0 | |||
| 8169f05edc | |||
| 153f4379f4 | |||
| 7ffb9afbd9 | |||
| c03042b44d | |||
| df2d6b6a0e | |||
| 7c04cc425e | |||
| 16f1e2c237 | |||
| 8a84b5be56 | |||
| 219923d752 | |||
| 348b505e5f | |||
| d3745e4e5f | |||
| 80cb6b7a91 | |||
| 4cceb239dd | |||
| 2ae0149adb | |||
| 3eb63452e7 | |||
| 1296964ae2 | |||
| c71db28bc6 | |||
| a0b2551e4a | |||
| ebd2e4324f | |||
| aa3148eddf | |||
| 42811344da | |||
| a0e1af83ac | |||
| c16d8ed6de | |||
| 15e4c856da | |||
| ced5d0f69f | |||
| b6eb4d009e | |||
| 8c71d99e5f | |||
| d7f3f4defe | |||
| 0f2192604c | |||
| 10df0b5f4a | |||
| d569ea1c28 | |||
| 52fa81c510 | |||
| d6668e3439 | |||
| ee1ef20ce1 | |||
| 9d5ffe11c7 | |||
| 900a3ee501 | |||
| 0a544bd7e8 | |||
| 4415cc8932 | |||
| efa147fdab | |||
| e746574a1d | |||
| c06049076a | |||
| bc04f727ac | |||
| 0bc9573a8a | |||
| 73f94fba3f | |||
| 7a16449724 | |||
| 718c765e3b | |||
| 150d620b8e | |||
| 307b936d01 | |||
| 6950f8e628 |
@@ -0,0 +1,47 @@
|
|||||||
|
{
|
||||||
|
"env": {
|
||||||
|
"browser": true,
|
||||||
|
"node": true,
|
||||||
|
"es2022": true
|
||||||
|
},
|
||||||
|
"parser": "@typescript-eslint/parser",
|
||||||
|
"plugins": ["@typescript-eslint"],
|
||||||
|
"parserOptions": {
|
||||||
|
"sourceType": "module"
|
||||||
|
},
|
||||||
|
"root": true,
|
||||||
|
"rules": {
|
||||||
|
"no-restricted-globals": ["error", "event", "self"],
|
||||||
|
"no-const-assign": ["error"],
|
||||||
|
"no-debugger": ["error"],
|
||||||
|
"no-dupe-class-members": ["error"],
|
||||||
|
"no-dupe-keys": ["error"],
|
||||||
|
"no-dupe-args": ["error"],
|
||||||
|
"no-dupe-else-if": ["error"],
|
||||||
|
"no-unsafe-negation": ["error"],
|
||||||
|
"no-duplicate-imports": ["error"],
|
||||||
|
"valid-typeof": ["error"],
|
||||||
|
"@typescript-eslint/no-unused-vars": ["error", { "vars": "all", "args": "none", "ignoreRestSiblings": false, "caughtErrors": "all" }],
|
||||||
|
"no-restricted-syntax": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
"selector": "MemberExpression[object.name='test'][property.name='only']",
|
||||||
|
"message": "test.only(...) is forbidden",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"selector": "MemberExpression[object.name='describe'][property.name='only']",
|
||||||
|
"message": "describe.only(...) is forbidden",
|
||||||
|
}
|
||||||
|
],
|
||||||
|
},
|
||||||
|
"globals": {
|
||||||
|
"describe": true,
|
||||||
|
"expect": true,
|
||||||
|
"test": true,
|
||||||
|
"beforeEach": true,
|
||||||
|
"beforeAll": true,
|
||||||
|
"afterEach": true,
|
||||||
|
"afterAll": true,
|
||||||
|
"jest": true,
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -5,7 +5,7 @@ name: Node.js CI
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ master, owl-next ]
|
branches: [ master ]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
@@ -22,7 +22,8 @@ jobs:
|
|||||||
uses: actions/setup-node@v1
|
uses: actions/setup-node@v1
|
||||||
with:
|
with:
|
||||||
node-version: ${{ matrix.node-version }}
|
node-version: ${{ matrix.node-version }}
|
||||||
- run: npm install
|
- run: npm ci
|
||||||
- run: npm run test
|
- run: npm run test
|
||||||
- run: npm run check-formatting
|
- run: npm run check-formatting
|
||||||
|
- run: npm run lint
|
||||||
- run: npm run build
|
- run: npm run build
|
||||||
|
|||||||
@@ -14,9 +14,6 @@ npm-debug.log*
|
|||||||
yarn-debug.log*
|
yarn-debug.log*
|
||||||
yarn-error.log*
|
yarn-error.log*
|
||||||
|
|
||||||
package-lock.json
|
|
||||||
yarn.lock
|
|
||||||
|
|
||||||
#ide's
|
#ide's
|
||||||
.vscode
|
.vscode
|
||||||
.idea
|
.idea
|
||||||
|
|||||||
+81
-80
@@ -30,19 +30,32 @@ All changes are documented here in no particular order.
|
|||||||
- breaking: `catchError` method is replaced by `onError` hook ([details](#36-catcherror-method-is-replaced-by-onerror-hook))
|
- breaking: `catchError` method is replaced by `onError` hook ([details](#36-catcherror-method-is-replaced-by-onerror-hook))
|
||||||
- breaking: Support for inline css (`css` tag and static `style`) has been removed ([details](#37-support-for-inline-css-css-tag-and-static-style-has-been-removed))
|
- breaking: Support for inline css (`css` tag and static `style`) has been removed ([details](#37-support-for-inline-css-css-tag-and-static-style-has-been-removed))
|
||||||
- new: prop validation system can now describe that additional props are allowed (with `*`) ([doc](doc/reference/props.md#props-validation))
|
- new: prop validation system can now describe that additional props are allowed (with `*`) ([doc](doc/reference/props.md#props-validation))
|
||||||
|
- breaking: prop validation system does not allow default prop on a mandatory (not optional) prop ([doc](doc/reference/props.md#props-validation))
|
||||||
|
- breaking: rendering a component does not necessarily render child components ([details](#40-rendering-a-component-does-not-necessarily-render-child-components))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
**Templates**
|
**Templates**
|
||||||
|
|
||||||
- breaking: `t-foreach` should always have a corresponding `t-key` ([details](#20-t-foreach-should-always-have-a-corresponding-t-key))
|
- breaking: `t-foreach` should always have a corresponding `t-key` ([details](#20-t-foreach-should-always-have-a-corresponding-t-key))
|
||||||
- breaking: `t-ref` does not work on components ([details](#29-t-ref-does-not-work-on-component))
|
- 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))
|
|
||||||
- breaking: `t-raw` directive has been removed (replaced by `t-out`) ([details](#38-t-raw-directive-has-been-removed-replaced-by-t-out))
|
- breaking: `t-raw` directive has been removed (replaced by `t-out`) ([details](#38-t-raw-directive-has-been-removed-replaced-by-t-out))
|
||||||
- new: add support for synthetic events ([doc](doc/reference/event_handling.md#synthetic-events))
|
- new: add support for synthetic events ([doc](doc/reference/event_handling.md#synthetic-events))
|
||||||
- breaking: style/class on components are now regular props ([details](#10-styleclass-on-components-are-now-regular-props))
|
- breaking: style/class on components are now regular props ([details](#10-styleclass-on-components-are-now-regular-props))
|
||||||
- new: components can use the `.bind` suffix to bind function props ([doc](doc/reference/props.md#binding-function-props))
|
- new: components can use the `.bind` suffix to bind function props ([doc](doc/reference/props.md#binding-function-props))
|
||||||
- breaking: `t-on` does not work on components any more ([details](#12-t-on-does-not-work-on-components-any-more))
|
- breaking: `t-on` does not accept expressions, only functions ([details](#30-t-on-does-not-accept-expressions-only-functions))
|
||||||
|
- new: an error is thrown if an handler defined in a `t-on-` directive is not a function (failed silently previously in some cases)
|
||||||
- breaking: `t-component` no longer accepts strings ([details](#17-t-component-no-longer-accepts-strings))
|
- breaking: `t-component` no longer accepts strings ([details](#17-t-component-no-longer-accepts-strings))
|
||||||
|
- new: the `this` variable in template expressions is now bound to the component
|
||||||
|
|
||||||
|
|
||||||
|
**Reactivity**
|
||||||
|
|
||||||
|
- finer grained reactivity: owl 2 tracks change per key/component
|
||||||
|
- finer grained reactivity: sub components can reobserve state ([doc](doc/reference/reactivity.md))
|
||||||
|
- new: `reactive` function: create reactive state (without being linked to a component) ([doc](doc/reference/reactivity.md#reactive))
|
||||||
|
- new: `markRaw` function: mark an object or array so that it is ignored by the reactivity system ([doc](doc/reference/reactivity.md#markraw))
|
||||||
|
- new: `toRaw` function: given a reactive objet, return the raw (non reactive) underlying object ([doc](doc/reference/reactivity.md#toraw))
|
||||||
|
|
||||||
|
|
||||||
**Slots**
|
**Slots**
|
||||||
@@ -66,13 +79,12 @@ All changes are documented here in no particular order.
|
|||||||
|
|
||||||
- improved performance
|
- improved performance
|
||||||
- much simpler code
|
- 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) ([doc](doc/reference/app.md))
|
- new App class to encapsulate a root Owl component (with the config for that application) ([doc](doc/reference/app.md))
|
||||||
- new `Memo` component
|
|
||||||
- new `useEffect` hook ([doc](doc/reference/hooks.md#useeffect))
|
- new `useEffect` hook ([doc](doc/reference/hooks.md#useeffect))
|
||||||
- breaking: `Context` is removed ([details](#15-context-is-removed))
|
- breaking: `Context` is removed ([details](#15-context-is-removed))
|
||||||
- breaking: `env` is now totally empty ([details](#16-env-is-now-totally-empty))
|
- breaking: `env` is now totally empty ([details](#16-env-is-now-totally-empty))
|
||||||
|
- breaking: `env` is now frozen ([details](#28-env-is-now-frozen))
|
||||||
|
- new hook: `useChildSubEnv` (only applies to child components) ([details](#27-usechildsubenv-only-applies-to-child-components))
|
||||||
- breaking: most exports are exported at top level ([details](#18-most-exports-are-exported-at-top-level))
|
- 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: properties are no longer set as attributes ([details](#19-properties-are-no-longer-set-as-attributes))
|
||||||
- breaking: `EventBus` api changed: it is now an `EventTarget` ([details](#21-eventbus-api-changed-it-is-now-an-eventtarget))
|
- breaking: `EventBus` api changed: it is now an `EventTarget` ([details](#21-eventbus-api-changed-it-is-now-an-eventtarget))
|
||||||
@@ -81,8 +93,6 @@ All changes are documented here in no particular order.
|
|||||||
- breaking: transition system is removed ([details](#24-transition-system-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: 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: `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: `renderToString` function on qweb has been removed ([details](#32-rendertostring-on-qweb-has-been-removed))
|
- breaking: `renderToString` function on qweb has been removed ([details](#32-rendertostring-on-qweb-has-been-removed))
|
||||||
- breaking: `debounce` utility function has been removed ([details](#34-debounce-utility-function-has-been-removed))
|
- breaking: `debounce` utility function has been removed ([details](#34-debounce-utility-function-has-been-removed))
|
||||||
- breaking: `browser` object has been removed ([details](#39-browser-object-has-been-removed))
|
- breaking: `browser` object has been removed ([details](#39-browser-object-has-been-removed))
|
||||||
@@ -237,35 +247,12 @@ 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),
|
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
|
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
|
subset of components that is subscribed to a piece of state. Now, Owl 2 features
|
||||||
a much more powerful reactivity system.
|
a much more powerful reactivity system, so the same rationale applies: in a way,
|
||||||
|
it's like each Owl 2 component has a `shouldUpdate` method that precisely tracks
|
||||||
|
every value used by the component.
|
||||||
|
|
||||||
Migration code: remove the `shouldUpdate` methods. Then, maybe the following
|
Migration code: remove the `shouldUpdate` methods, and it should work as well
|
||||||
ideas may help:
|
as before.
|
||||||
|
|
||||||
- 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 is removed
|
### 9. component.el is removed
|
||||||
|
|
||||||
@@ -325,41 +312,6 @@ Documentation:
|
|||||||
- [Mounting a component](doc/reference/app.md#mount-helper)
|
- [Mounting a component](doc/reference/app.md#mount-helper)
|
||||||
|
|
||||||
|
|
||||||
### 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"/>
|
|
||||||
<!-- or alternatively: -->
|
|
||||||
<SomeComponent onSomeEvent.bind="doSomething"/>
|
|
||||||
```
|
|
||||||
|
|
||||||
Note that one of the example above uses the `.bind` suffix, to bind the function
|
|
||||||
prop to the component. Most of the time, binding the function is necessary, and
|
|
||||||
using the `.bind` suffix is very helpful in that case.
|
|
||||||
|
|
||||||
Documentation: [Binding function props](doc/reference/props.md#binding-function-props)
|
|
||||||
|
|
||||||
### 13. Portal does no longer transfer DOM events
|
### 13. Portal does no longer transfer DOM events
|
||||||
|
|
||||||
In Owl 1, a Portal component would listen to events emitted on its portalled
|
In Owl 1, a Portal component would listen to events emitted on its portalled
|
||||||
@@ -565,15 +517,12 @@ 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
|
as props. If there is no escape, and `AsyncRoot` is needed, please reach out to
|
||||||
us so we can study this usecase.
|
us so we can study this usecase.
|
||||||
|
|
||||||
### 27. `useSubEnv` only applies to child components
|
### 27. `useChildSubEnv` (only applies to child components)
|
||||||
|
|
||||||
In Owl 1, a call to `useSubEnv` would define a new environment for the children
|
In Owl, a call to `useSubEnv` would define a new environment for the children
|
||||||
AND the component. It now only defines an environment for the children.
|
AND the component. It is very useful, but in some cases, one only need to update
|
||||||
|
the children component environment. This can now be done with a new hook:
|
||||||
Rationale: This was a subtle cause for bugs: some code had to be rrun
|
[`useChildSubEnv`](doc/reference/hooks.md#usesubenv-and-usechildsubenv)
|
||||||
before the call to `useSubEnv`, otherwise it could interfere with the sub environment.
|
|
||||||
|
|
||||||
Documentation: [Hooks](doc/reference/hooks.md#usesubenv)
|
|
||||||
|
|
||||||
### 28. `env` is now frozen
|
### 28. `env` is now frozen
|
||||||
|
|
||||||
@@ -659,10 +608,14 @@ Also, this can easily be done in userspace, by mounting a component in a div. F
|
|||||||
export async function renderToString(template, context) {
|
export async function renderToString(template, context) {
|
||||||
class C extends Component {
|
class C extends Component {
|
||||||
static template = template;
|
static template = template;
|
||||||
|
setup () {
|
||||||
|
Object.assign(this, context);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const div = document.createElement('div');
|
const div = document.createElement('div');
|
||||||
document.body.appendChild(div);
|
document.body.appendChild(div);
|
||||||
const component = await mount(C, div);
|
const app = new App(C);
|
||||||
|
await app.mount(div);
|
||||||
const result = div.innerHTML;
|
const result = div.innerHTML;
|
||||||
app.destroy();
|
app.destroy();
|
||||||
div.remove();
|
div.remove();
|
||||||
@@ -670,6 +623,30 @@ export async function renderToString(template, context) {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The function above works for most cases, but is asynchronous. An alternative
|
||||||
|
function could look like this:
|
||||||
|
|
||||||
|
```js
|
||||||
|
const { App, blockDom } = owl;
|
||||||
|
const app = new App(Component); // act as a template repository
|
||||||
|
|
||||||
|
function renderToString(template, context = {}) {
|
||||||
|
app.addTemplate(template, template, { allowDuplicate: true });
|
||||||
|
const templateFn = app.getTemplate(template);
|
||||||
|
const bdom = templateFn(context, {});
|
||||||
|
const div = document.createElement('div')
|
||||||
|
blockDom.mount(bdom, div);
|
||||||
|
return div.innerHTML;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
This is a synchronous function, so it will not work with components, but it should
|
||||||
|
be useful for most simple templates.
|
||||||
|
|
||||||
|
Also note that these two examples do not translate their templates. To do that,
|
||||||
|
they need to be modified to pass the proper translate function to the `App`
|
||||||
|
configuration.
|
||||||
|
|
||||||
### 33. Portal are now defined with `t-portal`
|
### 33. Portal are now defined with `t-portal`
|
||||||
|
|
||||||
Before Owl 2, one could use the `Portal` component by importing it and using it.
|
Before Owl 2, one could use the `Portal` component by importing it and using it.
|
||||||
@@ -762,4 +739,28 @@ Rationale: the `browser` object caused more trouble than it was worth. Also, it
|
|||||||
seems like this should be done in user space, not at the framework level.
|
seems like this should be done in user space, not at the framework level.
|
||||||
|
|
||||||
Migration: code should just be adapted to either use another browser object,
|
Migration: code should just be adapted to either use another browser object,
|
||||||
or to use native browser function (and then, just mock them directly).
|
or to use native browser function (and then, just mock them directly).
|
||||||
|
|
||||||
|
## 40. Rendering a component does not necessarily render child components
|
||||||
|
|
||||||
|
Before, if one had the following component tree:
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
graph TD;
|
||||||
|
A-->B;
|
||||||
|
A-->C;
|
||||||
|
```
|
||||||
|
|
||||||
|
when `A` would render, it would also render `B` and `C`. Now, in Owl 2, it will
|
||||||
|
(shallow) compare the before and after props, and `B` or `C` will only be rerendered
|
||||||
|
if their props have changed.
|
||||||
|
|
||||||
|
Now, the question is what happens if the props have changed, but in a deeper way?
|
||||||
|
In that case, Owl will know, because each props are now reactive. So, if some
|
||||||
|
inner value read by `B` was changed, then only `B` will be updated.
|
||||||
|
|
||||||
|
Rationale: This was just not possible in Owl 1, but it now possible. This is
|
||||||
|
due to the rewriteof the underlying rendering engine and the reactivity
|
||||||
|
system. The goal is to have a big performance boost in large screen with many
|
||||||
|
components: now Owl only rerender what is strictly useful.
|
||||||
|
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ Are you new to Owl? This is the place to start!
|
|||||||
- [Component](doc/reference/component.md)
|
- [Component](doc/reference/component.md)
|
||||||
- [Component Lifecycle](doc/reference/component.md#lifecycle)
|
- [Component Lifecycle](doc/reference/component.md#lifecycle)
|
||||||
- [Concurrency Model](doc/reference/concurrency_model.md)
|
- [Concurrency Model](doc/reference/concurrency_model.md)
|
||||||
|
- [Dev mode](doc/reference/app.md#dev-mode)
|
||||||
- [Dynamic sub components](doc/reference/component.md#dynamic-sub-components)
|
- [Dynamic sub components](doc/reference/component.md#dynamic-sub-components)
|
||||||
- [Environment](doc/reference/environment.md)
|
- [Environment](doc/reference/environment.md)
|
||||||
- [Error Handling](doc/reference/error_handling.md)
|
- [Error Handling](doc/reference/error_handling.md)
|
||||||
@@ -92,6 +93,7 @@ Are you new to Owl? This is the place to start!
|
|||||||
- [Loading Templates](doc/reference/app.md#loading-templates)
|
- [Loading Templates](doc/reference/app.md#loading-templates)
|
||||||
- [Mounting a component](doc/reference/app.md#mount-helper)
|
- [Mounting a component](doc/reference/app.md#mount-helper)
|
||||||
- [Portal](doc/reference/portal.md)
|
- [Portal](doc/reference/portal.md)
|
||||||
|
- [Precompiling templates](doc/reference/precompiling_templates.md)
|
||||||
- [Props](doc/reference/props.md)
|
- [Props](doc/reference/props.md)
|
||||||
- [Props Validation](doc/reference/props.md#props-validation)
|
- [Props Validation](doc/reference/props.md#props-validation)
|
||||||
- [Reactivity](doc/reference/reactivity.md)
|
- [Reactivity](doc/reference/reactivity.md)
|
||||||
@@ -110,6 +112,7 @@ Are you new to Owl? This is the place to start!
|
|||||||
- [Comparison with React/Vue](doc/miscellaneous/comparison.md)
|
- [Comparison with React/Vue](doc/miscellaneous/comparison.md)
|
||||||
- [Why did Odoo build Owl?](doc/miscellaneous/why_owl.md)
|
- [Why did Odoo build Owl?](doc/miscellaneous/why_owl.md)
|
||||||
- [Changelog (from owl 1.x to 2.x)](CHANGELOG.md)
|
- [Changelog (from owl 1.x to 2.x)](CHANGELOG.md)
|
||||||
|
- [Notes on compiled templates](doc/miscellaneous/compiled_template.md)
|
||||||
|
|
||||||
## Installing Owl
|
## Installing Owl
|
||||||
|
|
||||||
@@ -121,5 +124,5 @@ 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](https://github.com/odoo/owl/releases/latest)
|
||||||
|
|
||||||
|
|||||||
@@ -174,9 +174,9 @@ class Root extends Component {
|
|||||||
```
|
```
|
||||||
|
|
||||||
The template contains a [`t-foreach`](../reference/templates.md#loops) loop to iterate
|
The template contains a [`t-foreach`](../reference/templates.md#loops) loop to iterate
|
||||||
through the tasks. It can find the `tasks` list from the component, since the
|
through the tasks. It can find the `tasks` list from the component, since the rendering
|
||||||
component is the rendering context. Note that we use the `id` of each task as a
|
context contains the properties of the component. Note that we use the `id` of each task
|
||||||
`t-key`, which is very common. There are two css classes: `task-list` and `task`,
|
as a `t-key`, which is very common. There are two css classes: `task-list` and `task`,
|
||||||
that we will use in the next section.
|
that we will use in the next section.
|
||||||
|
|
||||||
Finally, notice the use of the `t-att-checked` attribute:
|
Finally, notice the use of the `t-att-checked` attribute:
|
||||||
@@ -240,7 +240,7 @@ class Task extends Component {
|
|||||||
static template = xml /* xml */`
|
static template = xml /* xml */`
|
||||||
<div class="task" t-att-class="props.task.isCompleted ? 'done' : ''">
|
<div class="task" t-att-class="props.task.isCompleted ? 'done' : ''">
|
||||||
<input type="checkbox" t-att-checked="props.task.isCompleted"/>
|
<input type="checkbox" t-att-checked="props.task.isCompleted"/>
|
||||||
<span><t t-esc="props.task.title"/></span>
|
<span><t t-esc="props.task.text"/></span>
|
||||||
</div>`;
|
</div>`;
|
||||||
static props = ["task"];
|
static props = ["task"];
|
||||||
}
|
}
|
||||||
@@ -502,6 +502,10 @@ deleteTask(task) {
|
|||||||
Notice that the `onDelete` prop is defined with a `.bind` suffix: this is a special
|
Notice that the `onDelete` prop is defined with a `.bind` suffix: this is a special
|
||||||
suffix that makes sure the function callback is bound to the component.
|
suffix that makes sure the function callback is bound to the component.
|
||||||
|
|
||||||
|
Notice also that we have two functions named `deleteTask`. The one in the Task
|
||||||
|
component just delegates the work to the Root component that owns the task list
|
||||||
|
via the `onDelete` property.
|
||||||
|
|
||||||
## 10. Using a store
|
## 10. Using a store
|
||||||
|
|
||||||
Looking at the code, it is apparent that all the code handling tasks is scattered
|
Looking at the code, it is apparent that all the code handling tasks is scattered
|
||||||
@@ -743,7 +747,7 @@ the user experience.
|
|||||||
```xml
|
```xml
|
||||||
<input type="checkbox" t-att-checked="props.task.isCompleted"
|
<input type="checkbox" t-att-checked="props.task.isCompleted"
|
||||||
t-att-id="props.task.id"
|
t-att-id="props.task.id"
|
||||||
t-on-click="dispatch('toggleTask', props.task.id)"/>
|
t-on-click="() => store.toggleTask(props.task)"/>
|
||||||
<label t-att-for="props.task.id"><t t-esc="props.task.text"/></label>
|
<label t-att-for="props.task.id"><t t-esc="props.task.text"/></label>
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -770,10 +774,11 @@ For reference, here is the final code:
|
|||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<title>OWL Todo App</title>
|
<title>OWL Todo App</title>
|
||||||
<link rel="stylesheet" href="app.css" />
|
<link rel="stylesheet" href="app.css" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
<script src="owl.js"></script>
|
<script src="owl.js"></script>
|
||||||
<script src="app.js"></script>
|
<script src="app.js"></script>
|
||||||
</head>
|
</body>
|
||||||
<body></body>
|
|
||||||
</html>
|
</html>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,98 @@
|
|||||||
|
# 🦉 Notes On Owl Compiled Templates 🦉
|
||||||
|
|
||||||
|
This page will explain what an Owl compiled template look like. This is a
|
||||||
|
technical document intended for developers interested in understanding how Owl
|
||||||
|
works internally.
|
||||||
|
|
||||||
|
Broadly speaking, Owl compiles templates into a javascript function (a closure)
|
||||||
|
that returns a function (the "render" function). The point of the closure is to
|
||||||
|
have a place to store all values specific to the template (in particular, "blocks").
|
||||||
|
Once a template is compiled, its closure function is called once to get the
|
||||||
|
render function, and from then on, only the render function is used.
|
||||||
|
|
||||||
|
The render function takes some context (and some additional information) and
|
||||||
|
return a virtual dom representation of the rendered template, as a block tree.
|
||||||
|
A block tree is a very light weight representation that only contains the dynamic
|
||||||
|
part of the template, and its structure. It is actually independant of the
|
||||||
|
static part of the templates (which are contained in the blocks captured by the
|
||||||
|
closure). This means that the work performed at render time is only to collect
|
||||||
|
dynamic data, and to describe the block structure of the result.
|
||||||
|
|
||||||
|
It looks like this, in pseudo code:
|
||||||
|
|
||||||
|
```js
|
||||||
|
function closure(bdom, helpers) {
|
||||||
|
// here is some place to put stuff specific to the template, such as
|
||||||
|
// blocks
|
||||||
|
...
|
||||||
|
|
||||||
|
return function render(context, node, key) {
|
||||||
|
// only build here all dynamic parts of the template
|
||||||
|
// build a block tree
|
||||||
|
return tree;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Now, let us see an example. Consider the following template:
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<div class="some-class">
|
||||||
|
<div class="blabla">
|
||||||
|
<span><t t-esc="state.value"/></span>
|
||||||
|
</div>
|
||||||
|
<t t-if="state.info">
|
||||||
|
<p class="info" t-att-class="someAttribute">
|
||||||
|
<t t-esc="state.info"/>
|
||||||
|
</p>
|
||||||
|
</t>
|
||||||
|
<SomeComponent value="value"/>
|
||||||
|
</div>
|
||||||
|
```
|
||||||
|
|
||||||
|
If you look carefully, there are 5 dynamic things:
|
||||||
|
|
||||||
|
- a text value (the first `t-esc`),
|
||||||
|
- a sub block (the `t-if`),
|
||||||
|
- a dynamic attribute (the `t-att-class` attribute),
|
||||||
|
- another text value (the second `t-esc`),
|
||||||
|
- and finally, a sub component
|
||||||
|
|
||||||
|
Here is the compiled code for this template:
|
||||||
|
|
||||||
|
```js
|
||||||
|
function closure(bdom, helpers) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
||||||
|
|
||||||
|
let block1 = createBlock(
|
||||||
|
`<div class="some-class"><div class="blabla"><span><block-text-0/></span></div><block-child-0/><block-child-1/></div>`
|
||||||
|
);
|
||||||
|
let block2 = createBlock(`<p class="info" block-attribute-0="class"><block-text-1/></p>`);
|
||||||
|
|
||||||
|
return function render(ctx, node, key = "") {
|
||||||
|
let b2, b3;
|
||||||
|
let txt1 = ctx["state"].value;
|
||||||
|
if (ctx["state"].info) {
|
||||||
|
let attr1 = ctx["someAttribute"];
|
||||||
|
let txt2 = ctx["state"].info;
|
||||||
|
b2 = block2([attr1, txt2]);
|
||||||
|
}
|
||||||
|
b3 = component(`SomeComponent`, { value: ctx["value"] }, key + `__1`, node, ctx);
|
||||||
|
return block1([txt1], [b2, b3]);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
The values captured in the closure capture the static part of the template: we
|
||||||
|
define here two blocks (which contains a template node, that can be deep cloned
|
||||||
|
whenever a block is mounted). Then the render function only describes the block
|
||||||
|
tree structure of the result, depending on the context. This means that we
|
||||||
|
minimize the amount of work done at render time.
|
||||||
|
|
||||||
|
Then, when we want to patch the dom, Owl will uses the `patch` function from
|
||||||
|
blockdom, which then will diff the block tree, and deep clone new blocks whenever
|
||||||
|
a new block is inserted, keep track of dynamic parts of each block, and update
|
||||||
|
them accordingly.
|
||||||
|
|
||||||
|
With this design, the cost of rendering a template is proportional to the number
|
||||||
|
of dynamic values, and not to the size of the template.
|
||||||
+9
-2
@@ -7,9 +7,14 @@ Main entities:
|
|||||||
- [`App`](reference/app.md): represent an Owl application (mainly a root component,a set of templates, and a config)
|
- [`App`](reference/app.md): represent an Owl application (mainly a root component,a set of templates, and a config)
|
||||||
- [`Component`](reference/component.md): the main class to define a concrete Owl component
|
- [`Component`](reference/component.md): the main class to define a concrete Owl component
|
||||||
- [`mount`](reference/app.md#mount-helper): main entry point for most application: mount a component to a target
|
- [`mount`](reference/app.md#mount-helper): main entry point for most application: mount a component to a target
|
||||||
|
- [`xml`](reference/templates.md#inline-templates): helper to define an inline template
|
||||||
|
|
||||||
|
Reactivity
|
||||||
|
|
||||||
- [`useState`](reference/reactivity.md#usestate): create a reactive object (hook, linked to a specific component)
|
- [`useState`](reference/reactivity.md#usestate): create a reactive object (hook, linked to a specific component)
|
||||||
- [`reactive`](reference/reactivity.md#reactive): create a reactive object (not linked to any component)
|
- [`reactive`](reference/reactivity.md#reactive): create a reactive object (not linked to any component)
|
||||||
- [`xml`](reference/templates.md#inline-templates): helper to define an inline template
|
- [`markRaw`](reference/reactivity.md#markraw): mark an object or array so that it is ignored by the reactivity system
|
||||||
|
- [`toRaw`](reference/reactivity.md#toraw): given a reactive objet, return the raw (non reactive) underlying object
|
||||||
|
|
||||||
Lifecycle hooks:
|
Lifecycle hooks:
|
||||||
|
|
||||||
@@ -31,7 +36,8 @@ Other hooks:
|
|||||||
- [`useEnv`](reference/hooks.md#useenv): return a reference to the current env
|
- [`useEnv`](reference/hooks.md#useenv): return a reference to the current env
|
||||||
- [`useExternalListener`](reference/hooks.md#useexternallistener): add a listener outside of a component DOM
|
- [`useExternalListener`](reference/hooks.md#useexternallistener): add a listener outside of a component DOM
|
||||||
- [`useRef`](reference/hooks.md#useref): get an object representing a reference (`t-ref`)
|
- [`useRef`](reference/hooks.md#useref): get an object representing a reference (`t-ref`)
|
||||||
- [`useSubEnv`](reference/hooks.md#usesubenv): extend the current env with additional information for child components
|
- [`useChildSubEnv`](reference/hooks.md#usesubenv-and-usechildsubenv): extend the current env with additional information (for child components)
|
||||||
|
- [`useSubEnv`](reference/hooks.md#usesubenv-and-usechildsubenv): extend the current env with additional information (for current component and child components)
|
||||||
|
|
||||||
Utility/helpers:
|
Utility/helpers:
|
||||||
|
|
||||||
@@ -39,4 +45,5 @@ Utility/helpers:
|
|||||||
- [`loadFile`](reference/utils.md#loadfile): an helper to load a file from the server
|
- [`loadFile`](reference/utils.md#loadfile): an helper to load a file from the server
|
||||||
- [`markup`](reference/templates.md#outputting-data): utility function to define strings that represent html (should not be escaped)
|
- [`markup`](reference/templates.md#outputting-data): utility function to define strings that represent html (should not be escaped)
|
||||||
- [`status`](reference/component.md#status-helper): utility function to get the status of a component (new, mounted or destroyed)
|
- [`status`](reference/component.md#status-helper): utility function to get the status of a component (new, mounted or destroyed)
|
||||||
|
- [`validate`](reference/utils.md#validate): validates if an object satisfies a specified schema
|
||||||
- [`whenReady`](reference/utils.md#whenready): utility function to execute code when DOM is ready
|
- [`whenReady`](reference/utils.md#whenready): utility function to execute code when DOM is ready
|
||||||
|
|||||||
+32
-16
@@ -3,6 +3,7 @@
|
|||||||
## Content
|
## Content
|
||||||
|
|
||||||
- [Overview](#overview)
|
- [Overview](#overview)
|
||||||
|
- [API](#api)
|
||||||
- [Configuration](#configuration)
|
- [Configuration](#configuration)
|
||||||
- [`mount` helper](#mount-helper)
|
- [`mount` helper](#mount-helper)
|
||||||
- [Loading templates](#loading-templates)
|
- [Loading templates](#loading-templates)
|
||||||
@@ -26,24 +27,10 @@ The basic workflow is: create an `App` instance configured with the root
|
|||||||
component, the templates, and possibly other settings. Then, we mount that
|
component, the templates, and possibly other settings. Then, we mount that
|
||||||
instance somewhere in the DOM.
|
instance somewhere in the DOM.
|
||||||
|
|
||||||
## Configuration
|
## API
|
||||||
|
|
||||||
- **`constructor(Root[, config])`**: first argument should be a component class (not
|
- **`constructor(Root[, config])`**: first argument should be a component class (not
|
||||||
an instance), and the optional second argument is a configuration object.
|
an instance), and the optional second argument is a configuration object (see below).
|
||||||
|
|
||||||
The `config` object is an object with some of the following keys:
|
|
||||||
|
|
||||||
- **`env (object)`**: if given, this will be the shared `env` given to each component
|
|
||||||
- **`props (object)`**: the props given to the root component
|
|
||||||
- **`dev (boolean, default=false)`**: if `true`, the application is rendered in `dev`
|
|
||||||
mode, which activates some additional checks (in particular, the props validation
|
|
||||||
code is only performed in dev mode)
|
|
||||||
- **`translatableAttributes (string[])`**: a list of additional attributes that should
|
|
||||||
be translated (see [translations](translations.md))
|
|
||||||
- **`translateFn (function)`**: a function that will be called by owl to translate
|
|
||||||
templates (see [translations](translations.md))
|
|
||||||
- **`templates (string | xml document)`**: all the templates that will be used by
|
|
||||||
the components created by the application.
|
|
||||||
|
|
||||||
- **`mount(target, options)`**: first argument is an html element, and the optional
|
- **`mount(target, options)`**: first argument is an html element, and the optional
|
||||||
second argument is an object with mounting options (see below). Mount the app
|
second argument is an object with mounting options (see below). Mount the app
|
||||||
@@ -58,6 +45,25 @@ instance somewhere in the DOM.
|
|||||||
|
|
||||||
- **`destroy()`**: destroys the application
|
- **`destroy()`**: destroys the application
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
The `config` object is an object with some of the following keys:
|
||||||
|
|
||||||
|
- **`env (object)`**: if given, this will be the shared `env` given to each component
|
||||||
|
- **`props (object)`**: the props given to the root component
|
||||||
|
- **`dev (boolean, default=false)`**: if `true`, the application is rendered in
|
||||||
|
[`dev` mode](#dev-mode);
|
||||||
|
- **`test (boolean, default=false)`**: `test` mode is the same as `dev` mode, except
|
||||||
|
that Owl will not log a message to warn that Owl is in `dev` mode.
|
||||||
|
- **`translatableAttributes (string[])`**: a list of additional attributes that should
|
||||||
|
be translated (see [translations](translations.md))
|
||||||
|
- **`translateFn (function)`**: a function that will be called by owl to translate
|
||||||
|
templates (see [translations](translations.md))
|
||||||
|
- **`templates (string | xml document)`**: all the templates that will be used by
|
||||||
|
the components created by the application.
|
||||||
|
- **`warnIfNoStaticProps (boolean, default=false)`**: if true, Owl will log a warning
|
||||||
|
whenever it encounters a component that does not provide a [static props description](props.md#props-validation).
|
||||||
|
|
||||||
## `mount` helper
|
## `mount` helper
|
||||||
|
|
||||||
Note that there is a `mount` helper to do that in just a line:
|
Note that there is a `mount` helper to do that in just a line:
|
||||||
@@ -105,3 +111,13 @@ const { loadFile, mount } = owl;
|
|||||||
mount(Root, document.body, { env });
|
mount(Root, document.body, { env });
|
||||||
})();
|
})();
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Dev mode
|
||||||
|
|
||||||
|
Dev mode activates some additional checks and developer amenities:
|
||||||
|
|
||||||
|
- [Props validation](./props.md#props-validation) is performed
|
||||||
|
- [t-foreach](./templates.md#loops) loops check for key unicity
|
||||||
|
- Lifecycle hooks are wrapped to report their errors in a more developer-friendly way
|
||||||
|
- onWillStart and onWillUpdateProps will emit a warning in the console when they
|
||||||
|
take longer than 3 seconds in an effort to ease debugging the presence of deadlocks
|
||||||
|
|||||||
@@ -68,12 +68,17 @@ The `Component` class has a very small API.
|
|||||||
component will go through the following lifecycle methods: `willUpdateProps`,
|
component will go through the following lifecycle methods: `willUpdateProps`,
|
||||||
`willPatch` and `patched`.
|
`willPatch` and `patched`.
|
||||||
|
|
||||||
* **`render()`**: calling this method directly will cause a rerender. Note
|
* **`render(deep[=false])`**: calling this method directly will cause a rerender. Note
|
||||||
that with the reactivity system, this should be rare to have to do it manually.
|
that with the reactivity system, this should be rare to have to do it manually.
|
||||||
Also, the rendering operation is asynchronous, so the DOM will only be updated
|
Also, the rendering operation is asynchronous, so the DOM will only be updated
|
||||||
slightly later (at the next animation frame, if no component delays the
|
slightly later (at the next animation frame, if no component delays the
|
||||||
rendering)
|
rendering)
|
||||||
|
|
||||||
|
By default, the render initiated by this method will stop at each child
|
||||||
|
component if their props are (shallow) equal. To force a render to update
|
||||||
|
all child components, one can use the optional `deep` argument. Note that the
|
||||||
|
value of the `deep` argument needs to be a boolean, not a truthy value.
|
||||||
|
|
||||||
## Static Properties
|
## Static Properties
|
||||||
|
|
||||||
- **`template (string)`**: this is the name of the template that
|
- **`template (string)`**: this is the name of the template that
|
||||||
|
|||||||
@@ -1,105 +0,0 @@
|
|||||||
# 🦉 Context 🦉
|
|
||||||
|
|
||||||
## Content
|
|
||||||
|
|
||||||
- [Overview](#overview)
|
|
||||||
- [Example](#example)
|
|
||||||
- [Reference](#reference)
|
|
||||||
- [`Context`](#context)
|
|
||||||
- [`useContext`](#usecontext)
|
|
||||||
|
|
||||||
## Overview
|
|
||||||
|
|
||||||
The `Context` object provides a way to share data between an arbitrary number
|
|
||||||
of components. Usually, data is passed from a parent to its children component,
|
|
||||||
but when we have to deal with some mostly global information, this can be
|
|
||||||
annoying, since each component will need to pass the information to each children,
|
|
||||||
even though some or most of them will not use the information.
|
|
||||||
|
|
||||||
With a `Context` object, each component can subscribe (with the `useContext` hook)
|
|
||||||
to its state, and will be updated whenever the context state is updated.
|
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
Assume that we have an application with various components which needs to render
|
|
||||||
differently depending on the size of the device. Here is how we could proceed
|
|
||||||
to make sure that the information is properly shared. First, let us create a
|
|
||||||
context, and add it to the environment:
|
|
||||||
|
|
||||||
```js
|
|
||||||
const deviceContext = new Context({ isMobile: true });
|
|
||||||
App.env.deviceContext = deviceContext;
|
|
||||||
```
|
|
||||||
|
|
||||||
If we want to make it completely responsive, we need to update its value whenever
|
|
||||||
the size of the screen is updated:
|
|
||||||
|
|
||||||
```js
|
|
||||||
const isMobile = () => window.innerWidth <= 768;
|
|
||||||
window.addEventListener(
|
|
||||||
"resize",
|
|
||||||
owl.utils.debounce(() => {
|
|
||||||
const state = deviceContext.state;
|
|
||||||
if (state.isMobile !== isMobile()) {
|
|
||||||
state.isMobile = !state.isMobile;
|
|
||||||
}
|
|
||||||
}, 15)
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
Then, each component that want can subscribe and render differently depending on the
|
|
||||||
fact that we are in a mobile or desktop mode.
|
|
||||||
|
|
||||||
```js
|
|
||||||
class SomeComponent extends Component {
|
|
||||||
static template = xml`
|
|
||||||
<div>
|
|
||||||
<t t-if=device.isMobile>
|
|
||||||
some simplified user interface
|
|
||||||
</t>
|
|
||||||
<t t-else="">
|
|
||||||
a more advanced user interface
|
|
||||||
</t>
|
|
||||||
</div>`;
|
|
||||||
device = useContext(this.env.deviceContext);
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Reference
|
|
||||||
|
|
||||||
### `Context`
|
|
||||||
|
|
||||||
A `Context` object should be created with a state object:
|
|
||||||
|
|
||||||
```js
|
|
||||||
const someContext = new Context({ some: "key" });
|
|
||||||
```
|
|
||||||
|
|
||||||
Its state is now available in the `state` key:
|
|
||||||
|
|
||||||
```js
|
|
||||||
someContext.state.some = "other key";
|
|
||||||
```
|
|
||||||
|
|
||||||
This is the way some global code (such as the responsive code above) should
|
|
||||||
read and update the context state. However, components should not ever read the
|
|
||||||
context state directly from the context, they should instead use the `useContext`
|
|
||||||
hook to properly register themselves to state changes.
|
|
||||||
|
|
||||||
Note that the `Context` hook is different from the React version. For example,
|
|
||||||
there is no concept of provider/consumer. So, the `Context` feature does not
|
|
||||||
by itself allow the use of a different context state depending on the component
|
|
||||||
place in the component tree. However, this functionality can be obtained, if
|
|
||||||
necessary, with the use of sub environment.
|
|
||||||
|
|
||||||
### `useContext`
|
|
||||||
|
|
||||||
The `useContext` hook is the normal way for a component to register themselve
|
|
||||||
to context state changes. The `useContext` method returns the context state:
|
|
||||||
|
|
||||||
```js
|
|
||||||
device = useContext(this.env.deviceContext);
|
|
||||||
```
|
|
||||||
|
|
||||||
It is a simple observed state (with an owl `Observer`), which contains the shared
|
|
||||||
information.
|
|
||||||
@@ -52,7 +52,7 @@ It is sometimes useful to add one (or more) specific keys to the environment,
|
|||||||
from the perspective of a specific component and its children. In that case, the
|
from the perspective of a specific component and its children. In that case, the
|
||||||
solution presented above will not work, since it sets the global environment.
|
solution presented above will not work, since it sets the global environment.
|
||||||
|
|
||||||
There is a hook for this situation: [`useSubEnv`](hooks.md#usesubenv).
|
There are two hooks for this situation: [`useSubEnv` and `useChildSubEnv`](hooks.md#usesubenv-and-usechildsubenv).
|
||||||
|
|
||||||
```js
|
```js
|
||||||
class SomeComponent extends Component {
|
class SomeComponent extends Component {
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
# 🦉 Event Bus 🦉
|
|
||||||
|
|
||||||
It is sometimes useful to use a `Bus` to communicate informations between various
|
|
||||||
parts of the code. Owl has a very simple bus class, which manages subscriptions,
|
|
||||||
triggering events, and callbacks.
|
|
||||||
|
|
||||||
```js
|
|
||||||
const bus = new owl.core.EventBus();
|
|
||||||
|
|
||||||
bus.on("some-event", null, function (...args) {
|
|
||||||
console.log(...args);
|
|
||||||
});
|
|
||||||
|
|
||||||
bus.trigger("some-event", 1, 2, 3);
|
|
||||||
// [1,2,3] will be logged to the console
|
|
||||||
```
|
|
||||||
|
|
||||||
Its API is:
|
|
||||||
|
|
||||||
| Method | Description |
|
|
||||||
| -------------------------------- | --------------------------------- |
|
|
||||||
| `on(eventType, owner, callback)` | add a listener |
|
|
||||||
| `off(eventType, owner)` | remove all listeners for an owner |
|
|
||||||
| `trigger(eventType, ...args)` | trigger an event |
|
|
||||||
| `clear` | remove all subscriptions |
|
|
||||||
@@ -5,6 +5,7 @@
|
|||||||
- [Event Handling](#event-handling)
|
- [Event Handling](#event-handling)
|
||||||
- [Modifiers](#modifiers)
|
- [Modifiers](#modifiers)
|
||||||
- [Synthetic Events](#synthetic-events)
|
- [Synthetic Events](#synthetic-events)
|
||||||
|
- [On Components](#on-components)
|
||||||
|
|
||||||
## Event Handling
|
## Event Handling
|
||||||
|
|
||||||
@@ -100,3 +101,19 @@ To enable it, one can just use the `.synthetic` suffix:
|
|||||||
</t>
|
</t>
|
||||||
</div>
|
</div>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## On Components
|
||||||
|
|
||||||
|
The `t-on` directive also works on a child component:
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<div>
|
||||||
|
in some template
|
||||||
|
<Child t-on-click="dosomething"/>
|
||||||
|
</div>
|
||||||
|
```
|
||||||
|
|
||||||
|
This will catch all click events on any html element contained in the `Child`
|
||||||
|
sub component. Note that if the child component is reduced to one (or more) text
|
||||||
|
nodes, then clicking on it will not call the handler, since the event will be
|
||||||
|
dispatched by the browser on the parent element (a `div` in this case).
|
||||||
|
|||||||
+20
-8
@@ -8,7 +8,7 @@
|
|||||||
- [Other hooks](#other-hooks)
|
- [Other hooks](#other-hooks)
|
||||||
- [`useState`](#usestate)
|
- [`useState`](#usestate)
|
||||||
- [`useRef`](#useref)
|
- [`useRef`](#useref)
|
||||||
- [`useSubEnv`](#usesubenv)
|
- [`useSubEnv` and `useChildSubEnv`](#usesubenv-and-usechildsubenv)
|
||||||
- [`useExternalListener`](#useexternallistener)
|
- [`useExternalListener`](#useexternallistener)
|
||||||
- [`useComponent`](#usecomponent)
|
- [`useComponent`](#usecomponent)
|
||||||
- [`useEnv`](#useenv)
|
- [`useEnv`](#useenv)
|
||||||
@@ -152,14 +152,14 @@ this.ref2 = useRef("component_2");
|
|||||||
References are only guaranteed to be active while the parent component is mounted.
|
References are only guaranteed to be active while the parent component is mounted.
|
||||||
If this is not the case, accessing `el` or `comp` on it will return `null`.
|
If this is not the case, accessing `el` or `comp` on it will return `null`.
|
||||||
|
|
||||||
### `useSubEnv`
|
### `useSubEnv` and `useChildSubEnv`
|
||||||
|
|
||||||
The environment is sometimes useful to share some common information between
|
The environment is sometimes useful to share some common information between
|
||||||
all components. But sometimes, we want to _scope_ that knowledge to a subtree.
|
all components. But sometimes, we want to _scope_ that knowledge to a subtree.
|
||||||
|
|
||||||
For example, if we have a form view component, maybe we would like to make some
|
For example, if we have a form view component, maybe we would like to make some
|
||||||
`model` object available to all sub components, but not to the whole application.
|
`model` object available to all sub components, but not to the whole application.
|
||||||
This is where the `useSubEnv` hook may be useful: it lets a component add some
|
This is where the `useChildSubEnv` hook may be useful: it lets a component add some
|
||||||
information to the environment in a way that only its children
|
information to the environment in a way that only its children
|
||||||
can access it:
|
can access it:
|
||||||
|
|
||||||
@@ -167,15 +167,26 @@ can access it:
|
|||||||
class FormComponent extends Component {
|
class FormComponent extends Component {
|
||||||
setup() {
|
setup() {
|
||||||
const model = makeModel();
|
const model = makeModel();
|
||||||
|
// model will be available on this.env for this component and all children
|
||||||
useSubEnv({ model });
|
useSubEnv({ model });
|
||||||
|
// someKey will be available on this.env for all children
|
||||||
|
useChildSubEnv({ someKey: "value" });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
The `useSubEnv` takes one argument: an object which contains some key/value that
|
The `useSubEnv` and `useChildSubEnv` hooks take one argument: an object which
|
||||||
will be added to the parent environment. Note that it will extend, not replace
|
contains some key/value that will be added to the current environment. These hooks
|
||||||
the parent environment. And of course, the parent environment will not be
|
will create a new env object with the new information:
|
||||||
affected.
|
|
||||||
|
- `useSubEnv` will assign this new `env` to itself and to all children components
|
||||||
|
- `useChildSubEnv` will only assign this new `env` to all children components.
|
||||||
|
|
||||||
|
As usual in Owl, [environments](environment.md) created with these two hooks are
|
||||||
|
frozen, to prevent unwanted modifications.
|
||||||
|
|
||||||
|
Note that both these hooks can be called an arbitrary number of times. The `env`
|
||||||
|
will then be updated accordingly.
|
||||||
|
|
||||||
### `useExternalListener`
|
### `useExternalListener`
|
||||||
|
|
||||||
@@ -223,7 +234,8 @@ are defined by a function instead of just the dependencies.
|
|||||||
|
|
||||||
The `useEffect` hook takes two function: the effect function and the dependency
|
The `useEffect` hook takes two function: the effect function and the dependency
|
||||||
function. The effect function perform some task and return (optionally) a cleanup
|
function. The effect function perform some task and return (optionally) a cleanup
|
||||||
function. The dependency function returns a list of dependencies. If any of these
|
function. The dependency function returns a list of dependencies, these dependencies
|
||||||
|
are passed as parameters in the effect function . If any of these
|
||||||
dependencies changes, then the current effect will be cleaned up and reexecuted.
|
dependencies changes, then the current effect will be cleaned up and reexecuted.
|
||||||
|
|
||||||
Here is an example without any dependencies:
|
Here is an example without any dependencies:
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
# 🦉 Precompiling templates 🦉
|
||||||
|
|
||||||
|
Owl is designed to be used by the Odoo javascript framework. Since Odoo handles
|
||||||
|
its assets in its own non standard way, it was decided/assumed that Owl would
|
||||||
|
compile templates at runtime.
|
||||||
|
|
||||||
|
However, in some cases, it is not optimal, or even worse, not possible to do that.
|
||||||
|
For example, browser extensions do not allow javascript code to create a new
|
||||||
|
function (using the `new Function(...)` syntax).
|
||||||
|
|
||||||
|
Therefore, in these cases, it is required to compile templates ahead of time. It
|
||||||
|
is possible to do that in Owl, but the tooling is still rough. For now, the
|
||||||
|
process is the following:
|
||||||
|
|
||||||
|
1. write your templates in xml files (with a `t-name` directive to declare the name
|
||||||
|
of the template)
|
||||||
|
2. Compile them in a `templates.js` file
|
||||||
|
3. get the `owl.iife.runtime.js` file (which is a owl build without the compiler)
|
||||||
|
4. bundle `owl.iife.runtime.js` and `template.js` with your assets (owl needs to
|
||||||
|
be positioned before the templates)
|
||||||
|
|
||||||
|
Here is a more detailed explanation on how to compile xml files into a js file:
|
||||||
|
|
||||||
|
1. clone the owl repository locally
|
||||||
|
2. `npm install` to install all the required tooling
|
||||||
|
3. `npm run build:runtime` to build the `owl.iife.runtime.js` file
|
||||||
|
4. `npm run build:compiler` to build the template compiler
|
||||||
|
5. `npm run compile_templates -- path/to/your/templates` will scan your target
|
||||||
|
folder, find all xml files, get all templates, compile them, and generate a
|
||||||
|
`templates.js` file.
|
||||||
+10
-1
@@ -159,6 +159,7 @@ For each key, a `prop` definition is either a boolean, a constructor, a list of
|
|||||||
- a boolean: indicate that the props exists, and is mandatory.
|
- a boolean: indicate that the props exists, and is mandatory.
|
||||||
- a constructor: this should describe the type, for example: `id: Number` describe
|
- a constructor: this should describe the type, for example: `id: Number` describe
|
||||||
the props `id` as a number
|
the props `id` as a number
|
||||||
|
- an object describing a value as type. This is done by using the `value` key. For example, `{value: false}` specifies that the corresponding value should be equal to false.
|
||||||
- a list of constructors. In that case, this means that we allow more than one
|
- a list of constructors. In that case, this means that we allow more than one
|
||||||
type. For example, `id: [Number, String]` means that `id` can be either a string
|
type. For example, `id: [Number, String]` means that `id` can be either a string
|
||||||
or a number.
|
or a number.
|
||||||
@@ -168,11 +169,15 @@ For each key, a `prop` definition is either a boolean, a constructor, a list of
|
|||||||
- `shape`: if the type was `Object`, then the `shape` key describes the interface of the object. If it is not set, then we only validate the object, not its elements,
|
- `shape`: if the type was `Object`, then the `shape` key describes the interface of the object. If it is not set, then we only validate the object, not its elements,
|
||||||
- `validate`: this is a function which should return a boolean to determine if
|
- `validate`: this is a function which should return a boolean to determine if
|
||||||
the value is valid or not. Useful for custom validation logic.
|
the value is valid or not. Useful for custom validation logic.
|
||||||
|
- `optional`: if true, the prop is not mandatory
|
||||||
|
|
||||||
There is a special `*` prop that means that additional prop are allowed. This is
|
There is a special `*` prop that means that additional prop are allowed. This is
|
||||||
sometimes useful for generic components that will propagate some or all their
|
sometimes useful for generic components that will propagate some or all their
|
||||||
props to their child components.
|
props to their child components.
|
||||||
|
|
||||||
|
Note that default values cannot be defined for a mandatory props. Doing so will
|
||||||
|
result in a prop validation error.
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
@@ -190,7 +195,8 @@ class ComponentB extends owl.Component {
|
|||||||
element: {type: Object, shape: {id: Boolean, text: String }
|
element: {type: Object, shape: {id: Boolean, text: String }
|
||||||
},
|
},
|
||||||
date: Date,
|
date: Date,
|
||||||
combinedVal: [Number, Boolean]
|
combinedVal: [Number, Boolean],
|
||||||
|
optionalProp: { type: Number, optional: true }
|
||||||
};
|
};
|
||||||
|
|
||||||
...
|
...
|
||||||
@@ -235,9 +241,12 @@ class ComponentB extends owl.Component {
|
|||||||
size: {
|
size: {
|
||||||
validate: e => ["small", "medium", "large"].includes(e)
|
validate: e => ["small", "medium", "large"].includes(e)
|
||||||
},
|
},
|
||||||
|
someId: [Number, {value: false}], // either a number or false
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Note: the props validation code is done by using the [validate utility function](utils.md#validate).
|
||||||
|
|
||||||
## Good Practices
|
## Good Practices
|
||||||
|
|
||||||
A `props` object is a collection of values that come from the parent. As such,
|
A `props` object is a collection of values that come from the parent. As such,
|
||||||
|
|||||||
+348
-33
@@ -2,79 +2,394 @@
|
|||||||
|
|
||||||
## Content
|
## Content
|
||||||
|
|
||||||
- [Overview](#overview)
|
- [Introduction](#introduction)
|
||||||
- [`useState`](#usestate)
|
- [`useState`](#usestate)
|
||||||
- [`reactive`](#reactive)
|
- [`reactive`](#reactive)
|
||||||
|
- [`Escape hatches`](#escape-hatches)
|
||||||
|
- [`Advanced usage`](#advanced-usage)
|
||||||
|
|
||||||
## Overview
|
## Introduction
|
||||||
|
|
||||||
Reactivity is a big topic in javascript frameworks. The goal is to provide a
|
Reactivity is a big topic in javascript frameworks. The goal is to provide a
|
||||||
simple way to manipulate state, in such a way that the interface automatically
|
simple way to manipulate state, in such a way that the interface updates automatically
|
||||||
update accordingly to state changes. Also, we obviously want this to happen in
|
according to state changes, and to do so in a performant manner.
|
||||||
a performant way.
|
|
||||||
|
|
||||||
To solve this issue, Owl provides two reactivity primitives:
|
To this end, Owl provides a proxy-based reactivity system, based on the `reactive` primitive.
|
||||||
|
The `reactive` function takes an object as a first argument, and an optional callback as its second
|
||||||
- `reactive`, which returns a proxy to its first argument, and tracks all read/update
|
argument, it returns a proxy of the object. This proxy tracks what properties are read
|
||||||
operation going through it,
|
through the proxy, and calls the provided callback whenever one of these properties is changed
|
||||||
- `useState`: a hook, that internally uses `reactive`, and is linked to its
|
through any reactive version of the same object. It does so in depth, by returning reactive versions
|
||||||
owner component: any read operation will be tracked (key by key), and any
|
of the subobjects when they are read.
|
||||||
updates to these tracked values will cause the component to be rerendered.
|
|
||||||
|
|
||||||
Most of the time, the `useState` hook is the best solution.
|
|
||||||
|
|
||||||
## `useState`
|
## `useState`
|
||||||
|
|
||||||
Let us start by an example of how `useState` could be used:
|
While the `reactive` primitive is very powerful, its usage in components follow a very standard pattern:
|
||||||
|
components want to be rerendered when part of the state which they depend on for rendering changes. To
|
||||||
|
this end, owl provides a standard hook: `useState`. To put it simply, this hook simply calls reactive
|
||||||
|
with the provided object, and the current component's render function as its callback. This will cause
|
||||||
|
it to rerender whenever any part of the state object that has been read by this component is modified.
|
||||||
|
|
||||||
|
Here is a simple example of how `useState` can be used:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
class Counter extends Component {
|
class Counter extends Component {
|
||||||
static template = xml`
|
static template = xml`
|
||||||
<div t-on-click="increment">
|
<div t-on-click="() => this.state.value++">
|
||||||
<t t-esc="state.value"/>
|
<t t-esc="state.value"/>
|
||||||
</div>`;
|
</div>`;
|
||||||
|
|
||||||
setup() {
|
setup() {
|
||||||
this.state = useState({ value: 0 });
|
this.state = useState({ value: 0 });
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
increment() {
|
This component reads `state.value` when it renders, subscribing it to changes to that key. Whenever
|
||||||
this.state.value++;
|
the value changes, Owl will update the component. Note that there is nothing special about the
|
||||||
|
`state` property, you can name your state variables whatever you want, and you can have multiple of
|
||||||
|
them on the same component if it makes sense to do so. This also allows `useState` to be used in custom
|
||||||
|
hooks that may require state that is specific to that hook.
|
||||||
|
|
||||||
|
### Reactive props
|
||||||
|
|
||||||
|
Since version 2.0, Owl renders are no longer "deep" by default: a component is only rerendered by its
|
||||||
|
parent if its props have changed (using a simple equality test). What if the contents of a props have
|
||||||
|
changed in a deeper property? If that prop is reactive, owl will rerender the child components that
|
||||||
|
need to be updated automatically, and only those components, it does so by reobserving reactive
|
||||||
|
objects passed as props to components. Consider the following example:
|
||||||
|
|
||||||
|
```js
|
||||||
|
class Counter extends Component {
|
||||||
|
static template = xml`
|
||||||
|
<div t-on-click="() => props.state.value++">
|
||||||
|
<t t-esc="props.state.value"/>
|
||||||
|
</div>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
class Parent extends Component {
|
||||||
|
static template = xml`
|
||||||
|
<Counter state="this.state"/>
|
||||||
|
<button t-on-click="() => this.state.value = 0">Reset counter</button>
|
||||||
|
<button t-on-click="() => this.state.test++" t-esc="this.state.test"/>`;
|
||||||
|
|
||||||
|
setup() {
|
||||||
|
this.state = useState({ value: 0, test: 1 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
If one were to use a simple state object, Owl would not be aware that the value
|
When clicking on the counter button, only the Counter rerenders, because the Parent has never read
|
||||||
was changed and that the component should be rerendered. With the `useState`
|
the "value" key in the state. When clicking on the "Reset Counter" button, the same thing happens:
|
||||||
hook, `this.state` is now a reactive object, so this component works as expected.
|
only the Counter component rerenders. What matters is not _where_ the state is updated, but which
|
||||||
|
parts of the state are updated, and which components depend on them. This is achieved by Owl by
|
||||||
|
automatically calling `useState` on reactive objects passed as props to a child component.
|
||||||
|
|
||||||
|
When clicking on the last button, the parent is rerendered, but the child does not care about the
|
||||||
|
`test` key: it has not read it. The props that we give it (`this.state`) have also not changed,
|
||||||
|
as such, the parent updates but the child doesn't.
|
||||||
|
|
||||||
|
For most day-to-day operations, `useState` should cover all of your needs. If
|
||||||
|
you are curious about more advanced use cases and technical details, read on.
|
||||||
|
|
||||||
|
### Debugging subscriptions
|
||||||
|
|
||||||
|
Owl provides a way to show which reactive objects and keys a component is subscribed to: you can
|
||||||
|
look at `component.__owl__.subscriptions`. Note that this is on the internal `__owl__` field, and
|
||||||
|
should not be used in any type of production code as the name of this property or any of its properties
|
||||||
|
or methods are subject to change at any point, even in stable versions of Owl, and may become available
|
||||||
|
only in debug mode in the future.
|
||||||
|
|
||||||
## `reactive`
|
## `reactive`
|
||||||
|
|
||||||
The `reactive` function is the basic reactivity primitive. It takes an object
|
The `reactive` function is the basic reactivity primitive. It takes an object
|
||||||
or an array as first argument, and optionally, a function as the second argument.
|
or an array as first argument, and optionally, a function as the second argument.
|
||||||
The function will be called whenever any tracked value is updated.
|
The function is called whenever any tracked value is updated.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const obj = reactive({ a: 1 }, () => console.log("changed"));
|
const obj = reactive({ a: 1 }, () => console.log("changed"));
|
||||||
|
|
||||||
obj.a = 2; // does not log anything: the 'a' key was not read
|
obj.a = 2; // does not log anything: the 'a' key has not been read yet
|
||||||
console.log(obj.a); // log 2, and reads the 'a' key => it is now tracked
|
console.log(obj.a); // logs 2 and reads the 'a' key => it is now tracked
|
||||||
obj.a = 3; // log 'changed' because we updated a tracked value
|
obj.a = 3; // logs 'changed' because we updated a tracked value
|
||||||
```
|
```
|
||||||
|
|
||||||
An important property of reactive objects is that they can be reobserved: this
|
An important property of reactive objects is that they can be reobserved: this
|
||||||
will create an independant proxy that tracks another set of keys:
|
will create an independent proxy that tracks another set of keys:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const obj1 = reactive({ a: 1, b: 2 }, () => console.log("observer 1"));
|
const obj1 = reactive({ a: 1, b: 2 }, () => console.log("observer 1"));
|
||||||
const obj2 = reactive(obj1, () => console.log("observer 2"));
|
const obj2 = reactive(obj1, () => console.log("observer 2"));
|
||||||
|
|
||||||
console.log(obj1.a); // log 1, and reads the 'a' key => it is now tracked by observer 1
|
console.log(obj1.a); // logs 1, and reads the 'a' key => it is now tracked by observer 1
|
||||||
console.log(obj1.b); // log 2, and 'b' is now tracked by observer 1
|
console.log(obj2.b); // logs 2, and 'b' is now tracked by observer 2
|
||||||
console.log(obj2.b); // log 2, and 'b' is now tracked by observer 1
|
obj2.a = 3; // only logs 'observer1', because observer2 does not track a
|
||||||
obj2.a = 3; // log 'observer1', because observer2 does not track a
|
obj2.b = 3; // only logs 'observer2', because observer1 does not track b
|
||||||
obj2.b = 3; // log 'observer1' and 'observer2'
|
console.log(obj2.a, obj1.b); // logs 3 and 3, while the object is observed independently, it is still a single object
|
||||||
```
|
```
|
||||||
|
|
||||||
Obviously, one can use `reactive` on the result of a `useState` if wanted, this
|
Because `useState` returns a normal reactive object, it is possible to call `reactive` on the result
|
||||||
is the proper way to watch for some state changes.
|
of a `useState` to observe changes to that object while outside the context of a component, or to
|
||||||
|
call `useState` on reactive objects created outside of components. In those cases, one needs to be
|
||||||
|
careful with regards to the lifetime of those reactive objects, as holding references to these
|
||||||
|
objects may prevent garbage collection of the component and its data even if Owl has destroyed it.
|
||||||
|
|
||||||
|
### Subscriptions are ephemereal
|
||||||
|
|
||||||
|
Subscription to state changes are ephemereal, whenever an observer is notified that a state object
|
||||||
|
has changed, all of its subscriptions are cleared, meaning that if it still cares about it, it
|
||||||
|
should read the properties it cares about again. For example:
|
||||||
|
|
||||||
|
```js
|
||||||
|
const obj = reactive({ a: 1 }, () => console.log("observer called"));
|
||||||
|
|
||||||
|
console.log(obj.a); // logs 1, and reads the 'a' key => it is now tracked by the observer
|
||||||
|
obj.a = 3; // logs 'observer1' and clears the subscriptions of the observer
|
||||||
|
obj.a = 4; // doesn't log anything, the key is no longer observed
|
||||||
|
```
|
||||||
|
|
||||||
|
This may seem counter-intuitive, but it makes perfect sense in the context of components:
|
||||||
|
|
||||||
|
```js
|
||||||
|
class DoubleCounter extends Component {
|
||||||
|
static template = xml`
|
||||||
|
<t t-esc="state.selected + ': ' + state[state.selected].value"/>
|
||||||
|
<button t-on-click="() => this.state.count1++">increment count 1</button>
|
||||||
|
<button t-on-click="() => this.state.count2++">increment count 2</button>
|
||||||
|
<button t-on-click="changeCounter">Switch counter</button>
|
||||||
|
`;
|
||||||
|
|
||||||
|
setup() {
|
||||||
|
this.state = useState({ selected: "count1", count1: 0, count2: 0 });
|
||||||
|
}
|
||||||
|
|
||||||
|
changeCounter() {
|
||||||
|
this.state.selected = this.state.selected === "count1" ? "count2" : "count1";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
In this component, if we increment the value of the second counter, the component will not rerender,
|
||||||
|
which makes sense as rerendering will have no effect, as the second counter is not displayed. If we
|
||||||
|
toggle the component to display the second counter, we now no longer want the component to rerender
|
||||||
|
when the value of the first counter changes, and this is what happens: a component only rerenders
|
||||||
|
when there are changes to pieces of state that have been read during or after the previous render.
|
||||||
|
If a piece of state has not been read in the last render, we know that its value won't influence the
|
||||||
|
rendered output, and so we can ignore it.
|
||||||
|
|
||||||
|
### reactive `Map` and `Set`
|
||||||
|
|
||||||
|
The reactivity system has special support built-in for the standard container types `Map` and `Set`.
|
||||||
|
They behave like one would expect: reading a key subscribes the observer to that key, adding or
|
||||||
|
removing an item to them notifies observers that have used any of the iterators on that reactive
|
||||||
|
object, such as `.entries()` or `.keys()`, likewise with clearing them.
|
||||||
|
|
||||||
|
## Escape hatches
|
||||||
|
|
||||||
|
Sometimes, it is desirable to bypass the reactivity system. Creating proxies when interacting with
|
||||||
|
reactive objects is expensive, and while on the whole, the performance benefit that we get by
|
||||||
|
rerendering only the parts of the interface that need it outweighs that cost, in some cases, we want
|
||||||
|
to be able to opt out of creating them in the first place. This is the purpose of `markRaw`:
|
||||||
|
|
||||||
|
### `markRaw`
|
||||||
|
|
||||||
|
Marks an object so that it is ignored by the reactivity system, meaning that if this object is ever
|
||||||
|
part of a of a reactive object, it will be returned as is, and no keys in that object will be
|
||||||
|
observed.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const someObject = markRaw({ b: 1 });
|
||||||
|
const state = useState({
|
||||||
|
a: 1,
|
||||||
|
obj: someObject,
|
||||||
|
});
|
||||||
|
console.log(state.obj.b); // attempt to subscribe to the "b" key in someObject
|
||||||
|
state.obj.b = 2; // No rerender will occur here
|
||||||
|
console.log(someObject === state.obj); // true
|
||||||
|
```
|
||||||
|
|
||||||
|
This is useful in some rare cases. One such example would be if you want to use an array of objects
|
||||||
|
that is potentially large to render a list, but those objects are known to be immutable:
|
||||||
|
|
||||||
|
```js
|
||||||
|
this.items = useState([
|
||||||
|
{ label: "some text", value: 42 },
|
||||||
|
// ... 1000 total objects
|
||||||
|
]);
|
||||||
|
```
|
||||||
|
|
||||||
|
in the template:
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<t t-foreach="items" t-as="item" t-key="item.label" t-esc="item.label + item.value"/>
|
||||||
|
```
|
||||||
|
|
||||||
|
Here, on every render, we go and read one thousand keys from a reactive object, which causes
|
||||||
|
one thousand reactive objects to be created. If we know that the content of these objects
|
||||||
|
cannot change, this is wasted work. If instead all of these objects are marked as raw, we avoid
|
||||||
|
all of this work while keeping the ability to lean on the reactivity to track the presence and
|
||||||
|
identity of these objects:
|
||||||
|
|
||||||
|
```js
|
||||||
|
this.items = useState([
|
||||||
|
markRaw({ label: "some text", value: 42 }),
|
||||||
|
// ... 1000 total objects
|
||||||
|
]);
|
||||||
|
```
|
||||||
|
|
||||||
|
However, use this function with caution: this is an escape hatch from the reactivity
|
||||||
|
system, and as such, using it may cause subtle and unintended issues! For example:
|
||||||
|
|
||||||
|
```js
|
||||||
|
// This will cause a rerender
|
||||||
|
this.items.push(markRaw({ label: "another label", value: 1337 }));
|
||||||
|
|
||||||
|
// THIS WILL NOT CAUSE A RENDER!
|
||||||
|
this.items[17].value = 3;
|
||||||
|
// The UI is now desynced from component's state until the next render caused by something else
|
||||||
|
```
|
||||||
|
|
||||||
|
In short: only use `markRaw` if your application is slowing down noticeably and profiling reveals
|
||||||
|
that a lot of time is spent creating useless reactive objects.
|
||||||
|
|
||||||
|
### `toRaw`
|
||||||
|
|
||||||
|
While `markRaw` marks an object so that it is never made reactive, `toRaw` takes an object and
|
||||||
|
returns the underlying non-reactive object. It can be useful in some niche cases. In particular,
|
||||||
|
because the reactivity system returns a proxy, the returned object does not compare equal to the
|
||||||
|
original object:
|
||||||
|
|
||||||
|
```js
|
||||||
|
const obj = {};
|
||||||
|
const reactiveObj = reactive(obj);
|
||||||
|
console.log(obj === reactiveObj); // false
|
||||||
|
console.log(obj === toRaw(reactiveObj)); // true
|
||||||
|
```
|
||||||
|
|
||||||
|
It can also be useful during debugging, as unfolding proxies recursively in debuggers can be confusing.
|
||||||
|
|
||||||
|
## Advanced usage
|
||||||
|
|
||||||
|
The following is a collection of small snippets that leverage the reactivity system in
|
||||||
|
"non-standard" ways to help you understand its power and where using it might make your code simpler.
|
||||||
|
|
||||||
|
### Notification manager
|
||||||
|
|
||||||
|
Showing notifications is a pretty common need in web applications, you may want to show a
|
||||||
|
notification from any other component within the application, and the notifications should stack on
|
||||||
|
top of one another regardless of which component spawned them, here is how we can leverage the
|
||||||
|
reactivity to accomplish this:
|
||||||
|
|
||||||
|
```js
|
||||||
|
let notificationId = 1;
|
||||||
|
const notifications = reactive({});
|
||||||
|
class NotificationContainer extends Component {
|
||||||
|
static template = xml`
|
||||||
|
<t t-foreach="notifications" t-as="notification" t-key="notification_key" t-esc="notification"/>
|
||||||
|
`;
|
||||||
|
setup() {
|
||||||
|
this.notifications = useState(notifications);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function addNotification(label) {
|
||||||
|
const id = notificationId++;
|
||||||
|
notifications[id] = label;
|
||||||
|
return () => {
|
||||||
|
delete notifications[id];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Here, the `notifications` variable is a reactive object. Notice how we didn't give `reactive` a
|
||||||
|
callback: this is because in this case, all we care about is that adding or removing notifications
|
||||||
|
in the `addNotification` function goes through the reactivity system. The `NotificationContainer`
|
||||||
|
component reobserves this object with `useState`, and is updated whenever notifications are
|
||||||
|
added or removed.
|
||||||
|
|
||||||
|
### Store
|
||||||
|
|
||||||
|
Centralizing application state is a pretty common want/need in web applications. Because of the way
|
||||||
|
the reactivity system works, you can treat any reactive object as a store, and if you call `useState`
|
||||||
|
on it, components automatically observe only the part of the store that they're interested in:
|
||||||
|
|
||||||
|
```js
|
||||||
|
export const store = reactive({
|
||||||
|
list: [],
|
||||||
|
add(item) {
|
||||||
|
this.list.push(item);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export function useStore() {
|
||||||
|
return useState(store);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
In any component:
|
||||||
|
|
||||||
|
```js
|
||||||
|
import { useStore } from "./store";
|
||||||
|
|
||||||
|
class List extends Component {
|
||||||
|
static template = xml`
|
||||||
|
<t t-foreach="store.list" t-as="item" t-key="item" t-esc="item"/>
|
||||||
|
`;
|
||||||
|
setup() {
|
||||||
|
this.store = useStore();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Anywhere in the application:
|
||||||
|
|
||||||
|
```js
|
||||||
|
import { store } from "./store";
|
||||||
|
// Will cause any instance of the List component in the app to update
|
||||||
|
store.add("New list item!");
|
||||||
|
```
|
||||||
|
|
||||||
|
Notice how we can make objects with methods into reactive objects, and when these methods are used
|
||||||
|
to mutate the store contents, it works as expected. And while stores are generally one-off objects,
|
||||||
|
it is entirely possible to make class instances reactive:
|
||||||
|
|
||||||
|
```js
|
||||||
|
class Store {
|
||||||
|
list = [];
|
||||||
|
add(item) {
|
||||||
|
this.list.push(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Essentially equivalent to the previous code
|
||||||
|
export const store = reactive(new Store());
|
||||||
|
```
|
||||||
|
|
||||||
|
Which can be useful to unit test the class separately.
|
||||||
|
|
||||||
|
### Local storage synchronization
|
||||||
|
|
||||||
|
Sometimes, you want to persist some state accross reloads, you can do this by storing it in the
|
||||||
|
`localStorage`, but what if you want to update the `localStorage` item every time the state changes,
|
||||||
|
so that you don't have to manually synchronize the states? Well, you can use the reactivity system
|
||||||
|
to write a custom hook that will do that for you:
|
||||||
|
|
||||||
|
```js
|
||||||
|
function useStoredState(key, initialState) {
|
||||||
|
const state = JSON.parse(localStorage.getItem(key)) || initialState;
|
||||||
|
const store = (obj) => localStorage.setItem(key, JSON.stringify(obj));
|
||||||
|
const reactiveState = reactive(state, () => store(reactiveState));
|
||||||
|
store(reactiveState);
|
||||||
|
return useState(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
class MyComponent extends Component {
|
||||||
|
setup() {
|
||||||
|
this.state = useStoredState("MyComponent.state", { value: 1 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
One important thing to notice is that both times we call `store`, we call it with `reactiveState`,
|
||||||
|
not `state`: we need `store` to read the keys through a reactive object for it to correctly
|
||||||
|
subscribe to state changes. Notice also that we call `store` the first time by hand, as otherwise it
|
||||||
|
will not be subscribed to anything, and no amount of change in the object will cause the reactive
|
||||||
|
callback to be invoked.
|
||||||
|
|||||||
+34
-12
@@ -87,8 +87,8 @@ grandparent of the slot content).
|
|||||||
|
|
||||||
## Default Slot
|
## Default Slot
|
||||||
|
|
||||||
The first element inside the component which is not a named slot will
|
All elements inside the component which are not a named slot will be treated as
|
||||||
be considered the `default` slot. For example:
|
part of the content of the `default` slot. For example:
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
<div t-name="Parent">
|
<div t-name="Parent">
|
||||||
@@ -110,6 +110,7 @@ One can mix default slot and named slots:
|
|||||||
default content
|
default content
|
||||||
<t t-set-slot="footer">
|
<t t-set-slot="footer">
|
||||||
content for footer slot here
|
content for footer slot here
|
||||||
|
</t>
|
||||||
</Child>
|
</Child>
|
||||||
</div>
|
</div>
|
||||||
```
|
```
|
||||||
@@ -209,30 +210,51 @@ use this `Notebook` component:
|
|||||||
</Notebook>
|
</Notebook>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Slot params works like normal props, so one can use the `.bind` suffix to
|
||||||
|
bind a function if needed.
|
||||||
|
|
||||||
## Slot scopes
|
## Slot scopes
|
||||||
|
|
||||||
For other kind of advanced use cases, the content of a slot may depends on some
|
For other kinds of advanced use cases, the content of a slot may depends on some
|
||||||
specific information specific to the generic component. This is the opposite
|
information specific to the generic component. This is the opposite of the slot
|
||||||
of the slot params.
|
params.
|
||||||
|
|
||||||
To solve this kind of problems, one can use the `t-set-scope` directive along
|
To solve this kind of problems, one can use the `t-slot-scope` directive along
|
||||||
with the `t-set-slot`. This defines the name of a variable that can access
|
with the `t-set-slot`. This defines the name of a variable that can access
|
||||||
everything given by the child component:
|
everything given by the child component:
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
<div>
|
<MyComponent>
|
||||||
<t t-set-slot="foo" t-set-scope="scope">
|
<t t-set-slot="foo" t-slot-scope="scope">
|
||||||
content
|
content
|
||||||
<t t-esc="scope.bool"/>
|
<t t-esc="scope.bool"/>
|
||||||
<t t-esc="scope.num"/>
|
<t t-esc="scope.num"/>
|
||||||
</t>
|
</t>
|
||||||
</div>
|
</MyComponent>
|
||||||
```
|
```
|
||||||
|
|
||||||
And the child component that includes the slot can provide values like this:
|
And the child component that includes the slot can provide values like this:
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
<div>
|
<t t-slot="foo" bool="other_var" num="5">
|
||||||
<t t-slot="foo" bool="other_var" num="5">
|
|
||||||
</div>
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
or this:
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<t t-slot="foo" t-props="someObject">
|
||||||
|
```
|
||||||
|
|
||||||
|
In the case of the default slot, you may declare the slot scope directly on the
|
||||||
|
component itself:
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<MyComponent t-slot-scope="scope">
|
||||||
|
content
|
||||||
|
<t t-esc="scope.bool"/>
|
||||||
|
<t t-esc="scope.num"/>
|
||||||
|
</MyComponent>
|
||||||
|
```
|
||||||
|
|
||||||
|
Slot values works like normal props, so one can use the `.bind` suffix to
|
||||||
|
bind a function if needed.
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
- [Fragments](#fragments)
|
- [Fragments](#fragments)
|
||||||
- [Inline templates](#inline-templates)
|
- [Inline templates](#inline-templates)
|
||||||
- [Rendering svg](#rendering-svg)
|
- [Rendering svg](#rendering-svg)
|
||||||
|
- [Restrictions](#restrictions)
|
||||||
|
|
||||||
## Overview
|
## Overview
|
||||||
|
|
||||||
@@ -114,7 +115,7 @@ It is useful to explain the various rules that apply on these expressions:
|
|||||||
<div><p t-if="console.log(1)">NOT valid</p></div>
|
<div><p t-if="console.log(1)">NOT valid</p></div>
|
||||||
```
|
```
|
||||||
|
|
||||||
2. it can use anything in the rendering context (typically, the component):
|
2. it can use anything in the rendering context (which typically contains the properties of the component):
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
<p t-if="user.birthday === today()">Happy bithday!</p>
|
<p t-if="user.birthday === today()">Happy bithday!</p>
|
||||||
@@ -289,10 +290,11 @@ If an expression evaluates to a falsy value, it will not be set at all:
|
|||||||
|
|
||||||
It is sometimes convenient to format an attribute with string interpolation. In
|
It is sometimes convenient to format an attribute with string interpolation. In
|
||||||
that case, the `t-attf-` directive can be used. It is useful when we need to mix
|
that case, the `t-attf-` directive can be used. It is useful when we need to mix
|
||||||
literal and dynamic elements, such as css classes.
|
literal and dynamic elements, such as css classes. The dynamic elements can be
|
||||||
|
specified with either `{{...}}` or `#{...}`:
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
<div t-attf-foo="a {{value1}} is {{value2}} of {{value3}} ]"/>
|
<div t-attf-foo="a {{value1}} is #{value2} of {{value3}} ]"/>
|
||||||
<!-- result if values are set to 1,2 and 3: <div foo="a 0 is 1 of 2 ]"></div> -->
|
<!-- result if values are set to 1,2 and 3: <div foo="a 0 is 1 of 2 ]"></div> -->
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -538,6 +540,14 @@ This can be used to define variables scoped to a sub template:
|
|||||||
<!-- "var" does not exist here -->
|
<!-- "var" does not exist here -->
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Note: by default, the rendering context for a sub template is simply the current
|
||||||
|
rendering context. However, it may be useful to be able to specify a specific
|
||||||
|
object as context. This can be done by using the `t-call-context` directive:
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<t t-call="other-template" t-call-context="obj"/>
|
||||||
|
```
|
||||||
|
|
||||||
### Dynamic sub templates
|
### Dynamic sub templates
|
||||||
|
|
||||||
The `t-call` directive can also be used to dynamically call a sub template,
|
The `t-call` directive can also be used to dynamically call a sub template,
|
||||||
@@ -674,7 +684,19 @@ This `RootNode` component will then display a live SVG representation of the
|
|||||||
graph described by the `graph` property. Note that there is a recursive structure
|
graph described by the `graph` property. Note that there is a recursive structure
|
||||||
here: the `Node` component uses itself as a subcomponent.
|
here: the `Node` component uses itself as a subcomponent.
|
||||||
|
|
||||||
Note that since SVG needs to be handled in a specific way (its namespace needs
|
**Important note:** Owl needs to properly set the namespace for each svg elements.
|
||||||
to be properly set), there is a small constraint for Owl components: if an owl
|
Since Owl compile each template separately, it is not able to determine easily
|
||||||
component is supposed to be a part of an svg graph, then its root node needs to
|
if a template is supposed to be included in a svg namespace or not. Therefore,
|
||||||
be a `g` tag, so Owl can properly set the namespace.
|
Owl depends on a heuristic: if a tag is either `svg`, `g` or `path`, then it will
|
||||||
|
be considered as svg. In practice, this means that each component or each sub
|
||||||
|
templates (included with `t-call`) should have one of these tag as root tag.
|
||||||
|
|
||||||
|
## Restrictions
|
||||||
|
|
||||||
|
Note that Owl templates forbid the use of tag and or attributes starting with
|
||||||
|
the `block-` string. This restriction prevents name collision with the internal
|
||||||
|
code of Owl.
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<div><block-1>this will not be accepted by Owl</block-1></div>
|
||||||
|
```
|
||||||
|
|||||||
@@ -54,6 +54,17 @@ For example, one may want to also translate `data-title` attributes. To do that,
|
|||||||
we can define additional attributes with the `translatableAttributes` option:
|
we can define additional attributes with the `translatableAttributes` option:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const app = new App(Root, { templates, tranaslateFn, translatalbeAttributes: ["data-title"] });
|
const app = new App(Root, { templates, tranaslateFn, translatableAttributes: ["data-title"] });
|
||||||
// ...
|
// ...
|
||||||
```
|
```
|
||||||
|
|
||||||
|
It is also possible to remove an attribute from the default list by prefixing it with `-`:
|
||||||
|
|
||||||
|
```js
|
||||||
|
const app = new App(Root, {
|
||||||
|
templates,
|
||||||
|
tranaslateFn,
|
||||||
|
translatableAttributes: ["data-title", "-title"],
|
||||||
|
});
|
||||||
|
// data-title attribute will be translated, but not title attribute...
|
||||||
|
```
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ functions are all available in the `owl.utils` namespace.
|
|||||||
- [`whenReady`](#whenready): executing code when DOM is ready
|
- [`whenReady`](#whenready): executing code when DOM is ready
|
||||||
- [`loadFile`](#loadfile): loading a file (useful for templates)
|
- [`loadFile`](#loadfile): loading a file (useful for templates)
|
||||||
- [`EventBus`](#eventbus): a simple EventBus
|
- [`EventBus`](#eventbus): a simple EventBus
|
||||||
|
- [`validate`](#validate): a validation function
|
||||||
|
|
||||||
## `whenReady`
|
## `whenReady`
|
||||||
|
|
||||||
@@ -56,3 +57,24 @@ bus.addEventListener("event", () => console.log("something happened"));
|
|||||||
|
|
||||||
bus.trigger("event"); // 'something happened' is logged
|
bus.trigger("event"); // 'something happened' is logged
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## `validate`
|
||||||
|
|
||||||
|
The `validate` function is a function that validates if a given object satisfies a
|
||||||
|
specified schema. It is actually used by Owl itself to perform
|
||||||
|
[props validation](props.md#props-validation). For example:
|
||||||
|
|
||||||
|
```js
|
||||||
|
validate(
|
||||||
|
{ a: "hey" },
|
||||||
|
{
|
||||||
|
id: Number,
|
||||||
|
url: [Boolean, { type: Array, element: Number }],
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// throws an error with the following information:
|
||||||
|
// - unknown key 'a',
|
||||||
|
// - 'id' is missing (should be a number),
|
||||||
|
// - 'url' is missing (should be a boolean or list of numbers),
|
||||||
|
```
|
||||||
|
|||||||
Generated
+5711
File diff suppressed because it is too large
Load Diff
+13
-10
@@ -1,11 +1,10 @@
|
|||||||
{
|
{
|
||||||
"name": "@odoo/owl",
|
"name": "@odoo/owl",
|
||||||
"version": "2.0.0-alpha1",
|
"version": "2.0.7",
|
||||||
"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",
|
|
||||||
"module": "dist/owl.es.js",
|
"module": "dist/owl.es.js",
|
||||||
"types": "dist/types/index.d.ts",
|
"types": "dist/types/owl.d.ts",
|
||||||
"files": [
|
"files": [
|
||||||
"dist"
|
"dist"
|
||||||
],
|
],
|
||||||
@@ -14,6 +13,8 @@
|
|||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build:bundle": "rollup -c --failAfterWarnings",
|
"build:bundle": "rollup -c --failAfterWarnings",
|
||||||
|
"build:runtime": "rollup -c --failAfterWarnings runtime",
|
||||||
|
"build:compiler": "rollup -c --failAfterWarnings compiler",
|
||||||
"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 --testTimeout=5000000",
|
"test:debug": "node --inspect-brk node_modules/.bin/jest --runInBand --watch --testTimeout=5000000",
|
||||||
@@ -24,8 +25,10 @@
|
|||||||
"playground:watch": "npm-run-all --parallel playground:serve \"build:* -- --watch\"",
|
"playground:watch": "npm-run-all --parallel playground: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",
|
"check-formatting": "prettier {src/*.ts,src/**/*.ts,tests/*.ts,tests/**/*.ts,doc/*.md,doc/**/*.md} --check",
|
||||||
|
"lint": "eslint src/**/*.ts tests/**/*.ts",
|
||||||
"publish": "npm run build && npm publish",
|
"publish": "npm run build && npm publish",
|
||||||
"release": "node tools/release.js"
|
"release": "node tools/release.js",
|
||||||
|
"compile_templates": "node tools/compile_xml.js"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -40,25 +43,25 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jest": "^27.0.1",
|
"@types/jest": "^27.0.1",
|
||||||
"@types/node": "^14.11.8",
|
"@types/node": "^14.11.8",
|
||||||
|
"@typescript-eslint/eslint-plugin": "5.48.1",
|
||||||
|
"@typescript-eslint/parser": "5.48.1",
|
||||||
"chalk": "^3.0.0",
|
"chalk": "^3.0.0",
|
||||||
"cpx": "^1.5.0",
|
|
||||||
"current-git-branch": "^1.1.0",
|
"current-git-branch": "^1.1.0",
|
||||||
"git-rev-sync": "^1.12.0",
|
"eslint": "8.31.0",
|
||||||
|
"git-rev-sync": "^3.0.2",
|
||||||
"github-api": "^3.3.0",
|
"github-api": "^3.3.0",
|
||||||
"jest": "^27.1.0",
|
"jest": "^27.1.0",
|
||||||
"jest-diff": "^27.3.1",
|
"jest-diff": "^27.3.1",
|
||||||
"jest-environment-jsdom": "^27.1.0",
|
"jest-environment-jsdom": "^27.1.0",
|
||||||
"live-server": "^1.2.1",
|
|
||||||
"npm-run-all": "^4.1.5",
|
"npm-run-all": "^4.1.5",
|
||||||
"prettier": "2.4.1",
|
"prettier": "2.4.1",
|
||||||
"rollup": "^2.56.3",
|
"rollup": "^2.56.3",
|
||||||
|
"rollup-plugin-dts": "^4.2.2",
|
||||||
"rollup-plugin-terser": "^7.0.2",
|
"rollup-plugin-terser": "^7.0.2",
|
||||||
"rollup-plugin-typescript2": "^0.31.1",
|
"rollup-plugin-typescript2": "^0.31.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": "4.5.2"
|
||||||
"uglify-es": "^3.3.9"
|
|
||||||
},
|
},
|
||||||
"jest": {
|
"jest": {
|
||||||
"testEnvironment": "jsdom",
|
"testEnvironment": "jsdom",
|
||||||
|
|||||||
+4
-23
@@ -1,28 +1,9 @@
|
|||||||
# 🦉 OWL Roadmap 🦉
|
# 🦉 OWL Roadmap 🦉
|
||||||
|
|
||||||
- Current version: 1.4.7
|
- Current version: 2.X
|
||||||
- Status: stable
|
- Status: stable
|
||||||
|
|
||||||
This roadmap is only an attempt at predicting Owl's future. Everything may
|
Owl is currently stable. No (large) improvements is expected in the near future.
|
||||||
change!
|
|
||||||
|
|
||||||
|
|
||||||
### 1.x
|
|
||||||
|
|
||||||
- add chrome and firefox devtools,
|
|
||||||
- fix every bugs,
|
|
||||||
- improve documentation,
|
|
||||||
- small backward compatible improvements.
|
|
||||||
|
|
||||||
### 2.x (2020? 2021? 2022?)
|
|
||||||
|
|
||||||
- stop support for `t-set` directive to define the content of a slot
|
|
||||||
|
|
||||||
Maybe:
|
|
||||||
|
|
||||||
- reimplement vdom to use *block* system, like Vue 3, which should make Owl
|
|
||||||
much faster
|
|
||||||
- refactor `QWeb` to use an intermediate representation (some kind of AST) to
|
|
||||||
allow additional optimisations.
|
|
||||||
|
|
||||||
|
|
||||||
|
Note that we intend to keep maintaining owl, and as such, improvements and/or
|
||||||
|
breaking changes may require a version bump in the future.
|
||||||
|
|||||||
+58
-35
@@ -2,14 +2,18 @@ import pkg from "./package.json";
|
|||||||
import git from "git-rev-sync";
|
import git from "git-rev-sync";
|
||||||
import typescript from 'rollup-plugin-typescript2';
|
import typescript from 'rollup-plugin-typescript2';
|
||||||
import { terser } from "rollup-plugin-terser";
|
import { terser } from "rollup-plugin-terser";
|
||||||
|
import dts from "rollup-plugin-dts";
|
||||||
|
|
||||||
const name = "owl";
|
let input, output;
|
||||||
const extend = true;
|
|
||||||
|
const IIFE_FILENAME = "dist/owl.iife.js";
|
||||||
|
const CJS_FILENAME = "dist/owl.cjs.js";
|
||||||
|
const ES_FILENAME = "dist/owl.es.js";
|
||||||
|
|
||||||
|
if (pkg.module !== ES_FILENAME || pkg.main !== CJS_FILENAME) {
|
||||||
|
throw new Error("package.json has been modified. Build script should be updated accordingly");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Meta data to be added on the __info__ object.
|
|
||||||
* Used to let external tools know the current owl version.
|
|
||||||
*/
|
|
||||||
const outro = `
|
const outro = `
|
||||||
__info__.version = '${pkg.version}';
|
__info__.version = '${pkg.version}';
|
||||||
__info__.date = '${new Date().toISOString()}';
|
__info__.date = '${new Date().toISOString()}';
|
||||||
@@ -17,13 +21,39 @@ __info__.hash = '${git.short()}';
|
|||||||
__info__.url = 'https://github.com/odoo/owl';
|
__info__.url = 'https://github.com/odoo/owl';
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
switch (process.argv[4]) {
|
||||||
|
case "compiler":
|
||||||
|
input = "src/compiler/index.ts",
|
||||||
|
output = [
|
||||||
|
getConfigForFormat('cjs', 'dist/compiler.js', ''),
|
||||||
|
]
|
||||||
|
break;
|
||||||
|
case "runtime":
|
||||||
|
input = "src/runtime/index.ts";
|
||||||
|
output = [
|
||||||
|
getConfigForFormat('esm', addSuffix(ES_FILENAME, 'runtime'), outro),
|
||||||
|
getConfigForFormat('cjs', addSuffix(CJS_FILENAME, 'runtime'), outro),
|
||||||
|
getConfigForFormat('iife', addSuffix(IIFE_FILENAME, 'runtime'), outro),
|
||||||
|
getConfigForFormat('iife', addSuffix(IIFE_FILENAME, 'runtime'), outro, true),
|
||||||
|
]
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
input = "src/index.ts",
|
||||||
|
output = [
|
||||||
|
getConfigForFormat('esm', ES_FILENAME, outro),
|
||||||
|
getConfigForFormat('cjs', CJS_FILENAME, outro),
|
||||||
|
getConfigForFormat('iife', IIFE_FILENAME, outro),
|
||||||
|
getConfigForFormat('iife', IIFE_FILENAME, outro, true),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate from a string depicting a path a new path for the minified version.
|
* Generate from a string depicting a path a new path for the minified version.
|
||||||
* @param {string} pkgFileName file name
|
* @param {string} pkgFileName file name
|
||||||
*/
|
*/
|
||||||
function generateMinifiedNameFromPkgName(pkgFileName) {
|
function addSuffix(pkgFileName, suffix) {
|
||||||
const parts = pkgFileName.split('.');
|
const parts = pkgFileName.split('.');
|
||||||
parts.splice(parts.length - 1, 0, "min");
|
parts.splice(parts.length - 1, 0, suffix);
|
||||||
return parts.join('.');
|
return parts.join('.');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,12 +63,12 @@ function generateMinifiedNameFromPkgName(pkgFileName) {
|
|||||||
* @param {string} generatedFileName generated file name
|
* @param {string} generatedFileName generated file name
|
||||||
* @param {boolean} minified should it be minified
|
* @param {boolean} minified should it be minified
|
||||||
*/
|
*/
|
||||||
function getConfigForFormat(format, generatedFileName, minified = false) {
|
function getConfigForFormat(format, generatedFileName, outro, minified = false) {
|
||||||
return {
|
return {
|
||||||
file: minified ? generateMinifiedNameFromPkgName(generatedFileName) : generatedFileName,
|
file: minified ? addSuffix(generatedFileName, "min") : generatedFileName,
|
||||||
format: format,
|
format: format,
|
||||||
name: name,
|
name: "owl",
|
||||||
extend: extend,
|
extend: true,
|
||||||
outro: outro,
|
outro: outro,
|
||||||
freeze: false,
|
freeze: false,
|
||||||
plugins: minified ? [terser()] : [],
|
plugins: minified ? [terser()] : [],
|
||||||
@@ -46,26 +76,19 @@ function getConfigForFormat(format, generatedFileName, minified = false) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default [
|
||||||
input: "src/index.ts",
|
{
|
||||||
output: [
|
input,
|
||||||
|
output,
|
||||||
/**
|
plugins: [
|
||||||
* Read about module formats:
|
typescript({
|
||||||
* https://auth0.com/blog/javascript-module-systems-showdown/
|
useTsconfigDeclarationDir: true
|
||||||
* https://medium.com/@kelin2025/so-you-wanna-use-es6-modules-714f48b3a953
|
}),
|
||||||
*/
|
]
|
||||||
|
},
|
||||||
getConfigForFormat('esm', pkg.module),
|
{
|
||||||
getConfigForFormat('esm', pkg.module, true),
|
input: "dist/types/index.d.ts",
|
||||||
getConfigForFormat('cjs', pkg.main),
|
output: [{ file: "dist/types/owl.d.ts", format: "es" }],
|
||||||
getConfigForFormat('cjs', pkg.main, true),
|
plugins: [dts()],
|
||||||
getConfigForFormat('iife', pkg.browser),
|
},
|
||||||
getConfigForFormat('iife', pkg.browser, true),
|
];
|
||||||
],
|
|
||||||
plugins: [
|
|
||||||
typescript({
|
|
||||||
useTsconfigDeclarationDir: true
|
|
||||||
}),
|
|
||||||
]
|
|
||||||
};
|
|
||||||
|
|||||||
-105
@@ -1,105 +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, TemplateSetConfig } from "./template_set";
|
|
||||||
import { nodeErrorHandlers } from "../component/error_handling";
|
|
||||||
|
|
||||||
// reimplement dev mode stuff see last change in 0f7a8289a6fb8387c3c1af41c6664b2a8448758f
|
|
||||||
|
|
||||||
export interface Env {
|
|
||||||
[key: string]: any;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface AppConfig extends TemplateSetConfig {
|
|
||||||
env?: Env;
|
|
||||||
props?: any;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
scheduler = new Scheduler();
|
|
||||||
root: ComponentNode | null = null;
|
|
||||||
|
|
||||||
constructor(Root: T, config: AppConfig = {}) {
|
|
||||||
super(config);
|
|
||||||
this.Root = Root;
|
|
||||||
if (config.dev) {
|
|
||||||
console.info(DEV_MSG);
|
|
||||||
}
|
|
||||||
const descrs = Object.getOwnPropertyDescriptors(config.env || {});
|
|
||||||
this.env = Object.freeze(Object.defineProperties({}, descrs));
|
|
||||||
this.props = config.props || {};
|
|
||||||
}
|
|
||||||
|
|
||||||
mount(target: HTMLElement, options?: MountOptions): Promise<InstanceType<T>> {
|
|
||||||
this.checkTarget(target);
|
|
||||||
const node = this.makeNode(this.Root, this.props);
|
|
||||||
const prom = this.mountNode(node, target, options);
|
|
||||||
this.root = node;
|
|
||||||
return prom;
|
|
||||||
}
|
|
||||||
|
|
||||||
checkTarget(target: HTMLElement) {
|
|
||||||
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");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
makeNode(Component: T, props: any): ComponentNode {
|
|
||||||
return new ComponentNode(Component, props, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
mountNode(node: ComponentNode, target: HTMLElement, options?: MountOptions) {
|
|
||||||
const promise: any = new Promise((resolve, reject) => {
|
|
||||||
let isResolved = false;
|
|
||||||
// manually set a onMounted callback.
|
|
||||||
// that way, we are independant from the current node.
|
|
||||||
node.mounted.push(() => {
|
|
||||||
resolve(node.component);
|
|
||||||
isResolved = true;
|
|
||||||
});
|
|
||||||
|
|
||||||
// Manually add the last resort error handler on the node
|
|
||||||
let handlers = nodeErrorHandlers.get(node);
|
|
||||||
if (!handlers) {
|
|
||||||
handlers = [];
|
|
||||||
nodeErrorHandlers.set(node, handlers);
|
|
||||||
}
|
|
||||||
handlers.unshift((e) => {
|
|
||||||
if (isResolved) {
|
|
||||||
console.error(e);
|
|
||||||
} else {
|
|
||||||
reject(e);
|
|
||||||
}
|
|
||||||
throw e;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
node.mountComponent(target, options);
|
|
||||||
return promise;
|
|
||||||
}
|
|
||||||
|
|
||||||
destroy() {
|
|
||||||
if (this.root) {
|
|
||||||
this.root.destroy();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function mount<T extends typeof Component>(
|
|
||||||
C: T,
|
|
||||||
target: HTMLElement,
|
|
||||||
config: AppConfig & MountOptions = {}
|
|
||||||
): Promise<InstanceType<T>> {
|
|
||||||
return new App(C, config).mount(target, config);
|
|
||||||
}
|
|
||||||
@@ -1,203 +0,0 @@
|
|||||||
import { BDom, multi, text, toggler } from "../blockdom";
|
|
||||||
import { validateProps } from "../component/props_validation";
|
|
||||||
import { Markup } from "../utils";
|
|
||||||
import { html } from "../blockdom/index";
|
|
||||||
import { TARGET } from "../reactivity";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 {
|
|
||||||
key = key + "__slot_" + name;
|
|
||||||
const nonReactiveProps = ctx.props && ctx.props[TARGET];
|
|
||||||
const slots = nonReactiveProps ? nonReactiveProps.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;
|
|
||||||
}
|
|
||||||
|
|
||||||
class LazyValue {
|
|
||||||
fn: any;
|
|
||||||
ctx: any;
|
|
||||||
node: any;
|
|
||||||
constructor(fn: any, ctx: any, node: any) {
|
|
||||||
this.fn = fn;
|
|
||||||
this.ctx = capture(ctx);
|
|
||||||
this.node = node;
|
|
||||||
}
|
|
||||||
|
|
||||||
evaluate(): any {
|
|
||||||
return this.fn(this.ctx, this.node);
|
|
||||||
}
|
|
||||||
|
|
||||||
toString() {
|
|
||||||
return this.evaluate().toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 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 (value instanceof LazyValue) {
|
|
||||||
safeKey = `lazy_value`;
|
|
||||||
block = value.evaluate();
|
|
||||||
} 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
let boundFunctions = new WeakMap();
|
|
||||||
|
|
||||||
function bind(ctx: any, fn: Function): Function {
|
|
||||||
let component = ctx.__owl__.component;
|
|
||||||
let boundFnMap = boundFunctions.get(component);
|
|
||||||
if (!boundFnMap) {
|
|
||||||
boundFnMap = new WeakMap();
|
|
||||||
boundFunctions.set(component, boundFnMap);
|
|
||||||
}
|
|
||||||
let boundFn = boundFnMap.get(fn);
|
|
||||||
if (!boundFn) {
|
|
||||||
boundFn = fn.bind(component);
|
|
||||||
boundFnMap.set(fn, boundFn);
|
|
||||||
}
|
|
||||||
return boundFn;
|
|
||||||
}
|
|
||||||
|
|
||||||
type RefMap = { [key: string]: HTMLElement | null };
|
|
||||||
type RefSetter = (el: HTMLElement | null) => void;
|
|
||||||
|
|
||||||
function multiRefSetter(refs: RefMap, name: string): RefSetter {
|
|
||||||
let count = 0;
|
|
||||||
return (el) => {
|
|
||||||
if (el) {
|
|
||||||
count++;
|
|
||||||
if (count > 1) {
|
|
||||||
throw new Error("Cannot have 2 elements with same ref name at the same time");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (count === 0 || el) {
|
|
||||||
refs[name] = el;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export const UTILS = {
|
|
||||||
withDefault,
|
|
||||||
zero: Symbol("zero"),
|
|
||||||
isBoundary,
|
|
||||||
callSlot,
|
|
||||||
capture,
|
|
||||||
withKey,
|
|
||||||
prepareList,
|
|
||||||
setContextValue,
|
|
||||||
multiRefSetter,
|
|
||||||
shallowEqual,
|
|
||||||
toNumber,
|
|
||||||
validateProps,
|
|
||||||
LazyValue,
|
|
||||||
safeOutput,
|
|
||||||
bind,
|
|
||||||
};
|
|
||||||
+501
-317
File diff suppressed because it is too large
Load Diff
@@ -1,15 +1,19 @@
|
|||||||
import type { BDom } from "../blockdom";
|
import type { TemplateSet } from "../runtime/template_set";
|
||||||
|
import type { BDom } from "../runtime/blockdom";
|
||||||
import { CodeGenerator, Config } from "./code_generator";
|
import { CodeGenerator, Config } from "./code_generator";
|
||||||
import { parse } from "./parser";
|
import { parse } from "./parser";
|
||||||
|
|
||||||
export type Template = (context: any, vnode: any, key?: string) => BDom;
|
export type Template = (context: any, vnode: any, key?: string) => BDom;
|
||||||
|
|
||||||
export type TemplateFunction = (blocks: any, utils: any) => Template;
|
export type TemplateFunction = (app: TemplateSet, bdom: any, helpers: any) => Template;
|
||||||
|
|
||||||
interface CompileOptions extends Config {
|
interface CompileOptions extends Config {
|
||||||
name?: string;
|
name?: string;
|
||||||
}
|
}
|
||||||
export function compile(template: string | Node, options: CompileOptions = {}): TemplateFunction {
|
export function compile(
|
||||||
|
template: string | Element,
|
||||||
|
options: CompileOptions = {}
|
||||||
|
): TemplateFunction {
|
||||||
// parsing
|
// parsing
|
||||||
const ast = parse(template);
|
const ast = parse(template);
|
||||||
|
|
||||||
@@ -23,5 +27,5 @@ export function compile(template: string | Node, options: CompileOptions = {}):
|
|||||||
const codeGenerator = new CodeGenerator(ast, { ...options, hasSafeContext });
|
const codeGenerator = new CodeGenerator(ast, { ...options, hasSafeContext });
|
||||||
const code = codeGenerator.generateCode();
|
const code = codeGenerator.generateCode();
|
||||||
// template function
|
// template function
|
||||||
return new Function("bdom, helpers", code) as TemplateFunction;
|
return new Function("app, bdom, helpers", code) as TemplateFunction;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { OwlError } from "../runtime/error_handling";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Owl QWeb Expression Parser
|
* Owl QWeb Expression Parser
|
||||||
*
|
*
|
||||||
@@ -26,7 +28,7 @@
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
const RESERVED_WORDS =
|
const RESERVED_WORDS =
|
||||||
"true,false,NaN,null,undefined,debugger,console,window,in,instanceof,new,function,return,this,eval,void,Math,RegExp,Array,Object,Date".split(
|
"true,false,NaN,null,undefined,debugger,console,window,in,instanceof,new,function,return,eval,void,Math,RegExp,Array,Object,Date".split(
|
||||||
","
|
","
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -85,8 +87,9 @@ const STATIC_TOKEN_MAP: { [key: string]: TKind } = Object.assign(Object.create(n
|
|||||||
});
|
});
|
||||||
|
|
||||||
// note that the space after typeof is relevant. It makes sure that the formatted
|
// note that the space after typeof is relevant. It makes sure that the formatted
|
||||||
// expression has a space after typeof
|
// expression has a space after typeof. Currently we don't support delete and void
|
||||||
const OPERATORS = "...,.,===,==,+,!==,!=,!,||,&&,>=,>,<=,<,?,-,*,/,%,typeof ,=>,=,;,in ".split(",");
|
const OPERATORS =
|
||||||
|
"...,.,===,==,+,!==,!=,!,||,&&,>=,>,<=,<,?,-,*,/,%,typeof ,=>,=,;,in ,new ,|,&,^,~".split(",");
|
||||||
|
|
||||||
type Tokenizer = (expr: string) => Token | false;
|
type Tokenizer = (expr: string) => Token | false;
|
||||||
|
|
||||||
@@ -105,14 +108,14 @@ let tokenizeString: Tokenizer = function (expr) {
|
|||||||
i++;
|
i++;
|
||||||
cur = expr[i];
|
cur = expr[i];
|
||||||
if (!cur) {
|
if (!cur) {
|
||||||
throw new Error("Invalid expression");
|
throw new OwlError("Invalid expression");
|
||||||
}
|
}
|
||||||
s += cur;
|
s += cur;
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
if (expr[i] !== start) {
|
if (expr[i] !== start) {
|
||||||
throw new Error("Invalid expression");
|
throw new OwlError("Invalid expression");
|
||||||
}
|
}
|
||||||
s += start;
|
s += start;
|
||||||
if (start === "`") {
|
if (start === "`") {
|
||||||
@@ -199,24 +202,30 @@ const TOKENIZERS = [
|
|||||||
export function tokenize(expr: string): Token[] {
|
export function tokenize(expr: string): Token[] {
|
||||||
const result: Token[] = [];
|
const result: Token[] = [];
|
||||||
let token: boolean | Token = true;
|
let token: boolean | Token = true;
|
||||||
|
let error: any;
|
||||||
|
let current = expr;
|
||||||
|
|
||||||
while (token) {
|
try {
|
||||||
expr = expr.trim();
|
while (token) {
|
||||||
if (expr) {
|
current = current.trim();
|
||||||
for (let tokenizer of TOKENIZERS) {
|
if (current) {
|
||||||
token = tokenizer(expr);
|
for (let tokenizer of TOKENIZERS) {
|
||||||
if (token) {
|
token = tokenizer(current);
|
||||||
result.push(token);
|
if (token) {
|
||||||
expr = expr.slice(token.size || token.value.length);
|
result.push(token);
|
||||||
break;
|
current = current.slice(token.size || token.value.length);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
token = false;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
token = false;
|
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
error = e; // Silence all errors and throw a generic error below
|
||||||
}
|
}
|
||||||
if (expr.length) {
|
if (current.length || error) {
|
||||||
throw new Error(`Tokenizer error: could not tokenize "${expr}"`);
|
throw new OwlError(`Tokenizer error: could not tokenize \`${expr}\``);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -329,28 +338,38 @@ export function compileExprToArray(expr: string): Token[] {
|
|||||||
// Mark all variables that have been used locally.
|
// Mark all variables that have been used locally.
|
||||||
// This assumes the expression has only one scope (incorrect but "good enough for now")
|
// This assumes the expression has only one scope (incorrect but "good enough for now")
|
||||||
for (const token of tokens) {
|
for (const token of tokens) {
|
||||||
if (token.type === "SYMBOL" && localVars.has(token.value)) {
|
if (token.type === "SYMBOL" && token.varName && localVars.has(token.value)) {
|
||||||
|
token.originalValue = token.value;
|
||||||
|
token.value = `_${token.value}`;
|
||||||
token.isLocal = true;
|
token.isLocal = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return tokens;
|
return tokens;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Leading spaces are trimmed during tokenization, so they need to be added back for some values
|
||||||
|
const paddedValues = new Map([["in ", " in "]]);
|
||||||
|
|
||||||
export function compileExpr(expr: string): string {
|
export function compileExpr(expr: string): string {
|
||||||
return compileExprToArray(expr)
|
return compileExprToArray(expr)
|
||||||
.map((t) => t.value)
|
.map((t) => paddedValues.get(t.value) || t.value)
|
||||||
.join("");
|
.join("");
|
||||||
}
|
}
|
||||||
|
|
||||||
export const INTERP_REGEXP = /\{\{.*?\}\}/g;
|
export const INTERP_REGEXP = /\{\{.*?\}\}|\#\{.*?\}/g;
|
||||||
const INTERP_GROUP_REGEXP = /\{\{.*?\}\}/g;
|
|
||||||
|
|
||||||
export function interpolate(s: string): string {
|
export function replaceDynamicParts(s: string, replacer: (s: string) => string) {
|
||||||
let matches = s.match(INTERP_REGEXP);
|
let matches = s.match(INTERP_REGEXP);
|
||||||
if (matches && matches[0].length === s.length) {
|
if (matches && matches[0].length === s.length) {
|
||||||
return `(${compileExpr(s.slice(2, -2))})`;
|
return `(${replacer(s.slice(2, matches[0][0] === "{" ? -2 : -1))})`;
|
||||||
}
|
}
|
||||||
|
|
||||||
let r = s.replace(INTERP_GROUP_REGEXP, (s) => "${" + compileExpr(s.slice(2, -2)) + "}");
|
let r = s.replace(
|
||||||
|
INTERP_REGEXP,
|
||||||
|
(s) => "${" + replacer(s.slice(2, s[0] === "{" ? -2 : -1)) + "}"
|
||||||
|
);
|
||||||
return "`" + r + "`";
|
return "`" + r + "`";
|
||||||
}
|
}
|
||||||
|
export function interpolate(s: string): string {
|
||||||
|
return replaceDynamicParts(s, compileExpr);
|
||||||
|
}
|
||||||
|
|||||||
+216
-118
@@ -1,7 +1,12 @@
|
|||||||
|
import { OwlError } from "../runtime/error_handling";
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// AST Type definition
|
// AST Type definition
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
export type EventHandlers = { [eventName: string]: string };
|
||||||
|
export type Attrs = { [attrs: string]: string };
|
||||||
|
|
||||||
export const enum ASTType {
|
export const enum ASTType {
|
||||||
Text,
|
Text,
|
||||||
Comment,
|
Comment,
|
||||||
@@ -18,6 +23,7 @@ export const enum ASTType {
|
|||||||
TDebug,
|
TDebug,
|
||||||
TLog,
|
TLog,
|
||||||
TSlot,
|
TSlot,
|
||||||
|
TSetSlot,
|
||||||
TCallBlock,
|
TCallBlock,
|
||||||
TTranslation,
|
TTranslation,
|
||||||
TPortal,
|
TPortal,
|
||||||
@@ -33,23 +39,26 @@ export interface ASTComment {
|
|||||||
value: string;
|
value: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface TModelInfo {
|
||||||
|
baseExpr: string;
|
||||||
|
expr: string;
|
||||||
|
targetAttr: string;
|
||||||
|
eventType: "change" | "click" | "input";
|
||||||
|
shouldTrim: boolean;
|
||||||
|
shouldNumberize: boolean;
|
||||||
|
hasDynamicChildren: boolean;
|
||||||
|
specialInitTargetAttr: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
export interface ASTDomNode {
|
export interface ASTDomNode {
|
||||||
type: ASTType.DomNode;
|
type: ASTType.DomNode;
|
||||||
tag: string;
|
tag: string;
|
||||||
dynamicTag: string | null;
|
|
||||||
attrs: { [key: string]: string };
|
|
||||||
content: AST[];
|
content: AST[];
|
||||||
|
attrs: Attrs | null;
|
||||||
ref: string | null;
|
ref: string | null;
|
||||||
on: { [key: string]: string };
|
on: EventHandlers | null;
|
||||||
model: {
|
model: TModelInfo | null;
|
||||||
baseExpr: string;
|
dynamicTag: string | null;
|
||||||
expr: string;
|
|
||||||
targetAttr: string;
|
|
||||||
specialInitTargetAttr: string | null;
|
|
||||||
eventType: "change" | "click" | "input";
|
|
||||||
shouldTrim: boolean;
|
|
||||||
shouldNumberize: boolean;
|
|
||||||
} | null;
|
|
||||||
ns: string | null;
|
ns: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,13 +99,13 @@ export interface ASTTForEach {
|
|||||||
type: ASTType.TForEach;
|
type: ASTType.TForEach;
|
||||||
collection: string;
|
collection: string;
|
||||||
elem: string;
|
elem: string;
|
||||||
key: string | null;
|
|
||||||
body: AST;
|
body: AST;
|
||||||
memo: string;
|
memo: string;
|
||||||
hasNoFirst: boolean;
|
hasNoFirst: boolean;
|
||||||
hasNoLast: boolean;
|
hasNoLast: boolean;
|
||||||
hasNoIndex: boolean;
|
hasNoIndex: boolean;
|
||||||
hasNoValue: boolean;
|
hasNoValue: boolean;
|
||||||
|
key: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ASTTKey {
|
export interface ASTTKey {
|
||||||
@@ -109,6 +118,16 @@ export interface ASTTCall {
|
|||||||
type: ASTType.TCall;
|
type: ASTType.TCall;
|
||||||
name: string;
|
name: string;
|
||||||
body: AST[] | null;
|
body: AST[] | null;
|
||||||
|
context: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ASTSlotDefinition {
|
||||||
|
type: ASTType.TSetSlot;
|
||||||
|
name: string;
|
||||||
|
content: AST | null;
|
||||||
|
scope: string | null;
|
||||||
|
on: EventHandlers | null;
|
||||||
|
attrs: Attrs | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ASTComponent {
|
export interface ASTComponent {
|
||||||
@@ -116,14 +135,17 @@ export interface ASTComponent {
|
|||||||
name: string;
|
name: string;
|
||||||
isDynamic: boolean;
|
isDynamic: boolean;
|
||||||
dynamicProps: string | null;
|
dynamicProps: string | null;
|
||||||
props: { [name: string]: string };
|
on: EventHandlers | null;
|
||||||
slots: { [name: string]: { content: AST; attrs?: { [key: string]: string }; scope?: string } };
|
props: { [name: string]: string } | null;
|
||||||
|
body: AST | null;
|
||||||
|
// slots: { [name: string]: ASTSlotDefinition } | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ASTSlot {
|
export interface ASTSlot {
|
||||||
type: ASTType.TSlot;
|
type: ASTType.TSlot;
|
||||||
name: string;
|
name: string;
|
||||||
attrs: { [key: string]: string };
|
attrs: Attrs | null;
|
||||||
|
on: EventHandlers | null;
|
||||||
defaultContent: AST | null;
|
defaultContent: AST | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,6 +190,7 @@ export type AST =
|
|||||||
| ASTTKey
|
| ASTTKey
|
||||||
| ASTComponent
|
| ASTComponent
|
||||||
| ASTSlot
|
| ASTSlot
|
||||||
|
| ASTSlotDefinition
|
||||||
| ASTTCallBlock
|
| ASTTCallBlock
|
||||||
| ASTLog
|
| ASTLog
|
||||||
| ASTDebug
|
| ASTDebug
|
||||||
@@ -177,23 +200,35 @@ export type AST =
|
|||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Parser
|
// Parser
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
interface ParsingContext {
|
const cache: WeakMap<Element, AST> = new WeakMap();
|
||||||
inPreTag: boolean;
|
|
||||||
inSVG: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function parse(xml: string | Node): AST {
|
export function parse(xml: string | Element): AST {
|
||||||
const node = xml instanceof Element ? xml : (parseXML(`<t>${xml}</t>`).firstChild! as Element);
|
if (typeof xml === "string") {
|
||||||
normalizeXML(node);
|
const elem = parseXML(`<t>${xml}</t>`).firstChild as Element;
|
||||||
const ctx = { inPreTag: false, inSVG: false };
|
return _parse(elem);
|
||||||
const ast = parseNode(node, ctx);
|
}
|
||||||
|
let ast = cache.get(xml);
|
||||||
if (!ast) {
|
if (!ast) {
|
||||||
return { type: ASTType.Text, value: "" };
|
// we clone here the xml to prevent modifying it in place
|
||||||
|
ast = _parse(xml.cloneNode(true) as Element);
|
||||||
|
cache.set(xml, ast);
|
||||||
}
|
}
|
||||||
return ast;
|
return ast;
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseNode(node: ChildNode, ctx: ParsingContext): AST | null {
|
function _parse(xml: Element): AST {
|
||||||
|
normalizeXML(xml);
|
||||||
|
const ctx = { inPreTag: false, inSVG: false };
|
||||||
|
return parseNode(xml, ctx) || { type: ASTType.Text, value: "" };
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ParsingContext {
|
||||||
|
tModelInfo?: TModelInfo | null;
|
||||||
|
inPreTag: boolean;
|
||||||
|
inSVG: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseNode(node: Node, ctx: ParsingContext): AST | null {
|
||||||
if (!(node instanceof Element)) {
|
if (!(node instanceof Element)) {
|
||||||
return parseTextCommentNode(node, ctx);
|
return parseTextCommentNode(node, ctx);
|
||||||
}
|
}
|
||||||
@@ -208,6 +243,7 @@ function parseNode(node: ChildNode, ctx: ParsingContext): AST | null {
|
|||||||
parseTKey(node, ctx) ||
|
parseTKey(node, ctx) ||
|
||||||
parseTTranslation(node, ctx) ||
|
parseTTranslation(node, ctx) ||
|
||||||
parseTSlot(node, ctx) ||
|
parseTSlot(node, ctx) ||
|
||||||
|
parseTSetSlot(node, ctx) ||
|
||||||
parseTOutNode(node, ctx) ||
|
parseTOutNode(node, ctx) ||
|
||||||
parseComponent(node, ctx) ||
|
parseComponent(node, ctx) ||
|
||||||
parseDOMNode(node, ctx) ||
|
parseDOMNode(node, ctx) ||
|
||||||
@@ -233,7 +269,7 @@ function parseTNode(node: Element, ctx: ParsingContext): AST | null {
|
|||||||
const lineBreakRE = /[\r\n]/;
|
const lineBreakRE = /[\r\n]/;
|
||||||
const whitespaceRE = /\s+/g;
|
const whitespaceRE = /\s+/g;
|
||||||
|
|
||||||
function parseTextCommentNode(node: ChildNode, ctx: ParsingContext): AST | null {
|
function parseTextCommentNode(node: Node, ctx: ParsingContext): AST | null {
|
||||||
if (node.nodeType === Node.TEXT_NODE) {
|
if (node.nodeType === Node.TEXT_NODE) {
|
||||||
let value = node.textContent || "";
|
let value = node.textContent || "";
|
||||||
if (!ctx.inPreTag) {
|
if (!ctx.inPreTag) {
|
||||||
@@ -281,6 +317,8 @@ function parseTDebugLog(node: Element, ctx: ParsingContext): AST | null {
|
|||||||
const hasDotAtTheEnd = /\.[\w_]+\s*$/;
|
const hasDotAtTheEnd = /\.[\w_]+\s*$/;
|
||||||
const hasBracketsAtTheEnd = /\[[^\[]+\]\s*$/;
|
const hasBracketsAtTheEnd = /\[[^\[]+\]\s*$/;
|
||||||
|
|
||||||
|
const ROOT_SVG_TAGS = new Set(["svg", "g", "path"]);
|
||||||
|
|
||||||
function parseDOMNode(node: Element, ctx: ParsingContext): AST | null {
|
function parseDOMNode(node: Element, ctx: ParsingContext): AST | null {
|
||||||
const { tagName } = node;
|
const { tagName } = node;
|
||||||
const dynamicTag = node.getAttribute("t-tag");
|
const dynamicTag = node.getAttribute("t-tag");
|
||||||
@@ -288,33 +326,37 @@ function parseDOMNode(node: Element, ctx: ParsingContext): AST | null {
|
|||||||
if (tagName === "t" && !dynamicTag) {
|
if (tagName === "t" && !dynamicTag) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
if (tagName.startsWith("block-")) {
|
||||||
|
throw new OwlError(`Invalid tag name: '${tagName}'`);
|
||||||
|
}
|
||||||
ctx = Object.assign({}, ctx);
|
ctx = Object.assign({}, ctx);
|
||||||
if (tagName === "pre") {
|
if (tagName === "pre") {
|
||||||
ctx.inPreTag = true;
|
ctx.inPreTag = true;
|
||||||
}
|
}
|
||||||
const shouldAddSVGNS = tagName === "svg" || (tagName === "g" && !ctx.inSVG);
|
const shouldAddSVGNS = ROOT_SVG_TAGS.has(tagName) && !ctx.inSVG;
|
||||||
ctx.inSVG = ctx.inSVG || shouldAddSVGNS;
|
ctx.inSVG = ctx.inSVG || shouldAddSVGNS;
|
||||||
const ns = shouldAddSVGNS ? "http://www.w3.org/2000/svg" : null;
|
const ns = shouldAddSVGNS ? "http://www.w3.org/2000/svg" : null;
|
||||||
const ref = node.getAttribute("t-ref");
|
const ref = node.getAttribute("t-ref");
|
||||||
node.removeAttribute("t-ref");
|
node.removeAttribute("t-ref");
|
||||||
|
|
||||||
const children = parseChildren(node, ctx);
|
|
||||||
|
|
||||||
const nodeAttrsNames = node.getAttributeNames();
|
const nodeAttrsNames = node.getAttributeNames();
|
||||||
const attrs: ASTDomNode["attrs"] = {};
|
let attrs: ASTDomNode["attrs"] = null;
|
||||||
const on: ASTDomNode["on"] = {};
|
let on: EventHandlers | null = null;
|
||||||
let model: ASTDomNode["model"] = null;
|
let model: TModelInfo | null = null;
|
||||||
|
|
||||||
for (let attr of nodeAttrsNames) {
|
for (let attr of nodeAttrsNames) {
|
||||||
const value = node.getAttribute(attr)!;
|
const value = node.getAttribute(attr)!;
|
||||||
if (attr.startsWith("t-on")) {
|
if (attr.startsWith("t-on")) {
|
||||||
if (attr === "t-on") {
|
if (attr === "t-on") {
|
||||||
throw new Error("Missing event name with t-on directive");
|
throw new OwlError("Missing event name with t-on directive");
|
||||||
}
|
}
|
||||||
|
on = on || {};
|
||||||
on[attr.slice(5)] = value;
|
on[attr.slice(5)] = value;
|
||||||
} else if (attr.startsWith("t-model")) {
|
} else if (attr.startsWith("t-model")) {
|
||||||
if (!["input", "select", "textarea"].includes(tagName)) {
|
if (!["input", "select", "textarea"].includes(tagName)) {
|
||||||
throw new Error("The t-model directive only works with <input>, <textarea> and <select>");
|
throw new OwlError(
|
||||||
|
"The t-model directive only works with <input>, <textarea> and <select>"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let baseExpr, expr;
|
let baseExpr, expr;
|
||||||
@@ -327,7 +369,7 @@ function parseDOMNode(node: Element, ctx: ParsingContext): AST | null {
|
|||||||
baseExpr = value.slice(0, index);
|
baseExpr = value.slice(0, index);
|
||||||
expr = value.slice(index + 1, -1);
|
expr = value.slice(index + 1, -1);
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`Invalid t-model expression: "${value}" (it should be assignable)`);
|
throw new OwlError(`Invalid t-model expression: "${value}" (it should be assignable)`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const typeAttr = node.getAttribute("type");
|
const typeAttr = node.getAttribute("type");
|
||||||
@@ -348,16 +390,31 @@ function parseDOMNode(node: Element, ctx: ParsingContext): AST | null {
|
|||||||
targetAttr: isCheckboxInput ? "checked" : "value",
|
targetAttr: isCheckboxInput ? "checked" : "value",
|
||||||
specialInitTargetAttr: isRadioInput ? "checked" : null,
|
specialInitTargetAttr: isRadioInput ? "checked" : null,
|
||||||
eventType,
|
eventType,
|
||||||
|
hasDynamicChildren: false,
|
||||||
shouldTrim: hasTrimMod && (isOtherInput || isTextarea),
|
shouldTrim: hasTrimMod && (isOtherInput || isTextarea),
|
||||||
shouldNumberize: hasNumberMod && (isOtherInput || isTextarea),
|
shouldNumberize: hasNumberMod && (isOtherInput || isTextarea),
|
||||||
};
|
};
|
||||||
} else {
|
if (isSelect) {
|
||||||
if (attr.startsWith("t-") && !attr.startsWith("t-att")) {
|
// don't pollute the original ctx
|
||||||
throw new Error(`Unknown QWeb directive: '${attr}'`);
|
ctx = Object.assign({}, ctx);
|
||||||
|
ctx.tModelInfo = model;
|
||||||
}
|
}
|
||||||
|
} else if (attr.startsWith("block-")) {
|
||||||
|
throw new OwlError(`Invalid attribute: '${attr}'`);
|
||||||
|
} else if (attr !== "t-name") {
|
||||||
|
if (attr.startsWith("t-") && !attr.startsWith("t-att")) {
|
||||||
|
throw new OwlError(`Unknown QWeb directive: '${attr}'`);
|
||||||
|
}
|
||||||
|
const tModel = ctx.tModelInfo;
|
||||||
|
if (tModel && ["t-att-value", "t-attf-value"].includes(attr)) {
|
||||||
|
tModel.hasDynamicChildren = true;
|
||||||
|
}
|
||||||
|
attrs = attrs || {};
|
||||||
attrs[attr] = value;
|
attrs[attr] = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const children = parseChildren(node, ctx);
|
||||||
return {
|
return {
|
||||||
type: ASTType.DomNode,
|
type: ASTType.DomNode,
|
||||||
tag: tagName,
|
tag: tagName,
|
||||||
@@ -400,7 +457,7 @@ function parseTEscNode(node: Element, ctx: ParsingContext): AST | null {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (ast.type === ASTType.TComponent) {
|
if (ast.type === ASTType.TComponent) {
|
||||||
throw new Error("t-esc is not supported on Component nodes");
|
throw new OwlError("t-esc is not supported on Component nodes");
|
||||||
}
|
}
|
||||||
return tesc;
|
return tesc;
|
||||||
}
|
}
|
||||||
@@ -456,7 +513,7 @@ function parseTForEach(node: Element, ctx: ParsingContext): AST | null {
|
|||||||
node.removeAttribute("t-as");
|
node.removeAttribute("t-as");
|
||||||
const key = node.getAttribute("t-key");
|
const key = node.getAttribute("t-key");
|
||||||
if (!key) {
|
if (!key) {
|
||||||
throw new Error(
|
throw new OwlError(
|
||||||
`"Directive t-foreach should always be used with a t-key!" (expression: t-foreach="${collection}" t-as="${elem}")`
|
`"Directive t-foreach should always be used with a t-key!" (expression: t-foreach="${collection}" t-as="${elem}")`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -511,21 +568,23 @@ function parseTCall(node: Element, ctx: ParsingContext): AST | null {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const subTemplate = node.getAttribute("t-call")!;
|
const subTemplate = node.getAttribute("t-call")!;
|
||||||
|
const context = node.getAttribute("t-call-context");
|
||||||
node.removeAttribute("t-call");
|
node.removeAttribute("t-call");
|
||||||
|
node.removeAttribute("t-call-context");
|
||||||
|
|
||||||
if (node.tagName !== "t") {
|
if (node.tagName !== "t") {
|
||||||
const ast = parseNode(node, ctx);
|
const ast = parseNode(node, ctx);
|
||||||
const tcall: AST = { type: ASTType.TCall, name: subTemplate, body: null };
|
const tcall: AST = { type: ASTType.TCall, name: subTemplate, body: null, context };
|
||||||
if (ast && ast.type === ASTType.DomNode) {
|
if (ast && ast.type === ASTType.DomNode) {
|
||||||
ast.content = [tcall];
|
ast.content = [tcall];
|
||||||
return ast;
|
return ast;
|
||||||
}
|
}
|
||||||
if (ast && ast.type === ASTType.TComponent) {
|
// if (ast && ast.type === ASTType.TComponent) {
|
||||||
return {
|
// return {
|
||||||
...ast,
|
// ...ast,
|
||||||
slots: { default: { content: tcall } },
|
// slots: { default: { content: tcall, scope: null, on: null, attrs: null } },
|
||||||
};
|
// };
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
const body = parseChildren(node, ctx);
|
const body = parseChildren(node, ctx);
|
||||||
|
|
||||||
@@ -533,6 +592,7 @@ function parseTCall(node: Element, ctx: ParsingContext): AST | null {
|
|||||||
type: ASTType.TCall,
|
type: ASTType.TCall,
|
||||||
name: subTemplate,
|
name: subTemplate,
|
||||||
body: body.length ? body : null,
|
body: body.length ? body : null,
|
||||||
|
context,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -619,7 +679,6 @@ function parseTSetNode(node: Element, ctx: ParsingContext): AST | null {
|
|||||||
|
|
||||||
// Error messages when trying to use an unsupported directive on a component
|
// Error messages when trying to use an unsupported directive on a component
|
||||||
const directiveErrorMap = new Map([
|
const directiveErrorMap = new Map([
|
||||||
["t-on", "t-on is no longer supported on components. Consider passing a callback in props."],
|
|
||||||
[
|
[
|
||||||
"t-ref",
|
"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-ref is no longer supported on components. Consider exposing only the public part of the component's API through a callback prop.",
|
||||||
@@ -637,7 +696,9 @@ function parseComponent(node: Element, ctx: ParsingContext): AST | null {
|
|||||||
let isDynamic = node.hasAttribute("t-component");
|
let isDynamic = node.hasAttribute("t-component");
|
||||||
|
|
||||||
if (isDynamic && name !== "t") {
|
if (isDynamic && name !== "t") {
|
||||||
throw new Error(`Directive 't-component' can only be used on <t> nodes (used on a <${name}>)`);
|
throw new OwlError(
|
||||||
|
`Directive 't-component' can only be used on <t> nodes (used on a <${name}>)`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(firstLetter === firstLetter.toUpperCase() || isDynamic)) {
|
if (!(firstLetter === firstLetter.toUpperCase() || isDynamic)) {
|
||||||
@@ -651,74 +712,38 @@ function parseComponent(node: Element, ctx: ParsingContext): AST | null {
|
|||||||
const dynamicProps = node.getAttribute("t-props");
|
const dynamicProps = node.getAttribute("t-props");
|
||||||
node.removeAttribute("t-props");
|
node.removeAttribute("t-props");
|
||||||
|
|
||||||
const props: ASTComponent["props"] = {};
|
// const defaultSlotScope = node.getAttribute("t-slot-scope");
|
||||||
|
// node.removeAttribute("t-slot-scope");
|
||||||
|
let on: ASTComponent["on"] = null;
|
||||||
|
|
||||||
|
let props: ASTComponent["props"] = null;
|
||||||
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-")) {
|
||||||
const message = directiveErrorMap.get(name.split("-").slice(0, 2).join("-"));
|
if (name.startsWith("t-on-")) {
|
||||||
throw new Error(message || `unsupported directive on Component: ${name}`);
|
on = on || {};
|
||||||
|
on[name.slice(5)] = value;
|
||||||
|
} else {
|
||||||
|
const message = directiveErrorMap.get(name.split("-").slice(0, 2).join("-"));
|
||||||
|
throw new OwlError(message || `unsupported directive on Component: ${name}`);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
props = props || {};
|
||||||
props[name] = value;
|
props[name] = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const slots: ASTComponent["slots"] = {};
|
let body: ASTComponent["body"] = null;
|
||||||
|
|
||||||
|
// let slots: ASTComponent["slots"] | null = null;
|
||||||
if (node.hasChildNodes()) {
|
if (node.hasChildNodes()) {
|
||||||
const clone = <Element>node.cloneNode(true);
|
body = parseChildNodes(node, ctx);
|
||||||
|
if (!node.querySelector('[t-set-slot]')) {
|
||||||
// named slots
|
body = {type: ASTType.TSetSlot, name: "default", content: body, on: null, attrs: null, scope: null}
|
||||||
const slotNodes = Array.from(clone.querySelectorAll("[t-set-slot]"));
|
|
||||||
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")!;
|
|
||||||
|
|
||||||
// check if this is defined in a sub component (in which case it should
|
|
||||||
// be ignored)
|
|
||||||
let el = slotNode.parentElement!;
|
|
||||||
let isInSubComponent = false;
|
|
||||||
while (el !== clone) {
|
|
||||||
if (el!.hasAttribute("t-component") || el!.tagName[0] === el!.tagName[0].toUpperCase()) {
|
|
||||||
isInSubComponent = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
el = el.parentElement!;
|
|
||||||
}
|
|
||||||
if (isInSubComponent) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
slotNode.removeAttribute("t-set-slot");
|
|
||||||
slotNode.remove();
|
|
||||||
const slotAst = parseNode(slotNode, ctx);
|
|
||||||
if (slotAst) {
|
|
||||||
const slotInfo: any = { content: 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
|
|
||||||
const defaultContent = parseChildNodes(clone, ctx);
|
|
||||||
if (defaultContent) {
|
|
||||||
slots.default = { content: defaultContent };
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return { type: ASTType.TComponent, name, isDynamic, dynamicProps, props, slots };
|
return { type: ASTType.TComponent, name, isDynamic, dynamicProps, props, body, on };
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
@@ -731,19 +756,92 @@ function parseTSlot(node: Element, ctx: ParsingContext): AST | null {
|
|||||||
}
|
}
|
||||||
const name = node.getAttribute("t-slot")!;
|
const name = node.getAttribute("t-slot")!;
|
||||||
node.removeAttribute("t-slot");
|
node.removeAttribute("t-slot");
|
||||||
const attrs: { [key: string]: string } = {};
|
let attrs: Attrs | null = null;
|
||||||
|
let on: ASTComponent["on"] = null;
|
||||||
for (let attributeName of node.getAttributeNames()) {
|
for (let attributeName of node.getAttributeNames()) {
|
||||||
const value = node.getAttribute(attributeName)!;
|
const value = node.getAttribute(attributeName)!;
|
||||||
attrs[attributeName] = value;
|
if (attributeName.startsWith("t-on-")) {
|
||||||
|
on = on || {};
|
||||||
|
on[attributeName.slice(5)] = value;
|
||||||
|
} else {
|
||||||
|
attrs = attrs || {};
|
||||||
|
attrs[attributeName] = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
type: ASTType.TSlot,
|
type: ASTType.TSlot,
|
||||||
name,
|
name,
|
||||||
attrs,
|
attrs,
|
||||||
|
on,
|
||||||
defaultContent: parseChildNodes(node, ctx),
|
defaultContent: parseChildNodes(node, ctx),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parseTSetSlot(node: Element, ctx: ParsingContext): AST | null {
|
||||||
|
if (!node.hasAttribute("t-set-slot")) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// const t = el.ownerDocument.createElement("t");
|
||||||
|
|
||||||
|
// const clone = <Element>node.cloneNode(true);
|
||||||
|
|
||||||
|
// // named slots
|
||||||
|
// const slotNodes = Array.from(clone.querySelectorAll("[t-set-slot]"));
|
||||||
|
// for (let slotNode of slotNodes) {
|
||||||
|
if (node.tagName !== "t") {
|
||||||
|
throw new OwlError(
|
||||||
|
`Directive 't-set-slot' can only be used on <t> nodes (used on a <${node.tagName}>)`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const name = node.getAttribute("t-set-slot")!;
|
||||||
|
|
||||||
|
// // check if this is defined in a sub component (in which case it should
|
||||||
|
// // be ignored)
|
||||||
|
// let el = slotNode.parentElement!;
|
||||||
|
// let isInSubComponent = false;
|
||||||
|
// while (el !== clone) {
|
||||||
|
// if (el!.hasAttribute("t-component") || el!.tagName[0] === el!.tagName[0].toUpperCase()) {
|
||||||
|
// isInSubComponent = true;
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// el = el.parentElement!;
|
||||||
|
// }
|
||||||
|
// if (isInSubComponent) {
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
|
||||||
|
node.removeAttribute("t-set-slot");
|
||||||
|
node.remove();
|
||||||
|
const slotAst = parseNode(node, ctx);
|
||||||
|
let on: ASTSlotDefinition["on"] = null;
|
||||||
|
let attrs: Attrs | null = null;
|
||||||
|
let scope: string | null = null;
|
||||||
|
for (let attributeName of node.getAttributeNames()) {
|
||||||
|
const value = node.getAttribute(attributeName)!;
|
||||||
|
if (attributeName === "t-slot-scope") {
|
||||||
|
scope = value;
|
||||||
|
continue;
|
||||||
|
} else if (attributeName.startsWith("t-on-")) {
|
||||||
|
on = on || {};
|
||||||
|
on[attributeName.slice(5)] = value;
|
||||||
|
} else {
|
||||||
|
attrs = attrs || {};
|
||||||
|
attrs[attributeName] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// slots = slots || {};
|
||||||
|
return { type: ASTType.TSetSlot, name, content: slotAst, on, attrs, scope };
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // default slot
|
||||||
|
// const defaultContent = parseChildNodes(clone, ctx);
|
||||||
|
// slots = slots || {};
|
||||||
|
// // t-set-slot="default" has priority over content
|
||||||
|
// if (defaultContent && !slots.default) {
|
||||||
|
// slots.default = { content: defaultContent, on, attrs: null, scope: defaultSlotScope };
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
function parseTTranslation(node: Element, ctx: ParsingContext): AST | null {
|
function parseTTranslation(node: Element, ctx: ParsingContext): AST | null {
|
||||||
if (node.getAttribute("t-translation") !== "off") {
|
if (node.getAttribute("t-translation") !== "off") {
|
||||||
return null;
|
return null;
|
||||||
@@ -786,7 +884,7 @@ function parseTPortal(node: Element, ctx: ParsingContext): AST | null {
|
|||||||
/**
|
/**
|
||||||
* Parse all the child nodes of a given node and return a list of ast elements
|
* Parse all the child nodes of a given node and return a list of ast elements
|
||||||
*/
|
*/
|
||||||
function parseChildren(node: Node, ctx: ParsingContext): AST[] {
|
function parseChildren(node: Element, ctx: ParsingContext): AST[] {
|
||||||
const children: AST[] = [];
|
const children: AST[] = [];
|
||||||
for (let child of node.childNodes) {
|
for (let child of node.childNodes) {
|
||||||
const childAst = parseNode(child, ctx);
|
const childAst = parseNode(child, ctx);
|
||||||
@@ -805,7 +903,7 @@ function parseChildren(node: Node, ctx: ParsingContext): AST[] {
|
|||||||
* Parse all the child nodes of a given node and return an ast if possible.
|
* Parse all the child nodes of a given node and return an ast if possible.
|
||||||
* In the case there are multiple children, they are wrapped in a astmulti.
|
* In the case there are multiple children, they are wrapped in a astmulti.
|
||||||
*/
|
*/
|
||||||
function parseChildNodes(node: Node, ctx: ParsingContext): AST | null {
|
function parseChildNodes(node: Element, ctx: ParsingContext): AST | null {
|
||||||
const children = parseChildren(node, ctx);
|
const children = parseChildren(node, ctx);
|
||||||
switch (children.length) {
|
switch (children.length) {
|
||||||
case 0:
|
case 0:
|
||||||
@@ -834,7 +932,7 @@ function normalizeTIf(el: Element) {
|
|||||||
let nattr = (name: string) => +!!node.getAttribute(name);
|
let nattr = (name: string) => +!!node.getAttribute(name);
|
||||||
if (prevElem && (pattr("t-if") || pattr("t-elif"))) {
|
if (prevElem && (pattr("t-if") || pattr("t-elif"))) {
|
||||||
if (pattr("t-foreach")) {
|
if (pattr("t-foreach")) {
|
||||||
throw new Error(
|
throw new OwlError(
|
||||||
"t-if cannot stay at the same level as t-foreach when using t-elif or t-else"
|
"t-if cannot stay at the same level as t-foreach when using t-elif or t-else"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -843,19 +941,19 @@ function normalizeTIf(el: Element) {
|
|||||||
return a + b;
|
return a + b;
|
||||||
}) > 1
|
}) > 1
|
||||||
) {
|
) {
|
||||||
throw new Error("Only one conditional branching directive is allowed per node");
|
throw new OwlError("Only one conditional branching directive is allowed per node");
|
||||||
}
|
}
|
||||||
// All text (with only spaces) and comment nodes (nodeType 8) between
|
// All text (with only spaces) and comment nodes (nodeType 8) between
|
||||||
// branch nodes are removed
|
// branch nodes are removed
|
||||||
let textNode;
|
let textNode;
|
||||||
while ((textNode = node.previousSibling) !== prevElem) {
|
while ((textNode = node.previousSibling) !== prevElem) {
|
||||||
if (textNode!.nodeValue!.trim().length && textNode!.nodeType !== 8) {
|
if (textNode!.nodeValue!.trim().length && textNode!.nodeType !== 8) {
|
||||||
throw new Error("text is not allowed between branching directives");
|
throw new OwlError("text is not allowed between branching directives");
|
||||||
}
|
}
|
||||||
textNode!.remove();
|
textNode!.remove();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new Error(
|
throw new OwlError(
|
||||||
"t-elif and t-else directives must be preceded by a t-if or t-elif directive"
|
"t-elif and t-else directives must be preceded by a t-if or t-elif directive"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -876,7 +974,7 @@ function normalizeTEsc(el: Element) {
|
|||||||
);
|
);
|
||||||
for (const el of elements) {
|
for (const el of elements) {
|
||||||
if (el.childNodes.length) {
|
if (el.childNodes.length) {
|
||||||
throw new Error("Cannot have t-esc on a component that already has content");
|
throw new OwlError("Cannot have t-esc on a component that already has content");
|
||||||
}
|
}
|
||||||
const value = el.getAttribute("t-esc");
|
const value = el.getAttribute("t-esc");
|
||||||
el.removeAttribute("t-esc");
|
el.removeAttribute("t-esc");
|
||||||
@@ -930,7 +1028,7 @@ function parseXML(xml: string): XMLDocument {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new Error(msg);
|
throw new OwlError(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
return doc;
|
return doc;
|
||||||
|
|||||||
@@ -1,71 +0,0 @@
|
|||||||
import { getCurrent } from "./component_node";
|
|
||||||
import { nodeErrorHandlers } from "./error_handling";
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
// hooks
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
export function onWillStart(fn: () => Promise<void> | void | any) {
|
|
||||||
const node = getCurrent()!;
|
|
||||||
node.willStart.push(fn.bind(node.component));
|
|
||||||
}
|
|
||||||
|
|
||||||
export function onWillUpdateProps(fn: (nextProps: any) => Promise<void> | void | any) {
|
|
||||||
const node = getCurrent()!;
|
|
||||||
node.willUpdateProps.push(fn.bind(node.component));
|
|
||||||
}
|
|
||||||
|
|
||||||
export function onMounted(fn: () => void | any) {
|
|
||||||
const node = getCurrent()!;
|
|
||||||
node.mounted.push(fn.bind(node.component));
|
|
||||||
}
|
|
||||||
|
|
||||||
export function onWillPatch(fn: () => Promise<void> | any | void) {
|
|
||||||
const node = getCurrent()!;
|
|
||||||
node.willPatch.unshift(fn.bind(node.component));
|
|
||||||
}
|
|
||||||
|
|
||||||
export function onPatched(fn: () => void | any) {
|
|
||||||
const node = getCurrent()!;
|
|
||||||
node.patched.push(fn.bind(node.component));
|
|
||||||
}
|
|
||||||
|
|
||||||
export function onWillUnmount(fn: () => Promise<void> | void | any) {
|
|
||||||
const node = getCurrent()!;
|
|
||||||
node.willUnmount.unshift(fn.bind(node.component));
|
|
||||||
}
|
|
||||||
|
|
||||||
export function onWillDestroy(fn: () => Promise<void> | void | any) {
|
|
||||||
const node = getCurrent()!;
|
|
||||||
node.willDestroy.push(fn.bind(node.component));
|
|
||||||
}
|
|
||||||
|
|
||||||
export function onWillRender(fn: () => void | any) {
|
|
||||||
const node = getCurrent()!;
|
|
||||||
const renderFn = node.renderFn;
|
|
||||||
node.renderFn = () => {
|
|
||||||
fn.call(node.component);
|
|
||||||
return renderFn();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function onRendered(fn: () => void | any) {
|
|
||||||
const node = getCurrent()!;
|
|
||||||
const renderFn = node.renderFn;
|
|
||||||
node.renderFn = () => {
|
|
||||||
const result = renderFn();
|
|
||||||
fn.call(node.component);
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
type OnErrorCallback = (error: any) => void | any;
|
|
||||||
export function onError(callback: OnErrorCallback) {
|
|
||||||
const node = getCurrent()!;
|
|
||||||
let handlers = nodeErrorHandlers.get(node);
|
|
||||||
if (!handlers) {
|
|
||||||
handlers = [];
|
|
||||||
nodeErrorHandlers.set(node, handlers);
|
|
||||||
}
|
|
||||||
handlers.push(callback.bind(node.component));
|
|
||||||
}
|
|
||||||
@@ -1,133 +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
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
function getPropDescription(staticProps: any) {
|
|
||||||
if (staticProps instanceof Array) {
|
|
||||||
return Object.fromEntries(
|
|
||||||
staticProps.map((p) => (p.endsWith("?") ? [p.slice(0, -1), false] : [p, true]))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return staticProps || { "*": true };
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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);
|
|
||||||
|
|
||||||
let propsDef = getPropDescription(ComponentClass.props);
|
|
||||||
const allowAdditionalProps = "*" in propsDef;
|
|
||||||
|
|
||||||
for (let propName in propsDef) {
|
|
||||||
if (propName === "*") {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
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}'`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!allowAdditionalProps) {
|
|
||||||
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,77 +0,0 @@
|
|||||||
import { fibersInError } from "./error_handling";
|
|
||||||
import { Fiber, RootFiber } from "./fibers";
|
|
||||||
import { STATUS } from "./status";
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
// Scheduler
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
export class Scheduler {
|
|
||||||
// capture the value of requestAnimationFrame as soon as possible, to avoid
|
|
||||||
// interactions with other code, such as test frameworks that override them
|
|
||||||
static requestAnimationFrame = window.requestAnimationFrame.bind(window);
|
|
||||||
tasks: Set<RootFiber> = new Set();
|
|
||||||
isRunning: boolean = false;
|
|
||||||
requestAnimationFrame: Window["requestAnimationFrame"];
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
this.requestAnimationFrame = Scheduler.requestAnimationFrame;
|
|
||||||
}
|
|
||||||
|
|
||||||
start() {
|
|
||||||
this.isRunning = true;
|
|
||||||
this.scheduleTasks();
|
|
||||||
}
|
|
||||||
|
|
||||||
stop() {
|
|
||||||
this.isRunning = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
addFiber(fiber: Fiber) {
|
|
||||||
this.tasks.add(fiber.root!);
|
|
||||||
if (!this.isRunning) {
|
|
||||||
this.start();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Process all current tasks. This only applies to the fibers that are ready.
|
|
||||||
* Other tasks are left unchanged.
|
|
||||||
*/
|
|
||||||
flush() {
|
|
||||||
this.tasks.forEach((fiber) => {
|
|
||||||
if (fiber.root !== fiber) {
|
|
||||||
this.tasks.delete(fiber);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const hasError = fibersInError.has(fiber);
|
|
||||||
if (hasError && fiber.counter !== 0) {
|
|
||||||
this.tasks.delete(fiber);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (fiber.node.status === STATUS.DESTROYED) {
|
|
||||||
this.tasks.delete(fiber);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fiber.counter === 0) {
|
|
||||||
if (!hasError) {
|
|
||||||
fiber.complete();
|
|
||||||
}
|
|
||||||
this.tasks.delete(fiber);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (this.tasks.size === 0) {
|
|
||||||
this.stop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
scheduleTasks() {
|
|
||||||
this.requestAnimationFrame(() => {
|
|
||||||
this.flush();
|
|
||||||
if (this.isRunning) {
|
|
||||||
this.scheduleTasks();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+13
-59
@@ -1,62 +1,16 @@
|
|||||||
import { UTILS } from "./app/template_helpers";
|
import { TemplateSet } from "./runtime/template_set";
|
||||||
import {
|
import { compile } from "./compiler";
|
||||||
config,
|
|
||||||
createBlock,
|
|
||||||
html,
|
|
||||||
list,
|
|
||||||
mount as blockMount,
|
|
||||||
multi,
|
|
||||||
patch,
|
|
||||||
remove,
|
|
||||||
text,
|
|
||||||
toggler,
|
|
||||||
comment,
|
|
||||||
} from "./blockdom";
|
|
||||||
import { mainEventHandler } from "./component/handler";
|
|
||||||
import { Portal } from "./portal";
|
|
||||||
export type { Reactive } from "./reactivity";
|
|
||||||
|
|
||||||
config.shouldNormalizeDom = false;
|
export * from "./runtime";
|
||||||
config.mainEventHandler = mainEventHandler;
|
|
||||||
(UTILS as any).Portal = Portal;
|
|
||||||
|
|
||||||
export const blockDom = {
|
TemplateSet.prototype._compileTemplate = function _compileTemplate(
|
||||||
config,
|
name: string,
|
||||||
// bdom entry points
|
template: string | Element
|
||||||
mount: blockMount,
|
) {
|
||||||
patch,
|
return compile(template, {
|
||||||
remove,
|
name,
|
||||||
// bdom block types
|
dev: this.dev,
|
||||||
list,
|
translateFn: this.translateFn,
|
||||||
multi,
|
translatableAttributes: this.translatableAttributes,
|
||||||
text,
|
});
|
||||||
toggler,
|
|
||||||
createBlock,
|
|
||||||
html,
|
|
||||||
comment,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export { App, mount } from "./app/app";
|
|
||||||
export { Component } from "./component/component";
|
|
||||||
export { useComponent } from "./component/component_node";
|
|
||||||
export { status } from "./component/status";
|
|
||||||
export { Memo } from "./memo";
|
|
||||||
export { xml } from "./app/template_set";
|
|
||||||
export { reactive } from "./reactivity";
|
|
||||||
export { useState } from "./component/component_node";
|
|
||||||
export { useEffect, useEnv, useExternalListener, useRef, useSubEnv } from "./hooks";
|
|
||||||
export { EventBus, whenReady, loadFile, markup } from "./utils";
|
|
||||||
export {
|
|
||||||
onWillStart,
|
|
||||||
onMounted,
|
|
||||||
onWillUnmount,
|
|
||||||
onWillUpdateProps,
|
|
||||||
onWillPatch,
|
|
||||||
onPatched,
|
|
||||||
onWillRender,
|
|
||||||
onRendered,
|
|
||||||
onWillDestroy,
|
|
||||||
onError,
|
|
||||||
} from "./component/lifecycle_hooks";
|
|
||||||
|
|
||||||
export const __info__ = {};
|
|
||||||
|
|||||||
-47
@@ -1,47 +0,0 @@
|
|||||||
import { Component } from "./component/component";
|
|
||||||
import type { ComponentNode } from "./component/component_node";
|
|
||||||
import { xml } from "./app/template_set";
|
|
||||||
import { Fiber } from "./component/fibers";
|
|
||||||
|
|
||||||
export class Memo extends Component {
|
|
||||||
static template = xml`<t t-slot="default"/>`;
|
|
||||||
|
|
||||||
constructor(props: any, env: any, node: ComponentNode) {
|
|
||||||
super(props, env, node);
|
|
||||||
|
|
||||||
// prevent patching process conditionally
|
|
||||||
let applyPatch = false;
|
|
||||||
const patchFn = node.patch;
|
|
||||||
node.patch = () => {
|
|
||||||
if (applyPatch) {
|
|
||||||
patchFn.call(node);
|
|
||||||
applyPatch = false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// check props change, and render/apply patch if it changed
|
|
||||||
let prevProps = props;
|
|
||||||
const updateAndRender = node.updateAndRender;
|
|
||||||
node.updateAndRender = function (props: any, parentFiber: Fiber) {
|
|
||||||
const shouldUpdate = !shallowEqual(prevProps, props);
|
|
||||||
if (shouldUpdate) {
|
|
||||||
prevProps = props;
|
|
||||||
updateAndRender.call(node, props, parentFiber);
|
|
||||||
applyPatch = true;
|
|
||||||
}
|
|
||||||
return Promise.resolve();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* we assume that each object have the same set of keys
|
|
||||||
*/
|
|
||||||
function shallowEqual(p1: any, p2: any): boolean {
|
|
||||||
for (let k in p1) {
|
|
||||||
if (k !== "slots" && p1[k] !== p2[k]) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
@@ -1,75 +0,0 @@
|
|||||||
import { onWillUnmount } from "./component/lifecycle_hooks";
|
|
||||||
import { xml } from "./app/template_set";
|
|
||||||
import { BDom, text, VNode } from "./blockdom";
|
|
||||||
import { Component } from "./component/component";
|
|
||||||
|
|
||||||
const VText: any = text("").constructor;
|
|
||||||
|
|
||||||
class VPortal extends VText implements Partial<VNode<VPortal>> {
|
|
||||||
// selector: string;
|
|
||||||
realBDom: BDom | null;
|
|
||||||
target: HTMLElement | null = null;
|
|
||||||
|
|
||||||
constructor(selector: string, realBDom: BDom) {
|
|
||||||
super("");
|
|
||||||
this.selector = selector;
|
|
||||||
this.realBDom = realBDom;
|
|
||||||
}
|
|
||||||
mount(parent: HTMLElement, anchor: ChildNode) {
|
|
||||||
super.mount(parent, anchor);
|
|
||||||
this.target = document.querySelector(this.selector) as any;
|
|
||||||
if (!this.target) {
|
|
||||||
let el: any = this.el;
|
|
||||||
while (el && el.parentElement instanceof HTMLElement) {
|
|
||||||
el = el.parentElement;
|
|
||||||
}
|
|
||||||
this.target = el && el.querySelector(this.selector);
|
|
||||||
if (!this.target) {
|
|
||||||
throw new Error("invalid portal target");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.realBDom!.mount(this.target!, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
beforeRemove() {
|
|
||||||
this.realBDom!.beforeRemove();
|
|
||||||
}
|
|
||||||
remove() {
|
|
||||||
if (this.realBDom) {
|
|
||||||
super.remove();
|
|
||||||
this.realBDom!.remove();
|
|
||||||
this.realBDom = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
patch(other: VPortal) {
|
|
||||||
super.patch(other);
|
|
||||||
if (this.realBDom) {
|
|
||||||
this.realBDom.patch(other.realBDom!, true);
|
|
||||||
} else {
|
|
||||||
this.realBDom = other.realBDom;
|
|
||||||
this.realBDom!.mount(this.target!, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class Portal extends Component {
|
|
||||||
static template = xml`<t t-slot="default"/>`;
|
|
||||||
static props = {
|
|
||||||
target: {
|
|
||||||
type: String,
|
|
||||||
},
|
|
||||||
slots: true,
|
|
||||||
};
|
|
||||||
|
|
||||||
setup() {
|
|
||||||
const node = this.__owl__;
|
|
||||||
const renderFn = node.renderFn;
|
|
||||||
node.renderFn = () => new VPortal(this.props.target, renderFn());
|
|
||||||
onWillUnmount(() => {
|
|
||||||
if (node.bdom) {
|
|
||||||
node.bdom.remove();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,190 +0,0 @@
|
|||||||
import { Callback } from "./utils";
|
|
||||||
|
|
||||||
// Allows to get the target of a Reactive (used for making a new Reactive from the underlying object)
|
|
||||||
export const TARGET = Symbol("Target");
|
|
||||||
// Special key to subscribe to, to be notified of key creation/deletion
|
|
||||||
const KEYCHANGES = Symbol("Key changes");
|
|
||||||
|
|
||||||
type ObjectKey = string | number | symbol;
|
|
||||||
type Target = object;
|
|
||||||
export type Reactive<T extends Target = Target> = T & {
|
|
||||||
[TARGET]: any;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks whether a given value can be made into a reactive object.
|
|
||||||
*
|
|
||||||
* @param value the value to check
|
|
||||||
* @returns whether the value can be made reactive
|
|
||||||
*/
|
|
||||||
function canBeMadeReactive(value: any): boolean {
|
|
||||||
return (
|
|
||||||
typeof value === "object" &&
|
|
||||||
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
|
|
||||||
* called when the given key changes on the target.
|
|
||||||
*
|
|
||||||
* @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 {
|
|
||||||
if (!targetToKeysToCallbacks.get(target)) {
|
|
||||||
targetToKeysToCallbacks.set(target, new Map());
|
|
||||||
}
|
|
||||||
const keyToCallbacks = targetToKeysToCallbacks.get(target)!;
|
|
||||||
if (!keyToCallbacks.get(key)) {
|
|
||||||
keyToCallbacks.set(key, new Set());
|
|
||||||
}
|
|
||||||
keyToCallbacks.get(key)!.add(callback);
|
|
||||||
if (!callbacksToTargets.has(callback)) {
|
|
||||||
callbacksToTargets.set(callback, new Set());
|
|
||||||
}
|
|
||||||
callbacksToTargets.get(callback)!.add(target);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Notify Reactives that are observing a given target that a key has changed on
|
|
||||||
* the target.
|
|
||||||
*
|
|
||||||
* @param target target whose Reactives should be notified that the target was
|
|
||||||
* changed.
|
|
||||||
* @param key the key that changed (or Symbol `KEYCHANGES` if a key was created
|
|
||||||
* or deleted)
|
|
||||||
*/
|
|
||||||
function notifyReactives(target: Target, key: ObjectKey): void {
|
|
||||||
const keyToCallbacks = targetToKeysToCallbacks.get(target);
|
|
||||||
if (!keyToCallbacks) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const callbacks = keyToCallbacks.get(key);
|
|
||||||
if (!callbacks) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Loop on copy because clearReactivesForCallback will modify the set in place
|
|
||||||
for (const callback of [...callbacks]) {
|
|
||||||
clearReactivesForCallback(callback);
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const callbacksToTargets = new WeakMap<Callback, Set<Target>>();
|
|
||||||
/**
|
|
||||||
* Clears all subscriptions of the Reactives associated with a given callback.
|
|
||||||
*
|
|
||||||
* @param callback the callback for which the reactives need to be cleared
|
|
||||||
*/
|
|
||||||
export 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
targetsToClear.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
const reactiveCache = new WeakMap<Target, WeakMap<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);
|
|
||||||
}
|
|
||||||
return reactivesForTarget.get(callback) as Reactive<T>;
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,210 @@
|
|||||||
|
import { Component, ComponentConstructor, Props } from "./component";
|
||||||
|
import { ComponentNode } from "./component_node";
|
||||||
|
import { nodeErrorHandlers, OwlError, handleError } from "./error_handling";
|
||||||
|
import { Fiber, RootFiber, MountOptions } from "./fibers";
|
||||||
|
import { Scheduler } from "./scheduler";
|
||||||
|
import { validateProps } from "./template_helpers";
|
||||||
|
import { TemplateSet, TemplateSetConfig } from "./template_set";
|
||||||
|
import { validateTarget } from "./utils";
|
||||||
|
|
||||||
|
// reimplement dev mode stuff see last change in 0f7a8289a6fb8387c3c1af41c6664b2a8448758f
|
||||||
|
|
||||||
|
export interface Env {
|
||||||
|
[key: string]: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AppConfig<P, E> extends TemplateSetConfig {
|
||||||
|
props?: P;
|
||||||
|
env?: E;
|
||||||
|
test?: boolean;
|
||||||
|
warnIfNoStaticProps?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
let hasBeenLogged = false;
|
||||||
|
|
||||||
|
export const DEV_MSG = () => {
|
||||||
|
const hash = (window as any).owl ? (window as any).owl.__info__.hash : "master";
|
||||||
|
|
||||||
|
return `Owl is running in 'dev' mode.
|
||||||
|
|
||||||
|
This is not suitable for production use.
|
||||||
|
See https://github.com/odoo/owl/blob/${hash}/doc/reference/app.md#configuration for more information.`;
|
||||||
|
};
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface Window {
|
||||||
|
__OWL_DEVTOOLS__: {
|
||||||
|
apps: Set<App>;
|
||||||
|
Fiber: typeof Fiber;
|
||||||
|
RootFiber: typeof RootFiber;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
window.__OWL_DEVTOOLS__ ||= {
|
||||||
|
apps: new Set<App>(),
|
||||||
|
Fiber: Fiber,
|
||||||
|
RootFiber: RootFiber,
|
||||||
|
};
|
||||||
|
|
||||||
|
export class App<
|
||||||
|
T extends abstract new (...args: any) => any = any,
|
||||||
|
P extends object = any,
|
||||||
|
E = any
|
||||||
|
> extends TemplateSet {
|
||||||
|
static validateTarget = validateTarget;
|
||||||
|
|
||||||
|
Root: ComponentConstructor<P, E>;
|
||||||
|
props: P;
|
||||||
|
env: E;
|
||||||
|
scheduler = new Scheduler();
|
||||||
|
root: ComponentNode<P, E> | null = null;
|
||||||
|
warnIfNoStaticProps: boolean;
|
||||||
|
|
||||||
|
constructor(Root: ComponentConstructor<P, E>, config: AppConfig<P, E> = {}) {
|
||||||
|
super(config);
|
||||||
|
this.Root = Root;
|
||||||
|
window.__OWL_DEVTOOLS__.apps.add(this);
|
||||||
|
if (config.test) {
|
||||||
|
this.dev = true;
|
||||||
|
}
|
||||||
|
this.warnIfNoStaticProps = config.warnIfNoStaticProps || false;
|
||||||
|
if (this.dev && !config.test && !hasBeenLogged) {
|
||||||
|
console.info(DEV_MSG());
|
||||||
|
hasBeenLogged = true;
|
||||||
|
}
|
||||||
|
const env = config.env || {};
|
||||||
|
const descrs = Object.getOwnPropertyDescriptors(env);
|
||||||
|
this.env = Object.freeze(Object.create(Object.getPrototypeOf(env), descrs));
|
||||||
|
this.props = config.props || ({} as P);
|
||||||
|
}
|
||||||
|
|
||||||
|
mount(target: HTMLElement, options?: MountOptions): Promise<Component<P, E> & InstanceType<T>> {
|
||||||
|
App.validateTarget(target);
|
||||||
|
if (this.dev) {
|
||||||
|
validateProps(this.Root, this.props, { __owl__: { app: this } });
|
||||||
|
}
|
||||||
|
const node = this.makeNode(this.Root, this.props);
|
||||||
|
const prom = this.mountNode(node, target, options);
|
||||||
|
this.root = node;
|
||||||
|
return prom;
|
||||||
|
}
|
||||||
|
|
||||||
|
makeNode(Component: ComponentConstructor, props: any): ComponentNode {
|
||||||
|
return new ComponentNode(Component, props, this, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
mountNode(node: ComponentNode, target: HTMLElement, options?: MountOptions) {
|
||||||
|
const promise: any = new Promise((resolve, reject) => {
|
||||||
|
let isResolved = false;
|
||||||
|
// manually set a onMounted callback.
|
||||||
|
// that way, we are independant from the current node.
|
||||||
|
node.mounted.push(() => {
|
||||||
|
resolve(node.component);
|
||||||
|
isResolved = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Manually add the last resort error handler on the node
|
||||||
|
let handlers = nodeErrorHandlers.get(node);
|
||||||
|
if (!handlers) {
|
||||||
|
handlers = [];
|
||||||
|
nodeErrorHandlers.set(node, handlers);
|
||||||
|
}
|
||||||
|
handlers.unshift((e) => {
|
||||||
|
if (!isResolved) {
|
||||||
|
reject(e);
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
node.mountComponent(target, options);
|
||||||
|
return promise;
|
||||||
|
}
|
||||||
|
|
||||||
|
destroy() {
|
||||||
|
if (this.root) {
|
||||||
|
this.scheduler.flush();
|
||||||
|
this.root.destroy();
|
||||||
|
}
|
||||||
|
window.__OWL_DEVTOOLS__.apps.delete(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
createComponent<P extends Props>(
|
||||||
|
name: string | null,
|
||||||
|
isStatic: boolean,
|
||||||
|
hasSlotsProp: boolean,
|
||||||
|
hasDynamicPropList: boolean,
|
||||||
|
hasNoProp: boolean
|
||||||
|
) {
|
||||||
|
const isDynamic = !isStatic;
|
||||||
|
function _arePropsDifferent(props1: Props, props2: Props): boolean {
|
||||||
|
for (let k in props1) {
|
||||||
|
if (props1[k] !== props2[k]) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return hasDynamicPropList && Object.keys(props1).length !== Object.keys(props2).length;
|
||||||
|
}
|
||||||
|
const arePropsDifferent = hasSlotsProp
|
||||||
|
? (_1: any, _2: any) => true
|
||||||
|
: hasNoProp
|
||||||
|
? (_1: any, _2: any) => false
|
||||||
|
: _arePropsDifferent;
|
||||||
|
const updateAndRender = ComponentNode.prototype.updateAndRender;
|
||||||
|
const initiateRender = ComponentNode.prototype.initiateRender;
|
||||||
|
|
||||||
|
return (props: P, key: string, ctx: ComponentNode, parent: any, C: any) => {
|
||||||
|
let children = ctx.children;
|
||||||
|
let node: any = children[key];
|
||||||
|
if (isDynamic && node && node.component.constructor !== C) {
|
||||||
|
node = undefined;
|
||||||
|
}
|
||||||
|
const parentFiber = ctx.fiber!;
|
||||||
|
if (node) {
|
||||||
|
if (arePropsDifferent(node.props, props) || parentFiber.deep || node.forceNextRender) {
|
||||||
|
node.forceNextRender = false;
|
||||||
|
updateAndRender.call(node, props, parentFiber);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// new component
|
||||||
|
if (isStatic) {
|
||||||
|
const components = parent.constructor.components;
|
||||||
|
if (!components) {
|
||||||
|
throw new OwlError(
|
||||||
|
`Cannot find the definition of component "${name}", missing static components key in parent`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
C = components[name as any];
|
||||||
|
if (!C) {
|
||||||
|
throw new OwlError(`Cannot find the definition of component "${name}"`);
|
||||||
|
} else if (!(C.prototype instanceof Component)) {
|
||||||
|
throw new OwlError(
|
||||||
|
`"${name}" is not a Component. It must inherit from the Component class`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
node = new ComponentNode(C, props, this, ctx, key);
|
||||||
|
children[key] = node;
|
||||||
|
initiateRender.call(node, new Fiber(node, parentFiber));
|
||||||
|
}
|
||||||
|
parentFiber.childrenMap[key] = node;
|
||||||
|
return node;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
handleError(...args: Parameters<typeof handleError>) {
|
||||||
|
return handleError(...args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function mount<
|
||||||
|
T extends abstract new (...args: any) => any = any,
|
||||||
|
P extends object = any,
|
||||||
|
E = any
|
||||||
|
>(
|
||||||
|
C: T & ComponentConstructor<P, E>,
|
||||||
|
target: HTMLElement,
|
||||||
|
config: AppConfig<P, E> & MountOptions = {}
|
||||||
|
): Promise<Component<P, E> & InstanceType<T>> {
|
||||||
|
return new App(C, config).mount(target, config);
|
||||||
|
}
|
||||||
@@ -93,6 +93,10 @@ function toClassObj(expr: string | number | { [c: string]: any }) {
|
|||||||
for (let key in expr as any) {
|
for (let key in expr as any) {
|
||||||
const value = (expr as any)[key];
|
const value = (expr as any)[key];
|
||||||
if (value) {
|
if (value) {
|
||||||
|
key = trim.call(key);
|
||||||
|
if (!key) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
const words = split.call(key, wordRegexp);
|
const words = split.call(key, wordRegexp);
|
||||||
for (let word of words) {
|
for (let word of words) {
|
||||||
result[word] = value;
|
result[word] = value;
|
||||||
@@ -139,7 +143,8 @@ export function updateClass(this: HTMLElement, val: any, oldVal: any) {
|
|||||||
|
|
||||||
export function makePropSetter(name: string): Setter<HTMLElement> {
|
export function makePropSetter(name: string): Setter<HTMLElement> {
|
||||||
return function setProp(this: HTMLElement, value: any) {
|
return function setProp(this: HTMLElement, value: any) {
|
||||||
(this as any)[name] = value;
|
// support 0, fallback to empty string for other falsy values
|
||||||
|
(this as any)[name] = value === 0 ? 0 : value ? value.valueOf() : "";
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { OwlError } from "../error_handling";
|
||||||
import {
|
import {
|
||||||
attrsSetter,
|
attrsSetter,
|
||||||
attrsUpdater,
|
attrsUpdater,
|
||||||
@@ -156,6 +157,15 @@ function buildTree(
|
|||||||
: document.createElement(tagName);
|
: document.createElement(tagName);
|
||||||
}
|
}
|
||||||
if (el instanceof Element) {
|
if (el instanceof Element) {
|
||||||
|
if (!domParentTree) {
|
||||||
|
// some html elements may have side effects when setting their attributes.
|
||||||
|
// For example, setting the src attribute of an <img/> will trigger a
|
||||||
|
// request to get the corresponding image. This is something that we
|
||||||
|
// don't want at compile time. We avoid that by putting the content of
|
||||||
|
// the block in a <template/> element
|
||||||
|
const fragment = document.createElement("template").content;
|
||||||
|
fragment.appendChild(el);
|
||||||
|
}
|
||||||
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;
|
||||||
@@ -245,7 +255,7 @@ function buildTree(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new Error("boom");
|
throw new OwlError("boom");
|
||||||
}
|
}
|
||||||
|
|
||||||
function addRef(tree: IntermediateTree) {
|
function addRef(tree: IntermediateTree) {
|
||||||
@@ -299,12 +309,13 @@ interface BlockCtx {
|
|||||||
locations: IndexedLocation[];
|
locations: IndexedLocation[];
|
||||||
children: Child[];
|
children: Child[];
|
||||||
cbRefs: number[];
|
cbRefs: number[];
|
||||||
|
refList: (() => void)[][];
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildContext(tree: IntermediateTree, ctx?: BlockCtx, fromIdx?: number): BlockCtx {
|
function buildContext(tree: IntermediateTree, ctx?: BlockCtx, fromIdx?: number): BlockCtx {
|
||||||
if (!ctx) {
|
if (!ctx) {
|
||||||
const children = new Array(tree.info.filter((v) => v.type === "child").length);
|
const children = new Array(tree.info.filter((v) => v.type === "child").length);
|
||||||
ctx = { collectors: [], locations: [], children, cbRefs: [], refN: tree.refN };
|
ctx = { collectors: [], locations: [], children, cbRefs: [], refN: tree.refN, refList: [] };
|
||||||
fromIdx = 0;
|
fromIdx = 0;
|
||||||
}
|
}
|
||||||
if (tree.refN) {
|
if (tree.refN) {
|
||||||
@@ -408,11 +419,11 @@ function updateCtx(ctx: BlockCtx, tree: IntermediateTree) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "ref":
|
case "ref":
|
||||||
ctx.cbRefs.push(info.idx);
|
const index = ctx.cbRefs.push(info.idx) - 1;
|
||||||
ctx.locations.push({
|
ctx.locations.push({
|
||||||
idx: info.idx,
|
idx: info.idx,
|
||||||
refIdx: info.refIdx!,
|
refIdx: info.refIdx!,
|
||||||
setData: setRef,
|
setData: makeRefSetter(index, ctx.refList),
|
||||||
updateData: NO_OP,
|
updateData: NO_OP,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -426,12 +437,21 @@ function buildBlock(template: HTMLElement, ctx: BlockCtx): BlockType {
|
|||||||
let B = createBlockClass(template, ctx);
|
let B = createBlockClass(template, ctx);
|
||||||
|
|
||||||
if (ctx.cbRefs.length) {
|
if (ctx.cbRefs.length) {
|
||||||
const refs = ctx.cbRefs;
|
const cbRefs = ctx.cbRefs;
|
||||||
|
const refList = ctx.refList;
|
||||||
|
let cbRefsNumber = cbRefs.length;
|
||||||
B = class extends B {
|
B = class extends B {
|
||||||
|
mount(parent: HTMLElement, afterNode: Node | null) {
|
||||||
|
refList.push(new Array(cbRefsNumber));
|
||||||
|
super.mount(parent, afterNode);
|
||||||
|
for (let cbRef of refList.pop()!) {
|
||||||
|
cbRef();
|
||||||
|
}
|
||||||
|
}
|
||||||
remove() {
|
remove() {
|
||||||
super.remove();
|
super.remove();
|
||||||
for (let ref of refs) {
|
for (let cbRef of cbRefs) {
|
||||||
let fn = (this as any).data[ref];
|
let fn = (this as any).data[cbRef];
|
||||||
fn(null);
|
fn(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -476,12 +496,12 @@ function createBlockClass(template: HTMLElement, ctx: BlockCtx): BlockClass {
|
|||||||
const nodeInsertBefore = nodeProto.insertBefore;
|
const nodeInsertBefore = nodeProto.insertBefore;
|
||||||
const elementRemove = elementProto.remove;
|
const elementRemove = elementProto.remove;
|
||||||
|
|
||||||
return class Block {
|
class Block {
|
||||||
el: HTMLElement | undefined;
|
el: HTMLElement | undefined;
|
||||||
refs: Node[] | undefined;
|
|
||||||
data: any[] | undefined;
|
|
||||||
parentEl?: HTMLElement | undefined;
|
parentEl?: HTMLElement | undefined;
|
||||||
|
data: any[] | undefined;
|
||||||
children?: (VNode | undefined)[];
|
children?: (VNode | undefined)[];
|
||||||
|
refs: Node[] | undefined;
|
||||||
|
|
||||||
constructor(data?: any[]) {
|
constructor(data?: any[]) {
|
||||||
this.data = data;
|
this.data = data;
|
||||||
@@ -497,51 +517,71 @@ function createBlockClass(template: HTMLElement, ctx: BlockCtx): BlockClass {
|
|||||||
return this.el!;
|
return this.el!;
|
||||||
}
|
}
|
||||||
|
|
||||||
moveBefore(other: Block | null, afterNode: Node | null) {
|
moveBeforeDOMNode(node: Node | null, parent = this.parentEl) {
|
||||||
const target = other ? other.el! : afterNode;
|
this.parentEl = parent;
|
||||||
nodeInsertBefore.call(this.parentEl, this.el!, target);
|
nodeInsertBefore.call(parent, this.el!, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
moveBeforeVNode(other: Block | null, afterNode: Node | null) {
|
||||||
|
nodeInsertBefore.call(this.parentEl, this.el!, other ? other.el! : afterNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
toString() {
|
||||||
|
const div = document.createElement("div");
|
||||||
|
this.mount(div, null);
|
||||||
|
return div.innerHTML;
|
||||||
}
|
}
|
||||||
|
|
||||||
mount(parent: HTMLElement, afterNode: Node | null) {
|
mount(parent: HTMLElement, afterNode: Node | null) {
|
||||||
const el = nodeCloneNode.call(template, true);
|
const el = nodeCloneNode.call(template, true) as HTMLElement;
|
||||||
nodeInsertBefore.call(parent, el, afterNode);
|
nodeInsertBefore.call(parent, el, afterNode);
|
||||||
if (isDynamic) {
|
this.el = el;
|
||||||
// collecting references
|
this.parentEl = parent;
|
||||||
const refs: Node[] = new Array(refN);
|
}
|
||||||
this.refs = refs;
|
patch(other: Block, withBeforeRemove: boolean) {}
|
||||||
refs[0] = el;
|
}
|
||||||
for (let i = 0; i < colN; i++) {
|
|
||||||
const w = collectors[i];
|
|
||||||
refs[w.idx] = w.getVal.call(refs[w.prevIdx]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// applying data to all update points
|
if (isDynamic) {
|
||||||
if (locN) {
|
Block.prototype.mount = function mount(parent: HTMLElement, afterNode: Node | null) {
|
||||||
const data = this.data!;
|
const el = nodeCloneNode.call(template, true);
|
||||||
for (let i = 0; i < locN; i++) {
|
// collecting references
|
||||||
const loc = locations[i];
|
const refs: Node[] = new Array(refN);
|
||||||
loc.setData.call(refs[loc.refIdx], data[i]);
|
this.refs = refs;
|
||||||
}
|
refs[0] = el;
|
||||||
}
|
for (let i = 0; i < colN; i++) {
|
||||||
|
const w = collectors[i];
|
||||||
|
refs[w.idx] = w.getVal.call(refs[w.prevIdx]);
|
||||||
|
}
|
||||||
|
|
||||||
// preparing all children
|
// applying data to all update points
|
||||||
if (childN) {
|
if (locN) {
|
||||||
const children = this.children;
|
const data = this.data!;
|
||||||
for (let i = 0; i < childN; i++) {
|
for (let i = 0; i < locN; i++) {
|
||||||
const child = children![i];
|
const loc = locations[i];
|
||||||
if (child) {
|
loc.setData.call(refs[loc.refIdx], data[i]);
|
||||||
const loc = childrenLocs[i];
|
}
|
||||||
const afterNode = loc.afterRefIdx ? refs[loc.afterRefIdx] : null;
|
}
|
||||||
child.isOnlyChild = loc.isOnlyChild;
|
|
||||||
child.mount(refs[loc.parentRefIdx] as any, afterNode);
|
nodeInsertBefore.call(parent, el, afterNode);
|
||||||
}
|
|
||||||
|
// preparing all children
|
||||||
|
if (childN) {
|
||||||
|
const children = this.children;
|
||||||
|
for (let i = 0; i < childN; i++) {
|
||||||
|
const child = children![i];
|
||||||
|
if (child) {
|
||||||
|
const loc = childrenLocs[i];
|
||||||
|
const afterNode = loc.afterRefIdx ? refs[loc.afterRefIdx] : null;
|
||||||
|
child.isOnlyChild = loc.isOnlyChild;
|
||||||
|
child.mount(refs[loc.parentRefIdx] as any, afterNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.el = el as HTMLElement;
|
this.el = el as HTMLElement;
|
||||||
this.parentEl = parent;
|
this.parentEl = parent;
|
||||||
}
|
};
|
||||||
patch(other: Block, withBeforeRemove: boolean) {
|
|
||||||
|
Block.prototype.patch = function patch(other: Block, withBeforeRemove: boolean) {
|
||||||
if (this === other) {
|
if (this === other) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -586,19 +626,17 @@ function createBlockClass(template: HTMLElement, ctx: BlockCtx): BlockClass {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
toString() {
|
}
|
||||||
const div = document.createElement("div");
|
return Block;
|
||||||
this.mount(div, null);
|
|
||||||
return div.innerHTML;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function setText(this: Text, value: any) {
|
function setText(this: Text, value: any) {
|
||||||
characterDataSetData.call(this, toText(value));
|
characterDataSetData.call(this, toText(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
function setRef(this: HTMLElement, fn: any) {
|
function makeRefSetter(index: number, refs: (() => void)[][]): Setter<HTMLElement> {
|
||||||
fn(this);
|
return function setRef(this: HTMLElement, fn: any) {
|
||||||
|
refs[refs.length - 1][index] = () => fn(this);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
import { createEventHandler } from "./events";
|
||||||
|
import type { VNode } from "./index";
|
||||||
|
|
||||||
|
type EventsSpec = { [name: string]: number };
|
||||||
|
|
||||||
|
type Catcher = (child: VNode, handlers: any[]) => VNode;
|
||||||
|
|
||||||
|
export function createCatcher(eventsSpec: EventsSpec): Catcher {
|
||||||
|
const n = Object.keys(eventsSpec).length;
|
||||||
|
|
||||||
|
class VCatcher {
|
||||||
|
child: VNode;
|
||||||
|
handlerData: any[];
|
||||||
|
handlerFns: any[] = [];
|
||||||
|
|
||||||
|
parentEl?: HTMLElement | undefined;
|
||||||
|
afterNode: Text | null = null;
|
||||||
|
|
||||||
|
constructor(child: VNode, handlers: any[]) {
|
||||||
|
this.child = child;
|
||||||
|
this.handlerData = handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
mount(parent: HTMLElement, afterNode: Node | null) {
|
||||||
|
this.parentEl = parent;
|
||||||
|
this.child.mount(parent, afterNode);
|
||||||
|
this.afterNode = document.createTextNode("");
|
||||||
|
parent.insertBefore(this.afterNode, afterNode);
|
||||||
|
this.wrapHandlerData();
|
||||||
|
for (let name in eventsSpec) {
|
||||||
|
const index = eventsSpec[name];
|
||||||
|
const handler = createEventHandler(name);
|
||||||
|
this.handlerFns[index] = handler;
|
||||||
|
handler.setup.call(parent, this.handlerData[index]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wrapHandlerData() {
|
||||||
|
for (let i = 0; i < n; i++) {
|
||||||
|
let handler = this.handlerData[i];
|
||||||
|
// handler = [...mods, fn, comp], so we need to replace second to last elem
|
||||||
|
let idx = handler.length - 2;
|
||||||
|
let origFn = handler[idx];
|
||||||
|
const self = this;
|
||||||
|
handler[idx] = function (ev: any) {
|
||||||
|
const target = ev.target;
|
||||||
|
let currentNode: any = self.child.firstNode();
|
||||||
|
const afterNode = self.afterNode;
|
||||||
|
while (currentNode && currentNode !== afterNode) {
|
||||||
|
if (currentNode.contains(target)) {
|
||||||
|
return origFn.call(this, ev);
|
||||||
|
}
|
||||||
|
currentNode = currentNode.nextSibling;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
moveBeforeDOMNode(node: Node | null, parent = this.parentEl) {
|
||||||
|
this.parentEl = parent;
|
||||||
|
this.child.moveBeforeDOMNode(node, parent);
|
||||||
|
parent!.insertBefore(this.afterNode!, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
moveBeforeVNode(other: VCatcher | null, afterNode: Node | null) {
|
||||||
|
if (other) {
|
||||||
|
// check this with @ged-odoo for use in foreach
|
||||||
|
afterNode = other.firstNode() || afterNode;
|
||||||
|
}
|
||||||
|
this.child.moveBeforeVNode(other ? other.child : null, afterNode);
|
||||||
|
this.parentEl!.insertBefore(this.afterNode!, afterNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
patch(other: VCatcher, withBeforeRemove: boolean) {
|
||||||
|
if (this === other) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.handlerData = other.handlerData;
|
||||||
|
this.wrapHandlerData();
|
||||||
|
for (let i = 0; i < n; i++) {
|
||||||
|
this.handlerFns[i].update.call(this.parentEl!, this.handlerData[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.child.patch(other.child, withBeforeRemove);
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeRemove() {
|
||||||
|
this.child.beforeRemove();
|
||||||
|
}
|
||||||
|
|
||||||
|
remove() {
|
||||||
|
for (let i = 0; i < n; i++) {
|
||||||
|
this.handlerFns[i].remove.call(this.parentEl!);
|
||||||
|
}
|
||||||
|
this.child.remove();
|
||||||
|
this.afterNode!.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
firstNode(): Node | undefined {
|
||||||
|
return this.child.firstNode();
|
||||||
|
}
|
||||||
|
|
||||||
|
toString(): string {
|
||||||
|
return this.child.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return function (child: VNode, handlers: any[]): VNode<VCatcher> {
|
||||||
|
return new VCatcher(child, handlers);
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ type EventHandlerSetter = (this: HTMLElement, data: any) => void;
|
|||||||
interface EventHandlerCreator {
|
interface EventHandlerCreator {
|
||||||
setup: EventHandlerSetter;
|
setup: EventHandlerSetter;
|
||||||
update: EventHandlerSetter;
|
update: EventHandlerSetter;
|
||||||
|
remove: (this: HTMLElement) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createEventHandler(rawEvent: string): EventHandlerCreator {
|
export function createEventHandler(rawEvent: string): EventHandlerCreator {
|
||||||
@@ -26,8 +27,8 @@ function createElementHandler(evName: string, capture: boolean = false): EventHa
|
|||||||
}
|
}
|
||||||
|
|
||||||
function listener(ev: Event) {
|
function listener(ev: Event) {
|
||||||
const currentTarget = ev.currentTarget;
|
const currentTarget = ev.currentTarget as HTMLElement;
|
||||||
if (!currentTarget || !document.contains(currentTarget as HTMLElement)) return;
|
if (!currentTarget || !currentTarget.ownerDocument.contains(currentTarget)) return;
|
||||||
const data = (currentTarget as any)[eventKey];
|
const data = (currentTarget as any)[eventKey];
|
||||||
if (!data) return;
|
if (!data) return;
|
||||||
config.mainEventHandler(data, ev, currentTarget);
|
config.mainEventHandler(data, ev, currentTarget);
|
||||||
@@ -38,11 +39,15 @@ function createElementHandler(evName: string, capture: boolean = false): EventHa
|
|||||||
this.addEventListener(evName, listener, { capture });
|
this.addEventListener(evName, listener, { capture });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function remove(this: HTMLElement) {
|
||||||
|
delete (this as any)[eventKey];
|
||||||
|
this.removeEventListener(evName, listener, { capture });
|
||||||
|
}
|
||||||
function update(this: HTMLElement, data: any) {
|
function update(this: HTMLElement, data: any) {
|
||||||
(this as any)[eventKey] = data;
|
(this as any)[eventKey] = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
return { setup, update };
|
return { setup, update, remove };
|
||||||
}
|
}
|
||||||
|
|
||||||
// Synthetic handler: a form of event delegation that allows placing only one
|
// Synthetic handler: a form of event delegation that allows placing only one
|
||||||
@@ -60,7 +65,12 @@ function createSyntheticHandler(evName: string, capture: boolean = false): Event
|
|||||||
_data[currentId] = data;
|
_data[currentId] = data;
|
||||||
(this as any)[eventKey] = _data;
|
(this as any)[eventKey] = _data;
|
||||||
}
|
}
|
||||||
return { setup, update: setup };
|
|
||||||
|
function remove(this: HTMLElement) {
|
||||||
|
delete (this as any)[eventKey];
|
||||||
|
}
|
||||||
|
|
||||||
|
return { setup, update: setup, remove };
|
||||||
}
|
}
|
||||||
|
|
||||||
function nativeToSyntheticEvent(eventKey: string, event: Event) {
|
function nativeToSyntheticEvent(eventKey: string, event: Event) {
|
||||||
@@ -29,14 +29,18 @@ class VHtml {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
moveBefore(other: VHtml | null, afterNode: Node | null) {
|
moveBeforeDOMNode(node: Node | null, parent = this.parentEl) {
|
||||||
const target = other ? other.content[0] : afterNode;
|
this.parentEl = parent;
|
||||||
const parent = this.parentEl;
|
|
||||||
for (let elem of this.content) {
|
for (let elem of this.content) {
|
||||||
nodeInsertBefore.call(parent, elem, target);
|
nodeInsertBefore.call(parent, elem, node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
moveBeforeVNode(other: VHtml | null, afterNode: Node | null) {
|
||||||
|
const target = other ? other.content[0] : afterNode;
|
||||||
|
this.moveBeforeDOMNode(target);
|
||||||
|
}
|
||||||
|
|
||||||
patch(other: VHtml) {
|
patch(other: VHtml) {
|
||||||
if (this === other) {
|
if (this === other) {
|
||||||
return;
|
return;
|
||||||
@@ -61,6 +65,7 @@ class VHtml {
|
|||||||
// remove current content
|
// remove current content
|
||||||
this.remove();
|
this.remove();
|
||||||
this.content = content;
|
this.content = content;
|
||||||
|
this.html = other.html;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -6,10 +6,12 @@ export { list } from "./list";
|
|||||||
export { multi } from "./multi";
|
export { multi } from "./multi";
|
||||||
export { text, comment } from "./text";
|
export { text, comment } from "./text";
|
||||||
export { html } from "./html";
|
export { html } from "./html";
|
||||||
|
export { createCatcher } from "./event_catcher";
|
||||||
|
|
||||||
export interface VNode<T = any> {
|
export interface VNode<T = any> {
|
||||||
mount(parent: HTMLElement, afterNode: Node | null): void;
|
mount(parent: HTMLElement, afterNode: Node | null): void;
|
||||||
moveBefore(other: T | null, afterNode: Node | null): void;
|
moveBeforeDOMNode(node: Node | null, parent?: HTMLElement): void;
|
||||||
|
moveBeforeVNode(other: T | null, afterNode: Node | null): void;
|
||||||
patch(other: T, withBeforeRemove: boolean): void;
|
patch(other: T, withBeforeRemove: boolean): void;
|
||||||
beforeRemove(): void;
|
beforeRemove(): void;
|
||||||
remove(): void;
|
remove(): void;
|
||||||
@@ -38,14 +38,23 @@ class VList {
|
|||||||
this.parentEl = parent;
|
this.parentEl = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
moveBefore(other: VList | null, afterNode: Node | null) {
|
moveBeforeDOMNode(node: Node | null, parent = this.parentEl) {
|
||||||
|
this.parentEl = parent;
|
||||||
|
const children = this.children;
|
||||||
|
for (let i = 0, l = children.length; i < l; i++) {
|
||||||
|
children[i].moveBeforeDOMNode(node, parent);
|
||||||
|
}
|
||||||
|
parent!.insertBefore(this.anchor!, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
moveBeforeVNode(other: VList | null, afterNode: Node | null) {
|
||||||
if (other) {
|
if (other) {
|
||||||
const next = other!.children[0];
|
const next = other!.children[0];
|
||||||
afterNode = (next ? next.firstNode() : other!.anchor) || null;
|
afterNode = (next ? next.firstNode() : other!.anchor) || null;
|
||||||
}
|
}
|
||||||
const children = this.children;
|
const children = this.children;
|
||||||
for (let i = 0, l = children.length; i < l; i++) {
|
for (let i = 0, l = children.length; i < l; i++) {
|
||||||
children[i].moveBefore(null, afterNode);
|
children[i].moveBeforeVNode(null, afterNode);
|
||||||
}
|
}
|
||||||
this.parentEl!.insertBefore(this.anchor!, afterNode);
|
this.parentEl!.insertBefore(this.anchor!, afterNode);
|
||||||
}
|
}
|
||||||
@@ -66,7 +75,7 @@ class VList {
|
|||||||
patch: cPatch,
|
patch: cPatch,
|
||||||
remove: cRemove,
|
remove: cRemove,
|
||||||
beforeRemove,
|
beforeRemove,
|
||||||
moveBefore: cMoveBefore,
|
moveBeforeVNode: cMoveBefore,
|
||||||
firstNode: cFirstNode,
|
firstNode: cFirstNode,
|
||||||
} = proto;
|
} = proto;
|
||||||
|
|
||||||
@@ -38,7 +38,22 @@ export class VMulti {
|
|||||||
this.parentEl = parent;
|
this.parentEl = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
moveBefore(other: VMulti | null, afterNode: Node | null) {
|
moveBeforeDOMNode(node: Node | null, parent = this.parentEl) {
|
||||||
|
this.parentEl = parent;
|
||||||
|
const children = this.children;
|
||||||
|
const anchors = this.anchors;
|
||||||
|
for (let i = 0, l = children.length; i < l; i++) {
|
||||||
|
let child = children[i];
|
||||||
|
if (child) {
|
||||||
|
child.moveBeforeDOMNode(node, parent);
|
||||||
|
} else {
|
||||||
|
const anchor = anchors![i];
|
||||||
|
nodeInsertBefore.call(parent, anchor, node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
moveBeforeVNode(other: VMulti | null, afterNode: Node | null) {
|
||||||
if (other) {
|
if (other) {
|
||||||
const next = other!.children[0];
|
const next = other!.children[0];
|
||||||
afterNode = (next ? next.firstNode() : other!.anchors![0]) || null;
|
afterNode = (next ? next.firstNode() : other!.anchors![0]) || null;
|
||||||
@@ -49,7 +64,7 @@ export class VMulti {
|
|||||||
for (let i = 0, l = children.length; i < l; i++) {
|
for (let i = 0, l = children.length; i < l; i++) {
|
||||||
let child = children[i];
|
let child = children[i];
|
||||||
if (child) {
|
if (child) {
|
||||||
child.moveBefore(null, afterNode);
|
child.moveBeforeVNode(null, afterNode);
|
||||||
} else {
|
} else {
|
||||||
const anchor = anchors![i];
|
const anchor = anchors![i];
|
||||||
nodeInsertBefore.call(parent, anchor, afterNode);
|
nodeInsertBefore.call(parent, anchor, afterNode);
|
||||||
@@ -9,11 +9,11 @@ const characterDataSetData = getDescriptor(characterDataProto, "data").set!;
|
|||||||
const nodeRemoveChild = nodeProto.removeChild;
|
const nodeRemoveChild = nodeProto.removeChild;
|
||||||
|
|
||||||
abstract class VSimpleNode {
|
abstract class VSimpleNode {
|
||||||
text: string;
|
text: string | String;
|
||||||
parentEl?: HTMLElement | undefined;
|
parentEl?: HTMLElement | undefined;
|
||||||
el?: any;
|
el?: any;
|
||||||
|
|
||||||
constructor(text: string) {
|
constructor(text: string | String) {
|
||||||
this.text = text;
|
this.text = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,9 +23,13 @@ abstract class VSimpleNode {
|
|||||||
this.el = node;
|
this.el = node;
|
||||||
}
|
}
|
||||||
|
|
||||||
moveBefore(other: VText | null, afterNode: Node | null) {
|
moveBeforeDOMNode(node: Node | null, parent = this.parentEl) {
|
||||||
const target = other ? other.el! : afterNode;
|
this.parentEl = parent;
|
||||||
nodeInsertBefore.call(this.parentEl, this.el!, target);
|
nodeInsertBefore.call(parent, this.el!, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
moveBeforeVNode(other: VText | null, afterNode: Node | null) {
|
||||||
|
nodeInsertBefore.call(this.parentEl, this.el!, other ? other.el! : afterNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
beforeRemove() {}
|
beforeRemove() {}
|
||||||
@@ -65,7 +69,7 @@ class VComment extends VSimpleNode {
|
|||||||
patch() {}
|
patch() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function text(str: string): VNode<VText> {
|
export function text(str: string | String): VNode<VText> {
|
||||||
return new VText(str);
|
return new VText(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -20,8 +20,12 @@ class VToggler {
|
|||||||
this.child.mount(parent, afterNode);
|
this.child.mount(parent, afterNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
moveBefore(other: VToggler | null, afterNode: Node | null) {
|
moveBeforeDOMNode(node: Node | null, parent?: HTMLElement) {
|
||||||
this.child.moveBefore(other ? other.child : null, afterNode);
|
this.child.moveBeforeDOMNode(node, parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
moveBeforeVNode(other: VToggler | null, afterNode: Node | null) {
|
||||||
|
this.moveBeforeDOMNode((other && other.firstNode()) || afterNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
patch(other: VToggler, withBeforeRemove: boolean) {
|
patch(other: VToggler, withBeforeRemove: boolean) {
|
||||||
@@ -1,12 +1,30 @@
|
|||||||
|
import { Schema } from "./validation";
|
||||||
import type { ComponentNode } from "./component_node";
|
import type { ComponentNode } from "./component_node";
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Component Class
|
// Component Class
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
export type Props = { [key: string]: any };
|
||||||
|
|
||||||
|
interface StaticComponentProperties {
|
||||||
|
template: string;
|
||||||
|
defaultProps?: any;
|
||||||
|
props?: Schema;
|
||||||
|
components?: { [componentName: string]: ComponentConstructor };
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ComponentConstructor<P extends Props = any, E = any> = (new (
|
||||||
|
props: P,
|
||||||
|
env: E,
|
||||||
|
node: ComponentNode
|
||||||
|
) => Component<P, E>) &
|
||||||
|
StaticComponentProperties;
|
||||||
|
|
||||||
export class Component<Props = any, Env = any> {
|
export class Component<Props = any, Env = any> {
|
||||||
static template: string = "";
|
static template: string = "";
|
||||||
static props?: any;
|
static props?: any;
|
||||||
|
static defaultProps?: any;
|
||||||
|
|
||||||
props: Props;
|
props: Props;
|
||||||
env: Env;
|
env: Env;
|
||||||
@@ -20,7 +38,7 @@ export class Component<Props = any, Env = any> {
|
|||||||
|
|
||||||
setup() {}
|
setup() {}
|
||||||
|
|
||||||
render(force: boolean = false) {
|
render(deep: boolean = false) {
|
||||||
this.__owl__.render(force);
|
this.__owl__.render(deep === true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,23 +1,18 @@
|
|||||||
import type { App, Env } from "../app/app";
|
import type { App, Env } from "./app";
|
||||||
import { BDom, VNode } from "../blockdom";
|
import { BDom, VNode } from "./blockdom";
|
||||||
import { clearReactivesForCallback, Reactive, reactive, TARGET } from "../reactivity";
|
import { Component, ComponentConstructor, Props } from "./component";
|
||||||
import { batched, Callback } from "../utils";
|
import { fibersInError, OwlError } from "./error_handling";
|
||||||
import { Component } from "./component";
|
import { Fiber, makeChildFiber, makeRootFiber, MountFiber, MountOptions } from "./fibers";
|
||||||
import { fibersInError, handleError } from "./error_handling";
|
import { clearReactivesForCallback, getSubscriptions, reactive, targets } from "./reactivity";
|
||||||
import {
|
|
||||||
Fiber,
|
|
||||||
makeChildFiber,
|
|
||||||
makeRootFiber,
|
|
||||||
MountFiber,
|
|
||||||
MountOptions,
|
|
||||||
RootFiber,
|
|
||||||
} from "./fibers";
|
|
||||||
import { applyDefaultProps } from "./props_validation";
|
|
||||||
import { STATUS } from "./status";
|
import { STATUS } from "./status";
|
||||||
|
import { batched, Callback } from "./utils";
|
||||||
|
|
||||||
let currentNode: ComponentNode | null = null;
|
let currentNode: ComponentNode | null = null;
|
||||||
|
|
||||||
export function getCurrent(): ComponentNode | null {
|
export function getCurrent(): ComponentNode {
|
||||||
|
if (!currentNode) {
|
||||||
|
throw new OwlError("No active component (a hook function should only be called in 'setup')");
|
||||||
|
}
|
||||||
return currentNode;
|
return currentNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,6 +20,16 @@ export function useComponent(): Component {
|
|||||||
return currentNode!.component;
|
return currentNode!.component;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply default props (only top level).
|
||||||
|
*/
|
||||||
|
function applyDefaultProps<P extends object>(props: P, defaultProps: Partial<P>) {
|
||||||
|
for (let propName in defaultProps) {
|
||||||
|
if (props[propName] === undefined) {
|
||||||
|
(props as any)[propName] = defaultProps[propName];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Integration with reactivity system (useState)
|
// Integration with reactivity system (useState)
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
@@ -40,98 +45,37 @@ const batchedRenderFunctions = new WeakMap<ComponentNode, Callback>();
|
|||||||
* relevant changes
|
* relevant changes
|
||||||
* @see reactive
|
* @see reactive
|
||||||
*/
|
*/
|
||||||
export function useState<T extends object>(state: T): Reactive<T> {
|
export function useState<T extends object>(state: T): T {
|
||||||
const node = currentNode!;
|
const node = getCurrent();
|
||||||
let render = batchedRenderFunctions.get(node)!;
|
let render = batchedRenderFunctions.get(node)!;
|
||||||
if (!render) {
|
if (!render) {
|
||||||
render = batched(node.render.bind(node));
|
render = batched(node.render.bind(node, false));
|
||||||
batchedRenderFunctions.set(node, render);
|
batchedRenderFunctions.set(node, render);
|
||||||
// manual implementation of onWillUnmount to break cyclic dependency
|
// manual implementation of onWillDestroy to break cyclic dependency
|
||||||
node.willUnmount.unshift(clearReactivesForCallback.bind(null, render));
|
node.willDestroy.push(clearReactivesForCallback.bind(null, render));
|
||||||
}
|
}
|
||||||
return reactive(state, render);
|
return reactive(state, render);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
// component function (used in compiled template code)
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
type Props = { [key: string]: any };
|
|
||||||
|
|
||||||
function arePropsDifferent(props1: Props, props2: Props): boolean {
|
|
||||||
for (let k in props1) {
|
|
||||||
if (props1[k] !== props2[k]) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
export function component(
|
|
||||||
name: string | typeof Component,
|
|
||||||
props: any,
|
|
||||||
key: string,
|
|
||||||
ctx: ComponentNode,
|
|
||||||
parent: any
|
|
||||||
): ComponentNode {
|
|
||||||
let node: any = ctx.children[key];
|
|
||||||
let isDynamic = typeof name !== "string";
|
|
||||||
|
|
||||||
if (node) {
|
|
||||||
if (node.status < STATUS.MOUNTED) {
|
|
||||||
node.destroy();
|
|
||||||
node = undefined;
|
|
||||||
} else if (node.status === STATUS.DESTROYED) {
|
|
||||||
node = undefined;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isDynamic && node && node.component.constructor !== name) {
|
|
||||||
node = undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
const parentFiber = ctx.fiber!;
|
|
||||||
if (node) {
|
|
||||||
const currentProps = node.component.props[TARGET];
|
|
||||||
if (parentFiber.force || arePropsDifferent(currentProps, props)) {
|
|
||||||
node.updateAndRender(props, parentFiber);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// new component
|
|
||||||
let C;
|
|
||||||
if (isDynamic) {
|
|
||||||
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;
|
|
||||||
|
|
||||||
const fiber = makeChildFiber(node, parentFiber);
|
|
||||||
node.initiateRender(fiber);
|
|
||||||
}
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Component VNode class
|
// Component VNode class
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
type LifecycleHook = Function;
|
type LifecycleHook = Function;
|
||||||
|
|
||||||
export class ComponentNode<T extends typeof Component = typeof Component>
|
export class ComponentNode<P extends Props = any, E = any> implements VNode<ComponentNode<P, E>> {
|
||||||
implements VNode<ComponentNode>
|
|
||||||
{
|
|
||||||
el?: HTMLElement | Text | undefined;
|
el?: HTMLElement | Text | undefined;
|
||||||
app: App;
|
app: App;
|
||||||
fiber: Fiber | null = null;
|
fiber: Fiber | null = null;
|
||||||
component: InstanceType<T>;
|
component: Component<P, E>;
|
||||||
bdom: BDom | null = null;
|
bdom: BDom | null = null;
|
||||||
status: STATUS = STATUS.NEW;
|
status: STATUS = STATUS.NEW;
|
||||||
|
forceNextRender: boolean = false;
|
||||||
|
parentKey: string | null;
|
||||||
|
props: P;
|
||||||
|
|
||||||
renderFn: Function;
|
renderFn: Function;
|
||||||
parent: ComponentNode | null;
|
parent: ComponentNode | null;
|
||||||
level: number;
|
|
||||||
childEnv: Env;
|
childEnv: Env;
|
||||||
children: { [key: string]: ComponentNode } = Object.create(null);
|
children: { [key: string]: ComponentNode } = Object.create(null);
|
||||||
refs: any = {};
|
refs: any = {};
|
||||||
@@ -144,18 +88,36 @@ export class ComponentNode<T extends typeof Component = typeof Component>
|
|||||||
patched: LifecycleHook[] = [];
|
patched: LifecycleHook[] = [];
|
||||||
willDestroy: LifecycleHook[] = [];
|
willDestroy: LifecycleHook[] = [];
|
||||||
|
|
||||||
constructor(C: T, props: any, app: App, parent?: ComponentNode) {
|
constructor(
|
||||||
|
C: ComponentConstructor<P, E>,
|
||||||
|
props: P,
|
||||||
|
app: App,
|
||||||
|
parent: ComponentNode | null,
|
||||||
|
parentKey: string | null
|
||||||
|
) {
|
||||||
currentNode = this;
|
currentNode = this;
|
||||||
this.app = app;
|
this.app = app;
|
||||||
this.parent = parent || null;
|
this.parent = parent;
|
||||||
this.level = parent ? parent.level + 1 : 0;
|
this.props = props;
|
||||||
applyDefaultProps(props, C);
|
this.parentKey = parentKey;
|
||||||
|
const defaultProps = C.defaultProps;
|
||||||
|
props = Object.assign({}, props);
|
||||||
|
if (defaultProps) {
|
||||||
|
applyDefaultProps(props, defaultProps);
|
||||||
|
}
|
||||||
const env = (parent && parent.childEnv) || app.env;
|
const env = (parent && parent.childEnv) || app.env;
|
||||||
this.childEnv = env;
|
this.childEnv = env;
|
||||||
props = useState(props);
|
for (const key in props) {
|
||||||
this.component = new C(props, env, this) as any;
|
const prop = props[key];
|
||||||
this.renderFn = app.getTemplate(C.template).bind(this.component, this.component, this);
|
if (prop && typeof prop === "object" && targets.has(prop)) {
|
||||||
|
props[key] = useState(prop);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.component = new C(props, env, this);
|
||||||
|
const ctx = Object.assign(Object.create(this.component), { this: this.component });
|
||||||
|
this.renderFn = app.getTemplate(C.template).bind(this.component, ctx, this);
|
||||||
this.component.setup();
|
this.component.setup();
|
||||||
|
currentNode = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
mountComponent(target: any, options?: MountOptions) {
|
mountComponent(target: any, options?: MountOptions) {
|
||||||
@@ -173,32 +135,39 @@ export class ComponentNode<T extends typeof Component = typeof Component>
|
|||||||
try {
|
try {
|
||||||
await Promise.all(this.willStart.map((f) => f.call(component)));
|
await Promise.all(this.willStart.map((f) => f.call(component)));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
handleError({ node: this, error: e });
|
this.app.handleError({ node: this, error: e });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.status === STATUS.NEW && this.fiber === fiber) {
|
if (this.status === STATUS.NEW && this.fiber === fiber) {
|
||||||
this._render(fiber);
|
fiber.render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async render(force: boolean = false) {
|
async render(deep: boolean) {
|
||||||
let current = this.fiber;
|
let current = this.fiber;
|
||||||
if (current && current.root!.locked) {
|
if (current && (current.root!.locked || (current as any).bdom === true)) {
|
||||||
await Promise.resolve();
|
await Promise.resolve();
|
||||||
// situation may have changed after the microtask tick
|
// situation may have changed after the microtask tick
|
||||||
current = this.fiber;
|
current = this.fiber;
|
||||||
}
|
}
|
||||||
if (current && !current.bdom && !fibersInError.has(current)) {
|
if (current) {
|
||||||
if (current.force || force === false) {
|
if (!current.bdom && !fibersInError.has(current)) {
|
||||||
|
if (deep) {
|
||||||
|
// we want the render from this point on to be with deep=true
|
||||||
|
current.deep = deep;
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
// if current rendering was with deep=true, we want this one to be the same
|
||||||
if (!this.bdom && !current) {
|
deep = deep || current.deep;
|
||||||
|
} else if (!this.bdom) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const fiber = makeRootFiber(this, force);
|
const fiber = makeRootFiber(this);
|
||||||
|
fiber.deep = deep;
|
||||||
this.fiber = fiber;
|
this.fiber = fiber;
|
||||||
|
|
||||||
this.app.scheduler.addFiber(fiber);
|
this.app.scheduler.addFiber(fiber);
|
||||||
await Promise.resolve();
|
await Promise.resolve();
|
||||||
if (this.status === STATUS.DESTROYED) {
|
if (this.status === STATUS.DESTROYED) {
|
||||||
@@ -216,16 +185,7 @@ export class ComponentNode<T extends typeof Component = typeof Component>
|
|||||||
// embedded in a rendering coming from above, so the fiber will be rendered
|
// embedded in a rendering coming from above, so the fiber will be rendered
|
||||||
// in the next microtick anyway, so we should not render it again.
|
// in the next microtick anyway, so we should not render it again.
|
||||||
if (this.fiber === fiber && (current || !fiber.parent)) {
|
if (this.fiber === fiber && (current || !fiber.parent)) {
|
||||||
this._render(fiber);
|
fiber.render();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_render(fiber: Fiber | RootFiber) {
|
|
||||||
try {
|
|
||||||
fiber.bdom = this.renderFn();
|
|
||||||
fiber.root!.counter--;
|
|
||||||
} catch (e) {
|
|
||||||
handleError({ node: this, error: e });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -247,28 +207,46 @@ export class ComponentNode<T extends typeof Component = typeof Component>
|
|||||||
for (let child of Object.values(this.children)) {
|
for (let child of Object.values(this.children)) {
|
||||||
child._destroy();
|
child._destroy();
|
||||||
}
|
}
|
||||||
for (let cb of this.willDestroy) {
|
if (this.willDestroy.length) {
|
||||||
cb.call(component);
|
try {
|
||||||
|
for (let cb of this.willDestroy) {
|
||||||
|
cb.call(component);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
this.app.handleError({ error: e, node: this });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.status = STATUS.DESTROYED;
|
this.status = STATUS.DESTROYED;
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateAndRender(props: any, parentFiber: Fiber) {
|
async updateAndRender(props: P, parentFiber: Fiber) {
|
||||||
|
const rawProps = props;
|
||||||
|
props = Object.assign({}, props);
|
||||||
// update
|
// update
|
||||||
const fiber = makeChildFiber(this, parentFiber);
|
const fiber = makeChildFiber(this, parentFiber);
|
||||||
this.fiber = fiber;
|
this.fiber = fiber;
|
||||||
const component = this.component;
|
const component = this.component;
|
||||||
applyDefaultProps(props, component.constructor as any);
|
const defaultProps = (component.constructor as any).defaultProps;
|
||||||
|
if (defaultProps) {
|
||||||
|
applyDefaultProps(props, defaultProps);
|
||||||
|
}
|
||||||
|
|
||||||
currentNode = this;
|
currentNode = this;
|
||||||
props = useState(props);
|
for (const key in props) {
|
||||||
|
const prop = props[key];
|
||||||
|
if (prop && typeof prop === "object" && targets.has(prop)) {
|
||||||
|
props[key] = useState(prop);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
currentNode = null;
|
||||||
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) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
component.props = props;
|
component.props = props;
|
||||||
this._render(fiber);
|
this.props = rawProps;
|
||||||
|
fiber.render();
|
||||||
const parentRoot = parentFiber.root!;
|
const parentRoot = parentFiber.root!;
|
||||||
if (this.willPatch.length) {
|
if (this.willPatch.length) {
|
||||||
parentRoot.willPatch.push(fiber);
|
parentRoot.willPatch.push(fiber);
|
||||||
@@ -318,11 +296,16 @@ export class ComponentNode<T extends typeof Component = typeof Component>
|
|||||||
bdom.mount(parent, anchor);
|
bdom.mount(parent, anchor);
|
||||||
this.status = STATUS.MOUNTED;
|
this.status = STATUS.MOUNTED;
|
||||||
this.fiber!.appliedToDom = true;
|
this.fiber!.appliedToDom = true;
|
||||||
|
this.children = this.fiber!.childrenMap;
|
||||||
this.fiber = null;
|
this.fiber = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
moveBefore(other: ComponentNode | null, afterNode: Node | null) {
|
moveBeforeDOMNode(node: Node | null, parent?: HTMLElement): void {
|
||||||
this.bdom!.moveBefore(other ? other.bdom : null, afterNode);
|
this.bdom!.moveBeforeDOMNode(node, parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
moveBeforeVNode(other: ComponentNode<P, E> | null, afterNode: Node | null) {
|
||||||
|
this.bdom!.moveBeforeVNode(other ? other.bdom : null, afterNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
patch() {
|
patch() {
|
||||||
@@ -334,12 +317,16 @@ export class ComponentNode<T extends typeof Component = typeof Component>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
_patch() {
|
_patch() {
|
||||||
const hasChildren = Object.keys(this.children).length > 0;
|
let hasChildren = false;
|
||||||
this.bdom!.patch(this!.fiber!.bdom!, hasChildren);
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
if (hasChildren) {
|
for (let _k in this.children) {
|
||||||
this.cleanOutdatedChildren();
|
hasChildren = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
this.fiber!.appliedToDom = true;
|
const fiber = this.fiber!;
|
||||||
|
this.children = fiber.childrenMap;
|
||||||
|
this.bdom!.patch(fiber.bdom!, hasChildren);
|
||||||
|
fiber.appliedToDom = true;
|
||||||
this.fiber = null;
|
this.fiber = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -351,17 +338,15 @@ export class ComponentNode<T extends typeof Component = typeof Component>
|
|||||||
this.bdom!.remove();
|
this.bdom!.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanOutdatedChildren() {
|
// ---------------------------------------------------------------------------
|
||||||
const children = this.children;
|
// Some debug helpers
|
||||||
for (const key in children) {
|
// ---------------------------------------------------------------------------
|
||||||
const node = children[key];
|
get name(): string {
|
||||||
const status = node.status;
|
return this.component.constructor.name;
|
||||||
if (status !== STATUS.MOUNTED) {
|
}
|
||||||
delete children[key];
|
|
||||||
if (status !== STATUS.DESTROYED) {
|
get subscriptions(): ReturnType<typeof getSubscriptions> {
|
||||||
node.destroy();
|
const render = batchedRenderFunctions.get(this);
|
||||||
}
|
return render ? getSubscriptions(render) : [];
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,16 @@
|
|||||||
import type { ComponentNode } from "./component_node";
|
import type { ComponentNode } from "./component_node";
|
||||||
import type { Fiber } from "./fibers";
|
import type { Fiber } from "./fibers";
|
||||||
|
|
||||||
|
// Custom error class that wraps error that happen in the owl lifecycle
|
||||||
|
export class OwlError extends Error {
|
||||||
|
cause?: any;
|
||||||
|
}
|
||||||
|
|
||||||
// Maps fibers to thrown errors
|
// Maps fibers to thrown errors
|
||||||
export const fibersInError: WeakMap<Fiber, any> = new WeakMap();
|
export const fibersInError: WeakMap<Fiber, any> = new WeakMap();
|
||||||
export const nodeErrorHandlers: WeakMap<ComponentNode, ((error: any) => void)[]> = new WeakMap();
|
export const nodeErrorHandlers: WeakMap<ComponentNode, ((error: any) => void)[]> = new WeakMap();
|
||||||
|
|
||||||
function _handleError(node: ComponentNode | null, error: any, isFirstRound = false): boolean {
|
function _handleError(node: ComponentNode | null, error: any): boolean {
|
||||||
if (!node) {
|
if (!node) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -16,22 +21,19 @@ function _handleError(node: ComponentNode | null, error: any, isFirstRound = fal
|
|||||||
|
|
||||||
const errorHandlers = nodeErrorHandlers.get(node);
|
const errorHandlers = nodeErrorHandlers.get(node);
|
||||||
if (errorHandlers) {
|
if (errorHandlers) {
|
||||||
let stopped = false;
|
let handled = false;
|
||||||
// execute in the opposite order
|
// execute in the opposite order
|
||||||
for (let i = errorHandlers.length - 1; i >= 0; i--) {
|
for (let i = errorHandlers.length - 1; i >= 0; i--) {
|
||||||
try {
|
try {
|
||||||
errorHandlers[i](error);
|
errorHandlers[i](error);
|
||||||
stopped = true;
|
handled = true;
|
||||||
break;
|
break;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
error = e;
|
error = e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stopped) {
|
if (handled) {
|
||||||
if (isFirstRound && fiber && fiber.node.fiber) {
|
|
||||||
fiber.root!.counter--;
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -40,7 +42,14 @@ function _handleError(node: ComponentNode | null, error: any, isFirstRound = fal
|
|||||||
|
|
||||||
type ErrorParams = { error: any } & ({ node: ComponentNode } | { fiber: Fiber });
|
type ErrorParams = { error: any } & ({ node: ComponentNode } | { fiber: Fiber });
|
||||||
export function handleError(params: ErrorParams) {
|
export function handleError(params: ErrorParams) {
|
||||||
const error = params.error;
|
let { error } = params;
|
||||||
|
// Wrap error if it wasn't wrapped by wrapError (ie when not in dev mode)
|
||||||
|
if (!(error instanceof OwlError)) {
|
||||||
|
error = Object.assign(
|
||||||
|
new OwlError(`An error occured in the owl lifecycle (see this Error's "cause" property)`),
|
||||||
|
{ cause: error }
|
||||||
|
);
|
||||||
|
}
|
||||||
const node = "node" in params ? params.node : params.fiber.node;
|
const node = "node" in params ? params.node : params.fiber.node;
|
||||||
const fiber = "fiber" in params ? params.fiber : node.fiber!;
|
const fiber = "fiber" in params ? params.fiber : node.fiber!;
|
||||||
|
|
||||||
@@ -54,7 +63,7 @@ export function handleError(params: ErrorParams) {
|
|||||||
|
|
||||||
fibersInError.set(fiber.root!, error);
|
fibersInError.set(fiber.root!, error);
|
||||||
|
|
||||||
const handled = _handleError(node, error, true);
|
const handled = _handleError(node, error);
|
||||||
if (!handled) {
|
if (!handled) {
|
||||||
console.warn(`[Owl] Unhandled error. Destroying the root component`);
|
console.warn(`[Owl] Unhandled error. Destroying the root component`);
|
||||||
try {
|
try {
|
||||||
@@ -62,5 +71,6 @@ export function handleError(params: ErrorParams) {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import { filterOutModifiersFromData } from "../blockdom/config";
|
import { filterOutModifiersFromData } from "./blockdom/config";
|
||||||
import { STATUS } from "./status";
|
import { STATUS } from "./status";
|
||||||
|
import { OwlError } from "./error_handling";
|
||||||
|
|
||||||
export const mainEventHandler = (data: any, ev: Event, currentTarget?: EventTarget | null) => {
|
export const mainEventHandler = (data: any, ev: Event, currentTarget?: EventTarget | null) => {
|
||||||
const { data: _data, modifiers } = filterOutModifiersFromData(data);
|
const { data: _data, modifiers } = filterOutModifiersFromData(data);
|
||||||
@@ -33,7 +34,7 @@ export const mainEventHandler = (data: any, ev: Event, currentTarget?: EventTarg
|
|||||||
if (Object.hasOwnProperty.call(data, 0)) {
|
if (Object.hasOwnProperty.call(data, 0)) {
|
||||||
const handler = data[0];
|
const handler = data[0];
|
||||||
if (typeof handler !== "function") {
|
if (typeof handler !== "function") {
|
||||||
throw new Error(`Invalid handler (expected a function, received: '${handler}')`);
|
throw new OwlError(`Invalid handler (expected a function, received: '${handler}')`);
|
||||||
}
|
}
|
||||||
let node = data[1] ? data[1].__owl__ : null;
|
let node = data[1] ? data[1].__owl__ : null;
|
||||||
if (node ? node.status === STATUS.MOUNTED : true) {
|
if (node ? node.status === STATUS.MOUNTED : true) {
|
||||||
@@ -1,27 +1,30 @@
|
|||||||
import { BDom, mount } from "../blockdom";
|
import { BDom, mount } from "./blockdom";
|
||||||
import type { ComponentNode } from "./component_node";
|
import type { ComponentNode } from "./component_node";
|
||||||
import { fibersInError, handleError } from "./error_handling";
|
import { fibersInError, OwlError } from "./error_handling";
|
||||||
import { STATUS } from "./status";
|
import { STATUS } from "./status";
|
||||||
|
|
||||||
export function makeChildFiber(node: ComponentNode, parent: Fiber): Fiber {
|
export function makeChildFiber(node: ComponentNode, parent: Fiber): Fiber {
|
||||||
let current = node.fiber;
|
let current = node.fiber;
|
||||||
if (current) {
|
if (current) {
|
||||||
let root = parent.root;
|
cancelFibers(current.children);
|
||||||
cancelFibers(root, current.children);
|
|
||||||
current.root = null;
|
current.root = null;
|
||||||
}
|
}
|
||||||
return new Fiber(node, parent);
|
return new Fiber(node, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function makeRootFiber(node: ComponentNode, force: boolean): Fiber {
|
export function makeRootFiber(node: ComponentNode): Fiber {
|
||||||
let current = node.fiber;
|
let current = node.fiber;
|
||||||
if (current) {
|
if (current) {
|
||||||
let root = current.root!;
|
let root = current.root!;
|
||||||
root.counter -= cancelFibers(root, current.children);
|
// lock root fiber because canceling children fibers may destroy components,
|
||||||
|
// which means any arbitrary code can be run in onWillDestroy, which may
|
||||||
|
// trigger new renderings
|
||||||
|
root.locked = true;
|
||||||
|
root.setCounter(root.counter + 1 - cancelFibers(current.children));
|
||||||
|
root.locked = false;
|
||||||
current.children = [];
|
current.children = [];
|
||||||
root.counter++;
|
current.childrenMap = {};
|
||||||
current.bdom = null;
|
current.bdom = null;
|
||||||
current.force = force;
|
|
||||||
if (fibersInError.has(current)) {
|
if (fibersInError.has(current)) {
|
||||||
fibersInError.delete(current);
|
fibersInError.delete(current);
|
||||||
fibersInError.delete(root);
|
fibersInError.delete(root);
|
||||||
@@ -36,22 +39,38 @@ export function makeRootFiber(node: ComponentNode, force: boolean): Fiber {
|
|||||||
if (node.patched.length) {
|
if (node.patched.length) {
|
||||||
fiber.patched.push(fiber);
|
fiber.patched.push(fiber);
|
||||||
}
|
}
|
||||||
fiber.force = force;
|
|
||||||
return fiber;
|
return fiber;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function throwOnRender() {
|
||||||
|
throw new OwlError("Attempted to render cancelled fiber");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns number of not-yet rendered fibers cancelled
|
* @returns number of not-yet rendered fibers cancelled
|
||||||
*/
|
*/
|
||||||
function cancelFibers(root: any, fibers: Fiber[]): number {
|
function cancelFibers(fibers: Fiber[]): number {
|
||||||
let result = 0;
|
let result = 0;
|
||||||
for (let fiber of fibers) {
|
for (let fiber of fibers) {
|
||||||
fiber.node.fiber = null;
|
let node = fiber.node;
|
||||||
fiber.root = root;
|
fiber.render = throwOnRender;
|
||||||
if (!fiber.bdom) {
|
if (node.status === STATUS.NEW) {
|
||||||
|
node.destroy();
|
||||||
|
delete node.parent!.children[node.parentKey!];
|
||||||
|
}
|
||||||
|
node.fiber = null;
|
||||||
|
if (fiber.bdom) {
|
||||||
|
// if fiber has been rendered, this means that the component props have
|
||||||
|
// been updated. however, this fiber will not be patched to the dom, so
|
||||||
|
// it could happen that the next render compare the current props with
|
||||||
|
// the same props, and skip the render completely. With the next line,
|
||||||
|
// we kindly request the component code to force a render, so it works as
|
||||||
|
// expected.
|
||||||
|
node.forceNextRender = true;
|
||||||
|
} else {
|
||||||
result++;
|
result++;
|
||||||
}
|
}
|
||||||
result += cancelFibers(root, fiber.children);
|
result += cancelFibers(fiber.children);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -63,21 +82,59 @@ export class Fiber {
|
|||||||
parent: Fiber | null;
|
parent: Fiber | null;
|
||||||
children: Fiber[] = [];
|
children: Fiber[] = [];
|
||||||
appliedToDom = false;
|
appliedToDom = false;
|
||||||
force: boolean = false;
|
deep: boolean = false;
|
||||||
|
childrenMap: ComponentNode["children"] = {};
|
||||||
|
|
||||||
constructor(node: ComponentNode, parent: Fiber | null) {
|
constructor(node: ComponentNode, parent: Fiber | null) {
|
||||||
this.node = node;
|
this.node = node;
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
if (parent) {
|
if (parent) {
|
||||||
this.force = parent.force;
|
this.deep = parent.deep;
|
||||||
const root = parent.root!;
|
const root = parent.root!;
|
||||||
root.counter++;
|
root.setCounter(root.counter + 1);
|
||||||
this.root = root;
|
this.root = root;
|
||||||
parent.children.push(this);
|
parent.children.push(this);
|
||||||
} else {
|
} else {
|
||||||
this.root = this as any;
|
this.root = this as any;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
// if some parent has a fiber => register in followup
|
||||||
|
let prev = this.root!.node;
|
||||||
|
let scheduler = prev.app.scheduler;
|
||||||
|
let current = prev.parent;
|
||||||
|
while (current) {
|
||||||
|
if (current.fiber) {
|
||||||
|
let root = current.fiber.root!;
|
||||||
|
if (root.counter === 0 && prev.parentKey! in current.fiber.childrenMap) {
|
||||||
|
current = root.node;
|
||||||
|
} else {
|
||||||
|
scheduler.delayedRenders.push(this);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
prev = current;
|
||||||
|
current = current.parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
// there are no current rendering from above => we can render
|
||||||
|
this._render();
|
||||||
|
}
|
||||||
|
|
||||||
|
_render() {
|
||||||
|
const node = this.node;
|
||||||
|
const root = this.root;
|
||||||
|
if (root) {
|
||||||
|
try {
|
||||||
|
(this.bdom as any) = true;
|
||||||
|
this.bdom = node.renderFn();
|
||||||
|
} catch (e) {
|
||||||
|
node.app.handleError({ node, error: e });
|
||||||
|
}
|
||||||
|
root.setCounter(root.counter - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class RootFiber extends Fiber {
|
export class RootFiber extends Fiber {
|
||||||
@@ -138,7 +195,14 @@ export class RootFiber extends Fiber {
|
|||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.locked = false;
|
this.locked = false;
|
||||||
handleError({ fiber: current || this, error: e });
|
node.app.handleError({ fiber: current || this, error: e });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setCounter(newValue: number) {
|
||||||
|
this.counter = newValue;
|
||||||
|
if (newValue === 0) {
|
||||||
|
this.node.app.scheduler.flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -162,6 +226,8 @@ export class MountFiber extends RootFiber {
|
|||||||
let current: Fiber | undefined = this;
|
let current: Fiber | undefined = this;
|
||||||
try {
|
try {
|
||||||
const node = this.node;
|
const node = this.node;
|
||||||
|
node.children = this.childrenMap;
|
||||||
|
(node.app.constructor as any).validateTarget(this.target);
|
||||||
if (node.bdom) {
|
if (node.bdom) {
|
||||||
// this is a complicated situation: if we mount a fiber with an existing
|
// this is a complicated situation: if we mount a fiber with an existing
|
||||||
// bdom, this means that this same fiber was already completed, mounted,
|
// bdom, this means that this same fiber was already completed, mounted,
|
||||||
@@ -193,7 +259,7 @@ export class MountFiber extends RootFiber {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
handleError({ fiber: current as Fiber, error: e });
|
this.node.app.handleError({ fiber: current as Fiber, error: e });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { Env } from "./app/app";
|
import type { Env } from "./app";
|
||||||
import { getCurrent } from "./component/component_node";
|
import { getCurrent } from "./component_node";
|
||||||
import { onMounted, onPatched, onWillUnmount } from "./component/lifecycle_hooks";
|
import { onMounted, onPatched, onWillUnmount } from "./lifecycle_hooks";
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// useRef
|
// useRef
|
||||||
@@ -11,7 +11,7 @@ import { onMounted, onPatched, onWillUnmount } from "./component/lifecycle_hooks
|
|||||||
* html node or component.
|
* html node or component.
|
||||||
*/
|
*/
|
||||||
export function useRef<T extends HTMLElement = HTMLElement>(name: string): { el: T | null } {
|
export function useRef<T extends HTMLElement = HTMLElement>(name: string): { el: T | null } {
|
||||||
const node = getCurrent()!;
|
const node = getCurrent();
|
||||||
const refs = node.refs;
|
const refs = node.refs;
|
||||||
return {
|
return {
|
||||||
get el(): T | null {
|
get el(): T | null {
|
||||||
@@ -29,7 +29,13 @@ export function useRef<T extends HTMLElement = HTMLElement>(name: string): { el:
|
|||||||
* need a reference to the env of the component calling them.
|
* need a reference to the env of the component calling them.
|
||||||
*/
|
*/
|
||||||
export function useEnv<E extends Env>(): E {
|
export function useEnv<E extends Env>(): E {
|
||||||
return getCurrent()!.component.env as any;
|
return getCurrent().component.env as any;
|
||||||
|
}
|
||||||
|
|
||||||
|
function extendEnv(currentEnv: Object, extension: Object): Object {
|
||||||
|
const env = Object.create(currentEnv);
|
||||||
|
const descrs = Object.getOwnPropertyDescriptors(extension);
|
||||||
|
return Object.freeze(Object.defineProperties(env, descrs));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -38,17 +44,19 @@ export function useEnv<E extends Env>(): E {
|
|||||||
* constructor method.
|
* constructor method.
|
||||||
*/
|
*/
|
||||||
export function useSubEnv(envExtension: Env) {
|
export function useSubEnv(envExtension: Env) {
|
||||||
const node = getCurrent()!;
|
const node = getCurrent();
|
||||||
const env = Object.create(node.childEnv);
|
node.component.env = extendEnv(node.component.env as any, envExtension);
|
||||||
const descrs = Object.getOwnPropertyDescriptors(envExtension);
|
useChildSubEnv(envExtension);
|
||||||
node.childEnv = Object.freeze(Object.defineProperties(env, descrs));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function useChildSubEnv(envExtension: Env) {
|
||||||
|
const node = getCurrent();
|
||||||
|
node.childEnv = extendEnv(node.childEnv, envExtension);
|
||||||
|
}
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// useEffect
|
// useEffect
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
const NO_OP = () => {};
|
|
||||||
/**
|
/**
|
||||||
* @param {...any} dependencies the dependencies computed by computeDependencies
|
* @param {...any} dependencies the dependencies computed by computeDependencies
|
||||||
* @returns {void|(()=>void)} a cleanup function that reverses the side
|
* @returns {void|(()=>void)} a cleanup function that reverses the side
|
||||||
@@ -69,11 +77,11 @@ type Effect = (...dependencies: any[]) => void | (() => void);
|
|||||||
* NaN !== NaN, which will cause the effect to rerun on every patch.
|
* NaN !== NaN, which will cause the effect to rerun on every patch.
|
||||||
*/
|
*/
|
||||||
export function useEffect(effect: Effect, computeDependencies: () => any[] = () => [NaN]) {
|
export function useEffect(effect: Effect, computeDependencies: () => any[] = () => [NaN]) {
|
||||||
let cleanup: () => void;
|
let cleanup: (() => void) | void;
|
||||||
let dependencies: any[];
|
let dependencies: any[];
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
dependencies = computeDependencies();
|
dependencies = computeDependencies();
|
||||||
cleanup = effect(...dependencies) || NO_OP;
|
cleanup = effect(...dependencies);
|
||||||
});
|
});
|
||||||
|
|
||||||
onPatched(() => {
|
onPatched(() => {
|
||||||
@@ -81,12 +89,14 @@ export function useEffect(effect: Effect, computeDependencies: () => any[] = ()
|
|||||||
const shouldReapply = newDeps.some((val, i) => val !== dependencies[i]);
|
const shouldReapply = newDeps.some((val, i) => val !== dependencies[i]);
|
||||||
if (shouldReapply) {
|
if (shouldReapply) {
|
||||||
dependencies = newDeps;
|
dependencies = newDeps;
|
||||||
cleanup();
|
if (cleanup) {
|
||||||
cleanup = effect(...dependencies) || NO_OP;
|
cleanup();
|
||||||
|
}
|
||||||
|
cleanup = effect(...dependencies);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
onWillUnmount(() => cleanup());
|
onWillUnmount(() => cleanup && cleanup());
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
@@ -107,12 +117,12 @@ export function useEffect(effect: Effect, computeDependencies: () => any[] = ()
|
|||||||
* `useExternalListener(window, 'click', this._doSomething);`
|
* `useExternalListener(window, 'click', this._doSomething);`
|
||||||
* */
|
* */
|
||||||
export function useExternalListener(
|
export function useExternalListener(
|
||||||
target: HTMLElement | typeof window,
|
target: EventTarget,
|
||||||
eventName: string,
|
eventName: string,
|
||||||
handler: EventListener,
|
handler: EventListener,
|
||||||
eventParams?: AddEventListenerOptions
|
eventParams?: AddEventListenerOptions
|
||||||
) {
|
) {
|
||||||
const node = getCurrent()!;
|
const node = getCurrent();
|
||||||
const boundHandler = handler.bind(node.component);
|
const boundHandler = handler.bind(node.component);
|
||||||
onMounted(() => target.addEventListener(eventName, boundHandler, eventParams));
|
onMounted(() => target.addEventListener(eventName, boundHandler, eventParams));
|
||||||
onWillUnmount(() => target.removeEventListener(eventName, boundHandler, eventParams));
|
onWillUnmount(() => target.removeEventListener(eventName, boundHandler, eventParams));
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
import {
|
||||||
|
config,
|
||||||
|
createBlock,
|
||||||
|
html,
|
||||||
|
list,
|
||||||
|
mount as blockMount,
|
||||||
|
multi,
|
||||||
|
patch,
|
||||||
|
remove,
|
||||||
|
text,
|
||||||
|
toggler,
|
||||||
|
comment,
|
||||||
|
} from "./blockdom";
|
||||||
|
import { mainEventHandler } from "./event_handling";
|
||||||
|
|
||||||
|
config.shouldNormalizeDom = false;
|
||||||
|
config.mainEventHandler = mainEventHandler;
|
||||||
|
|
||||||
|
export const blockDom = {
|
||||||
|
config,
|
||||||
|
// bdom entry points
|
||||||
|
mount: blockMount,
|
||||||
|
patch,
|
||||||
|
remove,
|
||||||
|
// bdom block types
|
||||||
|
list,
|
||||||
|
multi,
|
||||||
|
text,
|
||||||
|
toggler,
|
||||||
|
createBlock,
|
||||||
|
html,
|
||||||
|
comment,
|
||||||
|
};
|
||||||
|
|
||||||
|
export { App, mount } from "./app";
|
||||||
|
export { xml } from "./template_set";
|
||||||
|
export { Component } from "./component";
|
||||||
|
export type { ComponentConstructor } from "./component";
|
||||||
|
export { useComponent, useState } from "./component_node";
|
||||||
|
export { status } from "./status";
|
||||||
|
export { reactive, markRaw, toRaw } from "./reactivity";
|
||||||
|
export { useEffect, useEnv, useExternalListener, useRef, useChildSubEnv, useSubEnv } from "./hooks";
|
||||||
|
export { EventBus, whenReady, loadFile, markup } from "./utils";
|
||||||
|
export {
|
||||||
|
onWillStart,
|
||||||
|
onMounted,
|
||||||
|
onWillUnmount,
|
||||||
|
onWillUpdateProps,
|
||||||
|
onWillPatch,
|
||||||
|
onPatched,
|
||||||
|
onWillRender,
|
||||||
|
onRendered,
|
||||||
|
onWillDestroy,
|
||||||
|
onError,
|
||||||
|
} from "./lifecycle_hooks";
|
||||||
|
export { validate } from "./validation";
|
||||||
|
export { OwlError } from "./error_handling";
|
||||||
|
|
||||||
|
export const __info__ = {};
|
||||||
@@ -0,0 +1,122 @@
|
|||||||
|
import { getCurrent } from "./component_node";
|
||||||
|
import { nodeErrorHandlers, OwlError } from "./error_handling";
|
||||||
|
|
||||||
|
const TIMEOUT = Symbol("timeout");
|
||||||
|
function wrapError(fn: (...args: any[]) => any, hookName: string) {
|
||||||
|
const error = new OwlError(`The following error occurred in ${hookName}: `) as Error & {
|
||||||
|
cause: any;
|
||||||
|
};
|
||||||
|
const timeoutError = new OwlError(`${hookName}'s promise hasn't resolved after 3 seconds`);
|
||||||
|
const node = getCurrent();
|
||||||
|
return (...args: any[]) => {
|
||||||
|
const onError = (cause: any) => {
|
||||||
|
error.cause = cause;
|
||||||
|
if (cause instanceof Error) {
|
||||||
|
error.message += `"${cause.message}"`;
|
||||||
|
} else {
|
||||||
|
error.message = `Something that is not an Error was thrown in ${hookName} (see this Error's "cause" property)`;
|
||||||
|
}
|
||||||
|
throw error;
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
const result = fn(...args);
|
||||||
|
if (result instanceof Promise) {
|
||||||
|
if (hookName === "onWillStart" || hookName === "onWillUpdateProps") {
|
||||||
|
const fiber = node.fiber;
|
||||||
|
Promise.race([
|
||||||
|
result.catch(() => {}),
|
||||||
|
new Promise((resolve) => setTimeout(() => resolve(TIMEOUT), 3000)),
|
||||||
|
]).then((res) => {
|
||||||
|
if (res === TIMEOUT && node.fiber === fiber) {
|
||||||
|
console.warn(timeoutError);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return result.catch(onError);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
} catch (cause) {
|
||||||
|
onError(cause);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// hooks
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
export function onWillStart(fn: () => Promise<void> | void | any) {
|
||||||
|
const node = getCurrent();
|
||||||
|
const decorate = node.app.dev ? wrapError : (fn: any) => fn;
|
||||||
|
node.willStart.push(decorate(fn.bind(node.component), "onWillStart"));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function onWillUpdateProps(fn: (nextProps: any) => Promise<void> | void | any) {
|
||||||
|
const node = getCurrent();
|
||||||
|
const decorate = node.app.dev ? wrapError : (fn: any) => fn;
|
||||||
|
node.willUpdateProps.push(decorate(fn.bind(node.component), "onWillUpdateProps"));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function onMounted(fn: () => void | any) {
|
||||||
|
const node = getCurrent();
|
||||||
|
const decorate = node.app.dev ? wrapError : (fn: any) => fn;
|
||||||
|
node.mounted.push(decorate(fn.bind(node.component), "onMounted"));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function onWillPatch(fn: () => Promise<void> | any | void) {
|
||||||
|
const node = getCurrent();
|
||||||
|
const decorate = node.app.dev ? wrapError : (fn: any) => fn;
|
||||||
|
node.willPatch.unshift(decorate(fn.bind(node.component), "onWillPatch"));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function onPatched(fn: () => void | any) {
|
||||||
|
const node = getCurrent();
|
||||||
|
const decorate = node.app.dev ? wrapError : (fn: any) => fn;
|
||||||
|
node.patched.push(decorate(fn.bind(node.component), "onPatched"));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function onWillUnmount(fn: () => Promise<void> | void | any) {
|
||||||
|
const node = getCurrent();
|
||||||
|
const decorate = node.app.dev ? wrapError : (fn: any) => fn;
|
||||||
|
node.willUnmount.unshift(decorate(fn.bind(node.component), "onWillUnmount"));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function onWillDestroy(fn: () => Promise<void> | void | any) {
|
||||||
|
const node = getCurrent();
|
||||||
|
const decorate = node.app.dev ? wrapError : (fn: any) => fn;
|
||||||
|
node.willDestroy.push(decorate(fn.bind(node.component), "onWillDestroy"));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function onWillRender(fn: () => void | any) {
|
||||||
|
const node = getCurrent();
|
||||||
|
const renderFn = node.renderFn;
|
||||||
|
const decorate = node.app.dev ? wrapError : (fn: any) => fn;
|
||||||
|
fn = decorate(fn.bind(node.component), "onWillRender");
|
||||||
|
node.renderFn = () => {
|
||||||
|
fn();
|
||||||
|
return renderFn();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function onRendered(fn: () => void | any) {
|
||||||
|
const node = getCurrent();
|
||||||
|
const renderFn = node.renderFn;
|
||||||
|
const decorate = node.app.dev ? wrapError : (fn: any) => fn;
|
||||||
|
fn = decorate(fn.bind(node.component), "onRendered");
|
||||||
|
node.renderFn = () => {
|
||||||
|
const result = renderFn();
|
||||||
|
fn();
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
type OnErrorCallback = (error: any) => void | any;
|
||||||
|
export function onError(callback: OnErrorCallback) {
|
||||||
|
const node = getCurrent();
|
||||||
|
let handlers = nodeErrorHandlers.get(node);
|
||||||
|
if (!handlers) {
|
||||||
|
handlers = [];
|
||||||
|
nodeErrorHandlers.set(node, handlers);
|
||||||
|
}
|
||||||
|
handlers.push(callback.bind(node.component));
|
||||||
|
}
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
import { onMounted, onWillUnmount } from "./lifecycle_hooks";
|
||||||
|
import { BDom, text, VNode } from "./blockdom";
|
||||||
|
import { Component } from "./component";
|
||||||
|
import { OwlError } from "./error_handling";
|
||||||
|
|
||||||
|
const VText: any = text("").constructor;
|
||||||
|
|
||||||
|
class VPortal extends VText implements Partial<VNode<VPortal>> {
|
||||||
|
content: BDom | null;
|
||||||
|
selector: string;
|
||||||
|
target: HTMLElement | null = null;
|
||||||
|
|
||||||
|
constructor(selector: string, content: BDom) {
|
||||||
|
super("");
|
||||||
|
this.selector = selector;
|
||||||
|
this.content = content;
|
||||||
|
}
|
||||||
|
|
||||||
|
mount(parent: HTMLElement, anchor: ChildNode) {
|
||||||
|
super.mount(parent, anchor);
|
||||||
|
this.target = document.querySelector(this.selector) as any;
|
||||||
|
if (this.target) {
|
||||||
|
this.content!.mount(this.target!, null);
|
||||||
|
} else {
|
||||||
|
this.content!.mount(parent, anchor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeRemove() {
|
||||||
|
this.content!.beforeRemove();
|
||||||
|
}
|
||||||
|
remove() {
|
||||||
|
if (this.content) {
|
||||||
|
super.remove();
|
||||||
|
this.content!.remove();
|
||||||
|
this.content = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
patch(other: VPortal) {
|
||||||
|
super.patch(other);
|
||||||
|
if (this.content) {
|
||||||
|
this.content.patch(other.content!, true);
|
||||||
|
} else {
|
||||||
|
this.content = other.content;
|
||||||
|
this.content!.mount(this.target!, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* kind of similar to <t t-slot="default"/>, but it wraps it around a VPortal
|
||||||
|
*/
|
||||||
|
export function portalTemplate(app: any, bdom: any, helpers: any) {
|
||||||
|
let { callSlot } = helpers;
|
||||||
|
return function template(ctx: any, node: any, key = ""): any {
|
||||||
|
return new VPortal(ctx.props.target, callSlot(ctx, node, key, "default", false, null));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export class Portal extends Component {
|
||||||
|
static template = "__portal__";
|
||||||
|
static props = {
|
||||||
|
target: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
slots: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
setup() {
|
||||||
|
const node: any = this.__owl__;
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
const portal: VPortal = node.bdom;
|
||||||
|
if (!portal.target) {
|
||||||
|
const target: HTMLElement = document.querySelector(this.props.target);
|
||||||
|
if (target) {
|
||||||
|
portal.content!.moveBeforeDOMNode(target.firstChild, target);
|
||||||
|
} else {
|
||||||
|
throw new OwlError("invalid portal target");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
onWillUnmount(() => {
|
||||||
|
const portal: VPortal = node.bdom;
|
||||||
|
portal.remove();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,464 @@
|
|||||||
|
import type { Callback } from "./utils";
|
||||||
|
import { OwlError } from "./error_handling";
|
||||||
|
|
||||||
|
// Special key to subscribe to, to be notified of key creation/deletion
|
||||||
|
const KEYCHANGES = Symbol("Key changes");
|
||||||
|
// Used to specify the absence of a callback, can be used as WeakMap key but
|
||||||
|
// should only be used as a sentinel value and never called.
|
||||||
|
const NO_CALLBACK = () => {
|
||||||
|
throw new Error("Called NO_CALLBACK. Owl is broken, please report this to the maintainers.");
|
||||||
|
};
|
||||||
|
|
||||||
|
// The following types only exist to signify places where objects are expected
|
||||||
|
// to be reactive or not, they provide no type checking benefit over "object"
|
||||||
|
type Target = object;
|
||||||
|
type Reactive<T extends Target> = T;
|
||||||
|
|
||||||
|
type Collection = Set<any> | Map<any, any> | WeakMap<any, any>;
|
||||||
|
type CollectionRawType = "Set" | "Map" | "WeakMap";
|
||||||
|
|
||||||
|
const objectToString = Object.prototype.toString;
|
||||||
|
const objectHasOwnProperty = Object.prototype.hasOwnProperty;
|
||||||
|
|
||||||
|
const SUPPORTED_RAW_TYPES = new Set(["Object", "Array", "Set", "Map", "WeakMap"]);
|
||||||
|
const COLLECTION_RAWTYPES = new Set(["Set", "Map", "WeakMap"]);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* extract "RawType" from strings like "[object RawType]" => this lets us ignore
|
||||||
|
* many native objects such as Promise (whose toString is [object Promise])
|
||||||
|
* or Date ([object Date]), while also supporting collections without using
|
||||||
|
* instanceof in a loop
|
||||||
|
*
|
||||||
|
* @param obj the object to check
|
||||||
|
* @returns the raw type of the object
|
||||||
|
*/
|
||||||
|
function rawType(obj: any) {
|
||||||
|
return objectToString.call(toRaw(obj)).slice(8, -1);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Checks whether a given value can be made into a reactive object.
|
||||||
|
*
|
||||||
|
* @param value the value to check
|
||||||
|
* @returns whether the value can be made reactive
|
||||||
|
*/
|
||||||
|
function canBeMadeReactive(value: any): boolean {
|
||||||
|
if (typeof value !== "object") {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return SUPPORTED_RAW_TYPES.has(rawType(value));
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Creates a reactive from the given object/callback if possible and returns it,
|
||||||
|
* returns the original object otherwise.
|
||||||
|
*
|
||||||
|
* @param value the value make reactive
|
||||||
|
* @returns a reactive for the given object when possible, the original otherwise
|
||||||
|
*/
|
||||||
|
function possiblyReactive(val: any, cb: Callback) {
|
||||||
|
return canBeMadeReactive(val) ? reactive(val, cb) : val;
|
||||||
|
}
|
||||||
|
|
||||||
|
const skipped = new WeakSet<Target>();
|
||||||
|
/**
|
||||||
|
* Mark an object or array so that it is ignored by the reactivity system
|
||||||
|
*
|
||||||
|
* @param value the value to mark
|
||||||
|
* @returns the object itself
|
||||||
|
*/
|
||||||
|
export function markRaw<T extends Target>(value: T): T {
|
||||||
|
skipped.add(value);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given a reactive objet, return the raw (non reactive) underlying object
|
||||||
|
*
|
||||||
|
* @param value a reactive value
|
||||||
|
* @returns the underlying value
|
||||||
|
*/
|
||||||
|
export function toRaw<T extends Target, U extends Reactive<T>>(value: U | T): T {
|
||||||
|
return targets.has(value) ? (targets.get(value) as T) : value;
|
||||||
|
}
|
||||||
|
|
||||||
|
const targetToKeysToCallbacks = new WeakMap<Target, Map<PropertyKey, Set<Callback>>>();
|
||||||
|
/**
|
||||||
|
* Observes a given key on a target with an callback. The callback will be
|
||||||
|
* called when the given key changes on the target.
|
||||||
|
*
|
||||||
|
* @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: PropertyKey, callback: Callback): void {
|
||||||
|
if (callback === NO_CALLBACK) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!targetToKeysToCallbacks.get(target)) {
|
||||||
|
targetToKeysToCallbacks.set(target, new Map());
|
||||||
|
}
|
||||||
|
const keyToCallbacks = targetToKeysToCallbacks.get(target)!;
|
||||||
|
if (!keyToCallbacks.get(key)) {
|
||||||
|
keyToCallbacks.set(key, new Set());
|
||||||
|
}
|
||||||
|
keyToCallbacks.get(key)!.add(callback);
|
||||||
|
if (!callbacksToTargets.has(callback)) {
|
||||||
|
callbacksToTargets.set(callback, new Set());
|
||||||
|
}
|
||||||
|
callbacksToTargets.get(callback)!.add(target);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Notify Reactives that are observing a given target that a key has changed on
|
||||||
|
* the target.
|
||||||
|
*
|
||||||
|
* @param target target whose Reactives should be notified that the target was
|
||||||
|
* changed.
|
||||||
|
* @param key the key that changed (or Symbol `KEYCHANGES` if a key was created
|
||||||
|
* or deleted)
|
||||||
|
*/
|
||||||
|
function notifyReactives(target: Target, key: PropertyKey): void {
|
||||||
|
const keyToCallbacks = targetToKeysToCallbacks.get(target);
|
||||||
|
if (!keyToCallbacks) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const callbacks = keyToCallbacks.get(key);
|
||||||
|
if (!callbacks) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Loop on copy because clearReactivesForCallback will modify the set in place
|
||||||
|
for (const callback of [...callbacks]) {
|
||||||
|
clearReactivesForCallback(callback);
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const callbacksToTargets = new WeakMap<Callback, Set<Target>>();
|
||||||
|
/**
|
||||||
|
* Clears all subscriptions of the Reactives associated with a given callback.
|
||||||
|
*
|
||||||
|
* @param callback the callback for which the reactives need to be cleared
|
||||||
|
*/
|
||||||
|
export 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 [key, callbacks] of observedKeys.entries()) {
|
||||||
|
callbacks.delete(callback);
|
||||||
|
if (!callbacks.size) {
|
||||||
|
observedKeys.delete(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
targetsToClear.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getSubscriptions(callback: Callback) {
|
||||||
|
const targets = callbacksToTargets.get(callback) || [];
|
||||||
|
return [...targets].map((target) => {
|
||||||
|
const keysToCallbacks = targetToKeysToCallbacks.get(target);
|
||||||
|
let keys = [];
|
||||||
|
if (keysToCallbacks) {
|
||||||
|
for (const [key, cbs] of keysToCallbacks) {
|
||||||
|
if (cbs.has(callback)) {
|
||||||
|
keys.push(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return { target, keys };
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// Maps reactive objects to the underlying target
|
||||||
|
export const targets = new WeakMap<Reactive<Target>, Target>();
|
||||||
|
const reactiveCache = new WeakMap<Target, WeakMap<Callback, Reactive<Target>>>();
|
||||||
|
/**
|
||||||
|
* 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's 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 = NO_CALLBACK): T {
|
||||||
|
if (!canBeMadeReactive(target)) {
|
||||||
|
throw new OwlError(`Cannot make the given value reactive`);
|
||||||
|
}
|
||||||
|
if (skipped.has(target)) {
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
if (targets.has(target)) {
|
||||||
|
// target is reactive, create a reactive on the underlying object instead
|
||||||
|
return reactive(targets.get(target) as T, callback);
|
||||||
|
}
|
||||||
|
if (!reactiveCache.has(target)) {
|
||||||
|
reactiveCache.set(target, new WeakMap());
|
||||||
|
}
|
||||||
|
const reactivesForTarget = reactiveCache.get(target)!;
|
||||||
|
if (!reactivesForTarget.has(callback)) {
|
||||||
|
const targetRawType = rawType(target);
|
||||||
|
const handler = COLLECTION_RAWTYPES.has(targetRawType)
|
||||||
|
? collectionsProxyHandler(target as Collection, callback, targetRawType as CollectionRawType)
|
||||||
|
: basicProxyHandler<T>(callback);
|
||||||
|
const proxy = new Proxy(target, handler as ProxyHandler<T>) as Reactive<T>;
|
||||||
|
reactivesForTarget.set(callback, proxy);
|
||||||
|
targets.set(proxy, target);
|
||||||
|
}
|
||||||
|
return reactivesForTarget.get(callback) as Reactive<T>;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Creates a basic proxy handler for regular objects and arrays.
|
||||||
|
*
|
||||||
|
* @param callback @see reactive
|
||||||
|
* @returns a proxy handler object
|
||||||
|
*/
|
||||||
|
function basicProxyHandler<T extends Target>(callback: Callback): ProxyHandler<T> {
|
||||||
|
return {
|
||||||
|
get(target, key, receiver) {
|
||||||
|
// non-writable non-configurable properties cannot be made reactive
|
||||||
|
const desc = Object.getOwnPropertyDescriptor(target, key);
|
||||||
|
if (desc && !desc.writable && !desc.configurable) {
|
||||||
|
return Reflect.get(target, key, receiver);
|
||||||
|
}
|
||||||
|
observeTargetKey(target, key, callback);
|
||||||
|
return possiblyReactive(Reflect.get(target, key, receiver), callback);
|
||||||
|
},
|
||||||
|
set(target, key, value, receiver) {
|
||||||
|
const hadKey = objectHasOwnProperty.call(target, key);
|
||||||
|
const originalValue = Reflect.get(target, key, receiver);
|
||||||
|
const ret = Reflect.set(target, key, value, receiver);
|
||||||
|
if (!hadKey && objectHasOwnProperty.call(target, key)) {
|
||||||
|
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 !== Reflect.get(target, key, receiver) ||
|
||||||
|
(key === "length" && Array.isArray(target))
|
||||||
|
) {
|
||||||
|
notifyReactives(target, key);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
},
|
||||||
|
deleteProperty(target, key) {
|
||||||
|
const ret = Reflect.deleteProperty(target, key);
|
||||||
|
// TODO: only notify when something was actually deleted
|
||||||
|
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
|
||||||
|
// observing the key itself would observe value changes instead of presence changes
|
||||||
|
// so we may need a finer grained system to distinguish observing value vs presence.
|
||||||
|
observeTargetKey(target, KEYCHANGES, callback);
|
||||||
|
return Reflect.has(target, key);
|
||||||
|
},
|
||||||
|
} as ProxyHandler<T>;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Creates a function that will observe the key that is passed to it when called
|
||||||
|
* and delegates to the underlying method.
|
||||||
|
*
|
||||||
|
* @param methodName name of the method to delegate to
|
||||||
|
* @param target @see reactive
|
||||||
|
* @param callback @see reactive
|
||||||
|
*/
|
||||||
|
function makeKeyObserver(methodName: "has" | "get", target: any, callback: Callback) {
|
||||||
|
return (key: any) => {
|
||||||
|
key = toRaw(key);
|
||||||
|
observeTargetKey(target, key, callback);
|
||||||
|
return possiblyReactive(target[methodName](key), callback);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Creates an iterable that will delegate to the underlying iteration method and
|
||||||
|
* observe keys as necessary.
|
||||||
|
*
|
||||||
|
* @param methodName name of the method to delegate to
|
||||||
|
* @param target @see reactive
|
||||||
|
* @param callback @see reactive
|
||||||
|
*/
|
||||||
|
function makeIteratorObserver(
|
||||||
|
methodName: "keys" | "values" | "entries" | typeof Symbol.iterator,
|
||||||
|
target: any,
|
||||||
|
callback: Callback
|
||||||
|
) {
|
||||||
|
return function* () {
|
||||||
|
observeTargetKey(target, KEYCHANGES, callback);
|
||||||
|
const keys = target.keys();
|
||||||
|
for (const item of target[methodName]()) {
|
||||||
|
const key = keys.next().value;
|
||||||
|
observeTargetKey(target, key, callback);
|
||||||
|
yield possiblyReactive(item, callback);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Creates a forEach function that will delegate to forEach on the underlying
|
||||||
|
* collection while observing key changes, and keys as they're iterated over,
|
||||||
|
* and making the passed keys/values reactive.
|
||||||
|
*
|
||||||
|
* @param target @see reactive
|
||||||
|
* @param callback @see reactive
|
||||||
|
*/
|
||||||
|
function makeForEachObserver(target: any, callback: Callback) {
|
||||||
|
return function forEach(forEachCb: (val: any, key: any, target: any) => void, thisArg: any) {
|
||||||
|
observeTargetKey(target, KEYCHANGES, callback);
|
||||||
|
target.forEach(function (val: any, key: any, targetObj: any) {
|
||||||
|
observeTargetKey(target, key, callback);
|
||||||
|
forEachCb.call(
|
||||||
|
thisArg,
|
||||||
|
possiblyReactive(val, callback),
|
||||||
|
possiblyReactive(key, callback),
|
||||||
|
possiblyReactive(targetObj, callback)
|
||||||
|
);
|
||||||
|
}, thisArg);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Creates a function that will delegate to an underlying method, and check if
|
||||||
|
* that method has modified the presence or value of a key, and notify the
|
||||||
|
* reactives appropriately.
|
||||||
|
*
|
||||||
|
* @param setterName name of the method to delegate to
|
||||||
|
* @param getterName name of the method which should be used to retrieve the
|
||||||
|
* value before calling the delegate method for comparison purposes
|
||||||
|
* @param target @see reactive
|
||||||
|
*/
|
||||||
|
function delegateAndNotify(
|
||||||
|
setterName: "set" | "add" | "delete",
|
||||||
|
getterName: "has" | "get",
|
||||||
|
target: any
|
||||||
|
) {
|
||||||
|
return (key: any, value: any) => {
|
||||||
|
key = toRaw(key);
|
||||||
|
const hadKey = target.has(key);
|
||||||
|
const originalValue = target[getterName](key);
|
||||||
|
const ret = target[setterName](key, value);
|
||||||
|
const hasKey = target.has(key);
|
||||||
|
if (hadKey !== hasKey) {
|
||||||
|
notifyReactives(target, KEYCHANGES);
|
||||||
|
}
|
||||||
|
if (originalValue !== value) {
|
||||||
|
notifyReactives(target, key);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Creates a function that will clear the underlying collection and notify that
|
||||||
|
* the keys of the collection have changed.
|
||||||
|
*
|
||||||
|
* @param target @see reactive
|
||||||
|
*/
|
||||||
|
function makeClearNotifier(target: Map<any, any> | Set<any>) {
|
||||||
|
return () => {
|
||||||
|
const allKeys = [...target.keys()];
|
||||||
|
target.clear();
|
||||||
|
notifyReactives(target, KEYCHANGES);
|
||||||
|
for (const key of allKeys) {
|
||||||
|
notifyReactives(target, key);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Maps raw type of an object to an object containing functions that can be used
|
||||||
|
* to build an appropritate proxy handler for that raw type. Eg: when making a
|
||||||
|
* reactive set, calling the has method should mark the key that is being
|
||||||
|
* retrieved as observed, and calling the add or delete method should notify the
|
||||||
|
* reactives that the key which is being added or deleted has been modified.
|
||||||
|
*/
|
||||||
|
const rawTypeToFuncHandlers = {
|
||||||
|
Set: (target: any, callback: Callback) => ({
|
||||||
|
has: makeKeyObserver("has", target, callback),
|
||||||
|
add: delegateAndNotify("add", "has", target),
|
||||||
|
delete: delegateAndNotify("delete", "has", target),
|
||||||
|
keys: makeIteratorObserver("keys", target, callback),
|
||||||
|
values: makeIteratorObserver("values", target, callback),
|
||||||
|
entries: makeIteratorObserver("entries", target, callback),
|
||||||
|
[Symbol.iterator]: makeIteratorObserver(Symbol.iterator, target, callback),
|
||||||
|
forEach: makeForEachObserver(target, callback),
|
||||||
|
clear: makeClearNotifier(target),
|
||||||
|
get size() {
|
||||||
|
observeTargetKey(target, KEYCHANGES, callback);
|
||||||
|
return target.size;
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
Map: (target: any, callback: Callback) => ({
|
||||||
|
has: makeKeyObserver("has", target, callback),
|
||||||
|
get: makeKeyObserver("get", target, callback),
|
||||||
|
set: delegateAndNotify("set", "get", target),
|
||||||
|
delete: delegateAndNotify("delete", "has", target),
|
||||||
|
keys: makeIteratorObserver("keys", target, callback),
|
||||||
|
values: makeIteratorObserver("values", target, callback),
|
||||||
|
entries: makeIteratorObserver("entries", target, callback),
|
||||||
|
[Symbol.iterator]: makeIteratorObserver(Symbol.iterator, target, callback),
|
||||||
|
forEach: makeForEachObserver(target, callback),
|
||||||
|
clear: makeClearNotifier(target),
|
||||||
|
get size() {
|
||||||
|
observeTargetKey(target, KEYCHANGES, callback);
|
||||||
|
return target.size;
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
WeakMap: (target: any, callback: Callback) => ({
|
||||||
|
has: makeKeyObserver("has", target, callback),
|
||||||
|
get: makeKeyObserver("get", target, callback),
|
||||||
|
set: delegateAndNotify("set", "get", target),
|
||||||
|
delete: delegateAndNotify("delete", "has", target),
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* Creates a proxy handler for collections (Set/Map/WeakMap)
|
||||||
|
*
|
||||||
|
* @param callback @see reactive
|
||||||
|
* @param target @see reactive
|
||||||
|
* @returns a proxy handler object
|
||||||
|
*/
|
||||||
|
function collectionsProxyHandler<T extends Collection>(
|
||||||
|
target: T,
|
||||||
|
callback: Callback,
|
||||||
|
targetRawType: CollectionRawType
|
||||||
|
): ProxyHandler<T> {
|
||||||
|
// TODO: if performance is an issue we can create the special handlers lazily when each
|
||||||
|
// property is read.
|
||||||
|
const specialHandlers = rawTypeToFuncHandlers[targetRawType](target, callback);
|
||||||
|
return Object.assign(basicProxyHandler(callback), {
|
||||||
|
// FIXME: probably broken when part of prototype chain since we ignore the receiver
|
||||||
|
get(target: any, key: PropertyKey) {
|
||||||
|
if (objectHasOwnProperty.call(specialHandlers, key)) {
|
||||||
|
return (specialHandlers as any)[key];
|
||||||
|
}
|
||||||
|
observeTargetKey(target, key, callback);
|
||||||
|
return possiblyReactive(target[key], callback);
|
||||||
|
},
|
||||||
|
}) as ProxyHandler<T>;
|
||||||
|
}
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
import { fibersInError } from "./error_handling";
|
||||||
|
import { Fiber, RootFiber } from "./fibers";
|
||||||
|
import { STATUS } from "./status";
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// Scheduler
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
export class Scheduler {
|
||||||
|
// capture the value of requestAnimationFrame as soon as possible, to avoid
|
||||||
|
// interactions with other code, such as test frameworks that override them
|
||||||
|
static requestAnimationFrame = window.requestAnimationFrame.bind(window);
|
||||||
|
tasks: Set<RootFiber> = new Set();
|
||||||
|
requestAnimationFrame: Window["requestAnimationFrame"];
|
||||||
|
frame: number = 0;
|
||||||
|
delayedRenders: Fiber[] = [];
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.requestAnimationFrame = Scheduler.requestAnimationFrame;
|
||||||
|
}
|
||||||
|
|
||||||
|
addFiber(fiber: Fiber) {
|
||||||
|
this.tasks.add(fiber.root!);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process all current tasks. This only applies to the fibers that are ready.
|
||||||
|
* Other tasks are left unchanged.
|
||||||
|
*/
|
||||||
|
flush() {
|
||||||
|
if (this.delayedRenders.length) {
|
||||||
|
let renders = this.delayedRenders;
|
||||||
|
this.delayedRenders = [];
|
||||||
|
for (let f of renders) {
|
||||||
|
if (f.root && f.node.status !== STATUS.DESTROYED && f.node.fiber === f) {
|
||||||
|
f.render();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.frame === 0) {
|
||||||
|
this.frame = this.requestAnimationFrame(() => {
|
||||||
|
this.frame = 0;
|
||||||
|
this.tasks.forEach((fiber) => this.processFiber(fiber));
|
||||||
|
for (let task of this.tasks) {
|
||||||
|
if (task.node.status === STATUS.DESTROYED) {
|
||||||
|
this.tasks.delete(task);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
processFiber(fiber: RootFiber) {
|
||||||
|
if (fiber.root !== fiber) {
|
||||||
|
this.tasks.delete(fiber);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const hasError = fibersInError.has(fiber);
|
||||||
|
if (hasError && fiber.counter !== 0) {
|
||||||
|
this.tasks.delete(fiber);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (fiber.node.status === STATUS.DESTROYED) {
|
||||||
|
this.tasks.delete(fiber);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fiber.counter === 0) {
|
||||||
|
if (!hasError) {
|
||||||
|
fiber.complete();
|
||||||
|
}
|
||||||
|
this.tasks.delete(fiber);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,283 @@
|
|||||||
|
import { BDom, multi, text, toggler, createCatcher } from "./blockdom";
|
||||||
|
import { Markup } from "./utils";
|
||||||
|
import { html } from "./blockdom/index";
|
||||||
|
import { isOptional, validateSchema } from "./validation";
|
||||||
|
import type { ComponentConstructor } from "./component";
|
||||||
|
import { markRaw } from "./reactivity";
|
||||||
|
import { OwlError } from "./error_handling";
|
||||||
|
|
||||||
|
const ObjectCreate = Object.create;
|
||||||
|
/**
|
||||||
|
* 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 {
|
||||||
|
key = key + "__slot_" + name;
|
||||||
|
const slots = ctx.props.slots || {};
|
||||||
|
const { __render, __ctx, __scope } = slots[name] || {};
|
||||||
|
const slotScope = ObjectCreate(__ctx || {});
|
||||||
|
if (__scope) {
|
||||||
|
slotScope[__scope] = extra;
|
||||||
|
}
|
||||||
|
const slotBDom = __render ? __render(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(ctx, parent, key);
|
||||||
|
}
|
||||||
|
return multi([child1, child2]);
|
||||||
|
}
|
||||||
|
return slotBDom || text("");
|
||||||
|
}
|
||||||
|
|
||||||
|
function capture(ctx: any): any {
|
||||||
|
const result = ObjectCreate(ctx);
|
||||||
|
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 OwlError("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;
|
||||||
|
}
|
||||||
|
|
||||||
|
class LazyValue {
|
||||||
|
fn: any;
|
||||||
|
ctx: any;
|
||||||
|
component: any;
|
||||||
|
node: any;
|
||||||
|
key: any;
|
||||||
|
|
||||||
|
constructor(fn: any, ctx: any, component: any, node: any, key: any) {
|
||||||
|
this.fn = fn;
|
||||||
|
this.ctx = capture(ctx);
|
||||||
|
this.component = component;
|
||||||
|
this.node = node;
|
||||||
|
this.key = key;
|
||||||
|
}
|
||||||
|
|
||||||
|
evaluate(): any {
|
||||||
|
return this.fn.call(this.component, this.ctx, this.node, this.key);
|
||||||
|
}
|
||||||
|
|
||||||
|
toString() {
|
||||||
|
return this.evaluate().toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Safely outputs `value` as a block depending on the nature of `value`
|
||||||
|
*/
|
||||||
|
export function safeOutput(value: any, defaultValue?: any): ReturnType<typeof toggler> {
|
||||||
|
if (value === undefined) {
|
||||||
|
return defaultValue ? toggler("default", defaultValue) : toggler("undefined", text(""));
|
||||||
|
}
|
||||||
|
let safeKey;
|
||||||
|
let block;
|
||||||
|
switch (typeof value) {
|
||||||
|
case "object":
|
||||||
|
if (value instanceof Markup) {
|
||||||
|
safeKey = `string_safe`;
|
||||||
|
block = html(value as string);
|
||||||
|
} else if (value instanceof LazyValue) {
|
||||||
|
safeKey = `lazy_value`;
|
||||||
|
block = value.evaluate();
|
||||||
|
} else if (value instanceof String) {
|
||||||
|
safeKey = "string_unsafe";
|
||||||
|
block = text(value);
|
||||||
|
} else {
|
||||||
|
// Assuming it is a block
|
||||||
|
safeKey = "block_safe";
|
||||||
|
block = value;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "string":
|
||||||
|
safeKey = "string_unsafe";
|
||||||
|
block = text(value);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
safeKey = "string_unsafe";
|
||||||
|
block = text(String(value));
|
||||||
|
}
|
||||||
|
return toggler(safeKey, block);
|
||||||
|
}
|
||||||
|
|
||||||
|
let boundFunctions = new WeakMap();
|
||||||
|
const WeakMapGet = WeakMap.prototype.get;
|
||||||
|
const WeakMapSet = WeakMap.prototype.set;
|
||||||
|
|
||||||
|
function bind(component: any, fn: Function): Function {
|
||||||
|
let boundFnMap = WeakMapGet.call(boundFunctions, component);
|
||||||
|
if (!boundFnMap) {
|
||||||
|
boundFnMap = new WeakMap();
|
||||||
|
WeakMapSet.call(boundFunctions, component, boundFnMap);
|
||||||
|
}
|
||||||
|
let boundFn = WeakMapGet.call(boundFnMap, fn);
|
||||||
|
if (!boundFn) {
|
||||||
|
boundFn = fn.bind(component);
|
||||||
|
WeakMapSet.call(boundFnMap, fn, boundFn);
|
||||||
|
}
|
||||||
|
return boundFn;
|
||||||
|
}
|
||||||
|
|
||||||
|
type RefMap = { [key: string]: HTMLElement | null };
|
||||||
|
type RefSetter = (el: HTMLElement | null) => void;
|
||||||
|
|
||||||
|
function multiRefSetter(refs: RefMap, name: string): RefSetter {
|
||||||
|
let count = 0;
|
||||||
|
return (el) => {
|
||||||
|
if (el) {
|
||||||
|
count++;
|
||||||
|
if (count > 1) {
|
||||||
|
throw new OwlError("Cannot have 2 elements with same ref name at the same time");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (count === 0 || el) {
|
||||||
|
refs[name] = el;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function singleRefSetter(refs: RefMap, name: string): RefSetter {
|
||||||
|
let _el: HTMLElement | null = null;
|
||||||
|
return (el) => {
|
||||||
|
if (el || refs[name] === _el) {
|
||||||
|
refs[name] = el;
|
||||||
|
_el = el;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 function validateProps<P>(name: string | ComponentConstructor<P>, props: P, comp?: any) {
|
||||||
|
const ComponentClass =
|
||||||
|
typeof name !== "string"
|
||||||
|
? name
|
||||||
|
: (comp.constructor.components[name] as ComponentConstructor<P> | undefined);
|
||||||
|
|
||||||
|
if (!ComponentClass) {
|
||||||
|
// this is an error, wrong component. We silently return here instead so the
|
||||||
|
// error is triggered by the usual path ('component' function)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const schema = ComponentClass.props;
|
||||||
|
if (!schema) {
|
||||||
|
if (comp.__owl__.app.warnIfNoStaticProps) {
|
||||||
|
console.warn(`Component '${ComponentClass.name}' does not have a static props description`);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const defaultProps = ComponentClass.defaultProps;
|
||||||
|
if (defaultProps) {
|
||||||
|
let isMandatory = (name: string) =>
|
||||||
|
Array.isArray(schema)
|
||||||
|
? schema.includes(name)
|
||||||
|
: name in schema && !("*" in schema) && !isOptional(schema[name]);
|
||||||
|
for (let p in defaultProps) {
|
||||||
|
if (isMandatory(p)) {
|
||||||
|
throw new OwlError(
|
||||||
|
`A default value cannot be defined for a mandatory prop (name: '${p}', component: ${ComponentClass.name})`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const errors = validateSchema(props, schema);
|
||||||
|
if (errors.length) {
|
||||||
|
throw new OwlError(
|
||||||
|
`Invalid props for component '${ComponentClass.name}': ` + errors.join(", ")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const helpers = {
|
||||||
|
withDefault,
|
||||||
|
zero: Symbol("zero"),
|
||||||
|
isBoundary,
|
||||||
|
callSlot,
|
||||||
|
capture,
|
||||||
|
withKey,
|
||||||
|
prepareList,
|
||||||
|
setContextValue,
|
||||||
|
multiRefSetter,
|
||||||
|
singleRefSetter,
|
||||||
|
shallowEqual,
|
||||||
|
toNumber,
|
||||||
|
validateProps,
|
||||||
|
LazyValue,
|
||||||
|
safeOutput,
|
||||||
|
bind,
|
||||||
|
createCatcher,
|
||||||
|
markRaw,
|
||||||
|
OwlError,
|
||||||
|
};
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
import { createBlock, html, list, multi, text, toggler, comment } from "../blockdom";
|
import { compile, Template, TemplateFunction } from "../compiler";
|
||||||
import { compile, Template } from "../compiler";
|
import { comment, createBlock, html, list, multi, text, toggler } from "./blockdom";
|
||||||
import { component } from "../component/component_node";
|
import { getCurrent } from "./component_node";
|
||||||
import { UTILS } from "./template_helpers";
|
import { Portal, portalTemplate } from "./portal";
|
||||||
|
import { helpers } from "./template_helpers";
|
||||||
|
import { OwlError } from "./error_handling";
|
||||||
|
|
||||||
const bdom = { text, createBlock, list, multi, html, toggler, component, comment };
|
const bdom = { text, createBlock, list, multi, html, toggler, comment };
|
||||||
|
|
||||||
export const globalTemplates: { [key: string]: string | Node } = {};
|
|
||||||
|
|
||||||
function parseXML(xml: string): Document {
|
function parseXML(xml: string): Document {
|
||||||
const parser = new DOMParser();
|
const parser = new DOMParser();
|
||||||
@@ -32,7 +32,7 @@ function parseXML(xml: string): Document {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new Error(msg);
|
throw new OwlError(msg);
|
||||||
}
|
}
|
||||||
return doc;
|
return doc;
|
||||||
}
|
}
|
||||||
@@ -45,18 +45,15 @@ export interface TemplateSetConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class TemplateSet {
|
export class TemplateSet {
|
||||||
|
static registerTemplate(name: string, fn: TemplateFunction) {
|
||||||
|
globalTemplates[name] = fn;
|
||||||
|
}
|
||||||
dev: boolean;
|
dev: boolean;
|
||||||
rawTemplates: typeof globalTemplates = Object.create(globalTemplates);
|
rawTemplates: typeof globalTemplates = Object.create(globalTemplates);
|
||||||
templates: { [name: string]: Template } = {};
|
templates: { [name: string]: Template } = {};
|
||||||
translateFn?: (s: string) => string;
|
translateFn?: (s: string) => string;
|
||||||
translatableAttributes?: string[];
|
translatableAttributes?: string[];
|
||||||
utils: typeof UTILS = Object.assign({}, UTILS, {
|
Portal = Portal;
|
||||||
call: (owner: any, subTemplate: string, ctx: any, parent: any, key: any) => {
|
|
||||||
const template = this.getTemplate(subTemplate);
|
|
||||||
return toggler(subTemplate, template.call(owner, ctx, parent, key));
|
|
||||||
},
|
|
||||||
getTemplate: (name: string) => this.getTemplate(name),
|
|
||||||
});
|
|
||||||
|
|
||||||
constructor(config: TemplateSetConfig = {}) {
|
constructor(config: TemplateSetConfig = {}) {
|
||||||
this.dev = config.dev || false;
|
this.dev = config.dev || false;
|
||||||
@@ -67,14 +64,25 @@ export class TemplateSet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addTemplate(name: string, template: string | Node, options: { allowDuplicate?: boolean } = {}) {
|
addTemplate(name: string, template: string | Element) {
|
||||||
if (name in this.rawTemplates && !options.allowDuplicate) {
|
if (name in this.rawTemplates) {
|
||||||
throw new Error(`Template ${name} already defined`);
|
const rawTemplate = this.rawTemplates[name];
|
||||||
|
const currentAsString =
|
||||||
|
typeof rawTemplate === "string"
|
||||||
|
? rawTemplate
|
||||||
|
: rawTemplate instanceof Element
|
||||||
|
? rawTemplate.outerHTML
|
||||||
|
: rawTemplate.toString();
|
||||||
|
const newAsString = typeof template === "string" ? template : template.outerHTML;
|
||||||
|
if (currentAsString === newAsString) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
throw new OwlError(`Template ${name} already defined with different content`);
|
||||||
}
|
}
|
||||||
this.rawTemplates[name] = template;
|
this.rawTemplates[name] = template;
|
||||||
}
|
}
|
||||||
|
|
||||||
addTemplates(xml: string | Document, options: { allowDuplicate?: boolean } = {}) {
|
addTemplates(xml: string | Document) {
|
||||||
if (!xml) {
|
if (!xml) {
|
||||||
// empty string
|
// empty string
|
||||||
return;
|
return;
|
||||||
@@ -82,8 +90,7 @@ export class TemplateSet {
|
|||||||
xml = xml instanceof Document ? xml : parseXML(xml);
|
xml = xml instanceof Document ? xml : parseXML(xml);
|
||||||
for (const template of xml.querySelectorAll("[t-name]")) {
|
for (const template of xml.querySelectorAll("[t-name]")) {
|
||||||
const name = template.getAttribute("t-name")!;
|
const name = template.getAttribute("t-name")!;
|
||||||
template.removeAttribute("t-name");
|
this.addTemplate(name, template);
|
||||||
this.addTemplate(name, template, options);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,34 +98,42 @@ export class TemplateSet {
|
|||||||
if (!(name in this.templates)) {
|
if (!(name in this.templates)) {
|
||||||
const rawTemplate = this.rawTemplates[name];
|
const rawTemplate = this.rawTemplates[name];
|
||||||
if (rawTemplate === undefined) {
|
if (rawTemplate === undefined) {
|
||||||
throw new Error(`Missing template: "${name}"`);
|
let extraInfo = "";
|
||||||
|
try {
|
||||||
|
const componentName = getCurrent().component.constructor.name;
|
||||||
|
extraInfo = ` (for component "${componentName}")`;
|
||||||
|
} catch {}
|
||||||
|
throw new OwlError(`Missing template: "${name}"${extraInfo}`);
|
||||||
}
|
}
|
||||||
const templateFn = this._compileTemplate(name, rawTemplate);
|
const isFn = typeof rawTemplate === "function" && !(rawTemplate instanceof Element);
|
||||||
|
const templateFn = isFn ? rawTemplate : this._compileTemplate(name, rawTemplate);
|
||||||
// first add a function to lazily get the template, in case there is a
|
// first add a function to lazily get the template, in case there is a
|
||||||
// recursive call to the template name
|
// recursive call to the template name
|
||||||
const templates = this.templates;
|
const templates = this.templates;
|
||||||
this.templates[name] = function (context, parent) {
|
this.templates[name] = function (context, parent) {
|
||||||
return templates[name].call(this, context, parent);
|
return templates[name].call(this, context, parent);
|
||||||
};
|
};
|
||||||
const template = templateFn(bdom, this.utils);
|
const template = templateFn(this, bdom, helpers);
|
||||||
this.templates[name] = template;
|
this.templates[name] = template;
|
||||||
}
|
}
|
||||||
return this.templates[name];
|
return this.templates[name];
|
||||||
}
|
}
|
||||||
|
|
||||||
_compileTemplate(name: string, template: string | Node) {
|
_compileTemplate(name: string, template: string | Element): ReturnType<typeof compile> {
|
||||||
return compile(template, {
|
throw new OwlError(`Unable to compile a template. Please use owl full build instead`);
|
||||||
name,
|
}
|
||||||
dev: this.dev,
|
|
||||||
translateFn: this.translateFn,
|
callTemplate(owner: any, subTemplate: string, ctx: any, parent: any, key: any): any {
|
||||||
translatableAttributes: this.translatableAttributes,
|
const template = this.getTemplate(subTemplate);
|
||||||
});
|
return toggler(subTemplate, template.call(owner, ctx, parent, key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// xml tag helper
|
// xml tag helper
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
export const globalTemplates: { [key: string]: string | Element | TemplateFunction } = {};
|
||||||
|
|
||||||
export function xml(...args: Parameters<typeof String.raw>) {
|
export function xml(...args: Parameters<typeof String.raw>) {
|
||||||
const name = `__template__${xml.nextId++}`;
|
const name = `__template__${xml.nextId++}`;
|
||||||
const value = String.raw(...args);
|
const value = String.raw(...args);
|
||||||
@@ -127,3 +142,5 @@ export function xml(...args: Parameters<typeof String.raw>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
xml.nextId = 1;
|
xml.nextId = 1;
|
||||||
|
|
||||||
|
TemplateSet.registerTemplate("__portal__", portalTemplate);
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { OwlError } from "./error_handling";
|
||||||
export type Callback = () => void;
|
export type Callback = () => void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -15,15 +16,32 @@ export function batched(callback: Callback): Callback {
|
|||||||
await Promise.resolve();
|
await Promise.resolve();
|
||||||
if (!called) {
|
if (!called) {
|
||||||
called = true;
|
called = true;
|
||||||
callback();
|
|
||||||
// wait for all calls in this microtick to fall through before resetting "called"
|
// wait for all calls in this microtick to fall through before resetting "called"
|
||||||
// so that only the first call to the batched function calls the original callback
|
// so that only the first call to the batched function calls the original callback.
|
||||||
await Promise.resolve();
|
// Schedule this before calling the callback so that calls to the batched function
|
||||||
called = false;
|
// within the callback will proceed only after resetting called to false, and have
|
||||||
|
// a chance to execute the callback again
|
||||||
|
Promise.resolve().then(() => (called = false));
|
||||||
|
callback();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function validateTarget(target: HTMLElement) {
|
||||||
|
// Get the document and HTMLElement corresponding to the target to allow mounting in iframes
|
||||||
|
const document = target && target.ownerDocument;
|
||||||
|
if (document) {
|
||||||
|
const HTMLElement = document.defaultView!.HTMLElement;
|
||||||
|
if (target instanceof HTMLElement) {
|
||||||
|
if (!document.body.contains(target)) {
|
||||||
|
throw new OwlError("Cannot mount a component on a detached dom node");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new OwlError("Cannot mount component: the target is not a valid DOM element");
|
||||||
|
}
|
||||||
|
|
||||||
export class EventBus extends EventTarget {
|
export class EventBus extends EventTarget {
|
||||||
trigger(name: string, payload?: any) {
|
trigger(name: string, payload?: any) {
|
||||||
this.dispatchEvent(new CustomEvent(name, { detail: payload }));
|
this.dispatchEvent(new CustomEvent(name, { detail: payload }));
|
||||||
@@ -43,7 +61,7 @@ export function whenReady(fn?: any): Promise<void> {
|
|||||||
export async function loadFile(url: string): Promise<string> {
|
export async function loadFile(url: string): Promise<string> {
|
||||||
const result = await fetch(url);
|
const result = await fetch(url);
|
||||||
if (!result.ok) {
|
if (!result.ok) {
|
||||||
throw new Error("Error while fetching xml templates");
|
throw new OwlError("Error while fetching xml templates");
|
||||||
}
|
}
|
||||||
return await result.text();
|
return await result.text();
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,171 @@
|
|||||||
|
import { OwlError } from "./error_handling";
|
||||||
|
import { toRaw } from "./reactivity";
|
||||||
|
|
||||||
|
type BaseType =
|
||||||
|
| typeof String
|
||||||
|
| typeof Boolean
|
||||||
|
| typeof Number
|
||||||
|
| typeof Date
|
||||||
|
| typeof Object
|
||||||
|
| typeof Array
|
||||||
|
| true
|
||||||
|
| "*";
|
||||||
|
|
||||||
|
interface TypeInfo {
|
||||||
|
type?: TypeDescription;
|
||||||
|
optional?: boolean;
|
||||||
|
validate?: Function;
|
||||||
|
shape?: Schema;
|
||||||
|
element?: TypeDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
type ValueType = { value: any };
|
||||||
|
|
||||||
|
type TypeDescription = BaseType | TypeInfo | ValueType | TypeDescription[];
|
||||||
|
type SimplifiedSchema = string[];
|
||||||
|
type NormalizedSchema = { [key: string]: TypeDescription };
|
||||||
|
export type Schema = SimplifiedSchema | NormalizedSchema;
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// helpers
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
const isUnionType = (t: TypeDescription): t is TypeDescription[] => Array.isArray(t);
|
||||||
|
const isBaseType = (t: TypeDescription): t is BaseType => typeof t !== "object";
|
||||||
|
const isValueType = (t: TypeDescription): t is ValueType =>
|
||||||
|
typeof t === "object" && t && "value" in t;
|
||||||
|
|
||||||
|
export function isOptional(t: TypeDescription): Boolean {
|
||||||
|
return typeof t === "object" && "optional" in t ? t.optional || false : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function describeType(type: BaseType): string {
|
||||||
|
return type === "*" || type === true ? "value" : type.name.toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
function describe(info: TypeDescription): string {
|
||||||
|
if (isBaseType(info)) {
|
||||||
|
return describeType(info);
|
||||||
|
} else if (isUnionType(info)) {
|
||||||
|
return info.map(describe).join(" or ");
|
||||||
|
} else if (isValueType(info)) {
|
||||||
|
return String(info.value);
|
||||||
|
}
|
||||||
|
if ("element" in info) {
|
||||||
|
return `list of ${describe({ type: info.element, optional: false })}s`;
|
||||||
|
}
|
||||||
|
if ("shape" in (info as TypeInfo)) {
|
||||||
|
return `object`;
|
||||||
|
}
|
||||||
|
return describe(info.type || "*");
|
||||||
|
}
|
||||||
|
|
||||||
|
function toSchema(spec: SimplifiedSchema): NormalizedSchema {
|
||||||
|
return Object.fromEntries(
|
||||||
|
spec.map((e) =>
|
||||||
|
e.endsWith("?") ? [e.slice(0, -1), { optional: true }] : [e, { type: "*", optional: false }]
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Main validate function
|
||||||
|
*/
|
||||||
|
export function validate(obj: { [key: string]: any }, spec: Schema) {
|
||||||
|
let errors = validateSchema(obj, spec);
|
||||||
|
if (errors.length) {
|
||||||
|
throw new OwlError("Invalid object: " + errors.join(", "));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper validate function, to get the list of errors. useful if one want to
|
||||||
|
* manipulate the errors without parsing an error object
|
||||||
|
*/
|
||||||
|
export function validateSchema(obj: { [key: string]: any }, schema: Schema): string[] {
|
||||||
|
if (Array.isArray(schema)) {
|
||||||
|
schema = toSchema(schema);
|
||||||
|
}
|
||||||
|
obj = toRaw(obj);
|
||||||
|
let errors = [];
|
||||||
|
// check if each value in obj has correct shape
|
||||||
|
for (let key in obj) {
|
||||||
|
if (key in schema) {
|
||||||
|
let result = validateType(key, obj[key], schema[key]);
|
||||||
|
if (result) {
|
||||||
|
errors.push(result);
|
||||||
|
}
|
||||||
|
} else if (!("*" in schema)) {
|
||||||
|
errors.push(`unknown key '${key}'`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// check that all specified keys are defined in obj
|
||||||
|
for (let key in schema) {
|
||||||
|
const spec = schema[key];
|
||||||
|
if (key !== "*" && !isOptional(spec) && !(key in obj)) {
|
||||||
|
const isObj = typeof spec === "object" && !Array.isArray(spec);
|
||||||
|
const isAny = spec === "*" || (isObj && "type" in spec ? spec.type === "*" : isObj);
|
||||||
|
let detail = isAny ? "" : ` (should be a ${describe(spec)})`;
|
||||||
|
errors.push(`'${key}' is missing${detail}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
function validateBaseType(key: string, value: any, type: BaseType): string | null {
|
||||||
|
if (typeof type === "function") {
|
||||||
|
if (typeof value === "object") {
|
||||||
|
if (!(value instanceof type)) {
|
||||||
|
return `'${key}' is not a ${describeType(type)}`;
|
||||||
|
}
|
||||||
|
} else if (typeof value !== type.name.toLowerCase()) {
|
||||||
|
return `'${key}' is not a ${describeType(type)}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function validateArrayType(key: string, value: any, descr: TypeDescription): string | null {
|
||||||
|
if (!Array.isArray(value)) {
|
||||||
|
return `'${key}' is not a list of ${describe(descr)}s`;
|
||||||
|
}
|
||||||
|
for (let i = 0; i < value.length; i++) {
|
||||||
|
const error = validateType(`${key}[${i}]`, value[i], descr);
|
||||||
|
if (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function validateType(key: string, value: any, descr: TypeDescription): string | null {
|
||||||
|
if (value === undefined) {
|
||||||
|
return isOptional(descr) ? null : `'${key}' is undefined (should be a ${describe(descr)})`;
|
||||||
|
} else if (isBaseType(descr)) {
|
||||||
|
return validateBaseType(key, value, descr);
|
||||||
|
} else if (isValueType(descr)) {
|
||||||
|
return value === descr.value ? null : `'${key}' is not equal to '${descr.value}'`;
|
||||||
|
} else if (isUnionType(descr)) {
|
||||||
|
let validDescr = descr.find((p) => !validateType(key, value, p));
|
||||||
|
return validDescr ? null : `'${key}' is not a ${describe(descr)}`;
|
||||||
|
}
|
||||||
|
let result: string | null = null;
|
||||||
|
if ("element" in descr) {
|
||||||
|
result = validateArrayType(key, value, descr.element!);
|
||||||
|
} else if ("shape" in descr && !result) {
|
||||||
|
if (typeof value !== "object" || Array.isArray(value)) {
|
||||||
|
result = `'${key}' is not an object`;
|
||||||
|
} else {
|
||||||
|
const errors = validateSchema(value, descr.shape!);
|
||||||
|
if (errors.length) {
|
||||||
|
result = `'${key}' has not the correct shape (${errors.join(", ")})`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ("type" in descr && !result) {
|
||||||
|
result = validateType(key, value, descr.type!);
|
||||||
|
}
|
||||||
|
if ("validate" in descr && !result) {
|
||||||
|
result = !descr.validate!(value) ? `'${key}' is not valid` : null;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
@@ -47,16 +47,17 @@ exports[`Reactivity: useState concurrent renderings 3`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`Reactivity: useState destroyed component before being mounted is inactive 1`] = `
|
exports[`Reactivity: useState destroyed component before being mounted is inactive 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
const comp1 = app.createComponent(\`Child\`, true, false, false, true);
|
||||||
|
|
||||||
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 = \\"\\") {
|
||||||
let b2;
|
let b2;
|
||||||
if (ctx['state'].flag) {
|
if (ctx['state'].flag) {
|
||||||
b2 = component(\`Child\`, {}, key + \`__1\`, node, ctx);
|
b2 = comp1({}, key + \`__1\`, node, this, null);
|
||||||
}
|
}
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
}
|
}
|
||||||
@@ -64,9 +65,9 @@ exports[`Reactivity: useState destroyed component before being mounted is inacti
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`Reactivity: useState destroyed component before being mounted is inactive 2`] = `
|
exports[`Reactivity: useState destroyed component before being mounted is inactive 2`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
||||||
|
|
||||||
@@ -78,16 +79,17 @@ exports[`Reactivity: useState destroyed component before being mounted is inacti
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`Reactivity: useState destroyed component is inactive 1`] = `
|
exports[`Reactivity: useState destroyed component is inactive 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
const comp1 = app.createComponent(\`Child\`, true, false, false, true);
|
||||||
|
|
||||||
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 = \\"\\") {
|
||||||
let b2;
|
let b2;
|
||||||
if (ctx['state'].flag) {
|
if (ctx['state'].flag) {
|
||||||
b2 = component(\`Child\`, {}, key + \`__1\`, node, ctx);
|
b2 = comp1({}, key + \`__1\`, node, this, null);
|
||||||
}
|
}
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
}
|
}
|
||||||
@@ -95,9 +97,9 @@ exports[`Reactivity: useState destroyed component is inactive 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`Reactivity: useState destroyed component is inactive 2`] = `
|
exports[`Reactivity: useState destroyed component is inactive 2`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
||||||
|
|
||||||
@@ -109,9 +111,9 @@ exports[`Reactivity: useState destroyed component is inactive 2`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`Reactivity: useState one components can subscribe twice to same context 1`] = `
|
exports[`Reactivity: useState one components can subscribe twice to same context 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/><block-text-1/></div>\`);
|
let block1 = createBlock(\`<div><block-text-0/><block-text-1/></div>\`);
|
||||||
|
|
||||||
@@ -124,14 +126,15 @@ exports[`Reactivity: useState one components can subscribe twice to same context
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`Reactivity: useState parent and children subscribed to same context 1`] = `
|
exports[`Reactivity: useState parent and children subscribed to same context 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
const comp1 = app.createComponent(\`Child\`, true, false, false, true);
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><block-text-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/><block-text-0/></div>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let b2 = component(\`Child\`, {}, key + \`__1\`, node, ctx);
|
const b2 = comp1({}, key + \`__1\`, node, this, null);
|
||||||
let txt1 = ctx['contextObj'].b;
|
let txt1 = ctx['contextObj'].b;
|
||||||
return block1([txt1], [b2]);
|
return block1([txt1], [b2]);
|
||||||
}
|
}
|
||||||
@@ -139,9 +142,9 @@ exports[`Reactivity: useState parent and children subscribed to same context 1`]
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`Reactivity: useState parent and children subscribed to same context 2`] = `
|
exports[`Reactivity: useState parent and children subscribed to same context 2`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
||||||
|
|
||||||
@@ -216,24 +219,26 @@ exports[`Reactivity: useState several nodes on different level use same context
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`Reactivity: useState two components are updated in parallel 1`] = `
|
exports[`Reactivity: useState two components are updated in parallel 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
const comp1 = app.createComponent(\`Child\`, true, false, false, true);
|
||||||
|
const comp2 = app.createComponent(\`Child\`, true, false, false, true);
|
||||||
|
|
||||||
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);
|
const b2 = comp1({}, key + \`__1\`, node, this, null);
|
||||||
let b3 = component(\`Child\`, {}, key + \`__2\`, node, ctx);
|
const b3 = comp2({}, key + \`__2\`, node, this, null);
|
||||||
return block1([], [b2, b3]);
|
return block1([], [b2, b3]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`Reactivity: useState two components are updated in parallel 2`] = `
|
exports[`Reactivity: useState two components are updated in parallel 2`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
||||||
|
|
||||||
@@ -245,24 +250,26 @@ exports[`Reactivity: useState two components are updated in parallel 2`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`Reactivity: useState two components can subscribe to same context 1`] = `
|
exports[`Reactivity: useState two components can subscribe to same context 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
const comp1 = app.createComponent(\`Child\`, true, false, false, true);
|
||||||
|
const comp2 = app.createComponent(\`Child\`, true, false, false, true);
|
||||||
|
|
||||||
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);
|
const b2 = comp1({}, key + \`__1\`, node, this, null);
|
||||||
let b3 = component(\`Child\`, {}, key + \`__2\`, node, ctx);
|
const b3 = comp2({}, key + \`__2\`, node, this, null);
|
||||||
return block1([], [b2, b3]);
|
return block1([], [b2, b3]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`Reactivity: useState two components can subscribe to same context 2`] = `
|
exports[`Reactivity: useState two components can subscribe to same context 2`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
||||||
|
|
||||||
@@ -274,24 +281,26 @@ exports[`Reactivity: useState two components can subscribe to same context 2`] =
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`Reactivity: useState two independent components on different levels are updated in parallel 1`] = `
|
exports[`Reactivity: useState two independent components on different levels are updated in parallel 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
const comp1 = app.createComponent(\`Child\`, true, false, false, true);
|
||||||
|
const comp2 = app.createComponent(\`Parent\`, true, false, false, true);
|
||||||
|
|
||||||
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);
|
const b2 = comp1({}, key + \`__1\`, node, this, null);
|
||||||
let b3 = component(\`Parent\`, {}, key + \`__2\`, node, ctx);
|
const b3 = comp2({}, key + \`__2\`, node, this, null);
|
||||||
return block1([], [b2, b3]);
|
return block1([], [b2, b3]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`Reactivity: useState two independent components on different levels are updated in parallel 2`] = `
|
exports[`Reactivity: useState two independent components on different levels are updated in parallel 2`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
||||||
|
|
||||||
@@ -303,23 +312,24 @@ exports[`Reactivity: useState two independent components on different levels are
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`Reactivity: useState two independent components on different levels are updated in parallel 3`] = `
|
exports[`Reactivity: useState two independent components on different levels are updated in parallel 3`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
const comp1 = app.createComponent(\`Child\`, true, false, false, true);
|
||||||
|
|
||||||
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 = \\"\\") {
|
||||||
let b2 = component(\`Child\`, {}, key + \`__1\`, node, ctx);
|
const b2 = comp1({}, key + \`__1\`, node, this, null);
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`Reactivity: useState useContext=useState hook is reactive, for one component 1`] = `
|
exports[`Reactivity: useState useContext=useState hook is reactive, for one component 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
||||||
|
|
||||||
@@ -331,23 +341,24 @@ exports[`Reactivity: useState useContext=useState hook is reactive, for one comp
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`Reactivity: useState useless atoms should be deleted 1`] = `
|
exports[`Reactivity: useState useless atoms should be deleted 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { prepareList, withKey } = helpers;
|
let { prepareList, withKey } = helpers;
|
||||||
|
const comp1 = app.createComponent(\`Quantity\`, true, false, false, false);
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/> Total: <block-text-0/> Count: <block-text-1/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/> Total: <block-text-0/> Count: <block-text-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(Object.keys(ctx['state']));
|
const [k_block2, v_block2, l_block2, c_block2] = prepareList(Object.keys(ctx['state']));;
|
||||||
for (let i1 = 0; i1 < l_block2; i1++) {
|
for (let i1 = 0; i1 < l_block2; i1++) {
|
||||||
ctx[\`id\`] = v_block2[i1];
|
ctx[\`id\`] = v_block2[i1];
|
||||||
let key1 = ctx['id'];
|
const key1 = ctx['id'];
|
||||||
c_block2[i1] = withKey(component(\`Quantity\`, {id: ctx['id']}, key + \`__1__\${key1}\`, node, ctx), key1);
|
c_block2[i1] = withKey(comp1({id: ctx['id']}, key + \`__1__\${key1}\`, node, this, null), key1);
|
||||||
}
|
}
|
||||||
ctx = ctx.__proto__;
|
ctx = ctx.__proto__;
|
||||||
let b2 = list(c_block2);
|
const b2 = list(c_block2);
|
||||||
let txt1 = ctx['total'];
|
let txt1 = ctx['total'];
|
||||||
let txt2 = Object.keys(ctx['state']).length;
|
let txt2 = Object.keys(ctx['state']).length;
|
||||||
return block1([txt1, txt2], [b2]);
|
return block1([txt1, txt2], [b2]);
|
||||||
@@ -356,9 +367,9 @@ exports[`Reactivity: useState useless atoms should be deleted 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`Reactivity: useState useless atoms should be deleted 2`] = `
|
exports[`Reactivity: useState useless atoms should be deleted 2`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
||||||
|
|
||||||
@@ -370,9 +381,9 @@ exports[`Reactivity: useState useless atoms should be deleted 2`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`Reactivity: useState very simple use, with initial value 1`] = `
|
exports[`Reactivity: useState very simple use, with initial value 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`app App supports env with getters/setters 1`] = `
|
exports[`app App supports env with getters/setters 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/> <block-text-1/></div>\`);
|
let block1 = createBlock(\`<div><block-text-0/> <block-text-1/></div>\`);
|
||||||
|
|
||||||
@@ -16,9 +16,9 @@ exports[`app App supports env with getters/setters 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`app can configure an app with props 1`] = `
|
exports[`app can configure an app with props 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
||||||
|
|
||||||
@@ -29,10 +29,23 @@ exports[`app can configure an app with props 1`] = `
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`app destroy remove the widget from the DOM 1`] = `
|
exports[`app can mount app in an iframe 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div class=\\"my-div\\"/>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
return block1();
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`app destroy remove the widget from the DOM 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div/>\`);
|
let block1 = createBlock(\`<div/>\`);
|
||||||
|
|
||||||
@@ -41,3 +54,17 @@ exports[`app destroy remove the widget from the DOM 1`] = `
|
|||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`app warnIfNoStaticProps works as expected 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
let txt1 = ctx['message'];
|
||||||
|
return block1([txt1]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|||||||
+37
-2
@@ -1,5 +1,5 @@
|
|||||||
import { App, Component, xml } from "../../src";
|
import { App, Component, mount, xml } from "../../src";
|
||||||
import { status } from "../../src/component/status";
|
import { status } from "../../src/runtime/status";
|
||||||
import { makeTestFixture, snapshotEverything, nextTick, elem } from "../helpers";
|
import { makeTestFixture, snapshotEverything, nextTick, elem } from "../helpers";
|
||||||
|
|
||||||
let fixture: HTMLElement;
|
let fixture: HTMLElement;
|
||||||
@@ -59,4 +59,39 @@ describe("app", () => {
|
|||||||
await app.mount(fixture);
|
await app.mount(fixture);
|
||||||
expect(fixture.innerHTML).toBe("<div>333</div>");
|
expect(fixture.innerHTML).toBe("<div>333</div>");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("warnIfNoStaticProps works as expected", async () => {
|
||||||
|
let originalconsoleWarn = console.warn;
|
||||||
|
let mockConsoleWarn = jest.fn(() => {});
|
||||||
|
console.warn = mockConsoleWarn;
|
||||||
|
|
||||||
|
class Root extends Component {
|
||||||
|
static template = xml`<div t-esc="message"/>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
await mount(Root, fixture, { dev: true, props: { messge: "hey" }, warnIfNoStaticProps: true });
|
||||||
|
|
||||||
|
console.warn = originalconsoleWarn;
|
||||||
|
expect(mockConsoleWarn).toBeCalledWith(
|
||||||
|
"Component 'Root' does not have a static props description"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("can mount app in an iframe", async () => {
|
||||||
|
class SomeComponent extends Component {
|
||||||
|
static template = xml`<div class="my-div"/>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const iframe = document.createElement("iframe");
|
||||||
|
fixture.appendChild(iframe);
|
||||||
|
const app = new App(SomeComponent);
|
||||||
|
const iframeDoc = iframe.contentDocument!;
|
||||||
|
const comp = await app.mount(iframeDoc.body);
|
||||||
|
const div = iframeDoc.querySelector(".my-div");
|
||||||
|
expect(div).not.toBe(null);
|
||||||
|
expect(iframeDoc.contains(div)).toBe(true);
|
||||||
|
app.destroy();
|
||||||
|
expect(iframeDoc.contains(div)).toBe(false);
|
||||||
|
expect(status(comp)).toBe("destroyed");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { createBlock, mount, patch, remove, text } from "../../src/blockdom";
|
import { createBlock, mount, patch, remove, text } from "../../src/runtime/blockdom";
|
||||||
import { makeTestFixture } from "./helpers";
|
import { makeTestFixture } from "./helpers";
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { mount, patch, createBlock } from "../../src/blockdom";
|
import { mount, patch, createBlock } from "../../src/runtime/blockdom";
|
||||||
import { makeTestFixture } from "./helpers";
|
import { makeTestFixture } from "./helpers";
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
@@ -169,6 +169,27 @@ describe("properties", () => {
|
|||||||
expect(input.value).toBe("potato");
|
expect(input.value).toBe("potato");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("input with value attribute, and falsy value given", () => {
|
||||||
|
const block = createBlock(`<input block-attribute-0="value"/>`);
|
||||||
|
|
||||||
|
const tree = block([undefined]);
|
||||||
|
mount(tree, fixture);
|
||||||
|
const input = fixture.querySelector("input")!;
|
||||||
|
expect(input.value).toBe("");
|
||||||
|
|
||||||
|
patch(tree, block([null]));
|
||||||
|
expect(input.value).toBe("");
|
||||||
|
|
||||||
|
patch(tree, block([0]));
|
||||||
|
expect(input.value).toBe("0");
|
||||||
|
|
||||||
|
patch(tree, block([""]));
|
||||||
|
expect(input.value).toBe("");
|
||||||
|
|
||||||
|
patch(tree, block([false]));
|
||||||
|
expect(input.value).toBe("");
|
||||||
|
});
|
||||||
|
|
||||||
test("input type=checkbox with checked attribute", () => {
|
test("input type=checkbox with checked attribute", () => {
|
||||||
// render input with initial value
|
// render input with initial value
|
||||||
const block = createBlock(`<input type="checkbox" block-attribute-0="checked"/>`);
|
const block = createBlock(`<input type="checkbox" block-attribute-0="checked"/>`);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { mount, createBlock, multi, config, patch } from "../../src/blockdom";
|
import { mount, createBlock, multi, config, patch } from "../../src/runtime/blockdom";
|
||||||
// import { defaultHandler, setupMainHandler } from "../../src/bdom/block";
|
// import { defaultHandler, setupMainHandler } from "../../src/bdom/block";
|
||||||
import { makeTestFixture } from "./helpers";
|
import { makeTestFixture } from "./helpers";
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { createBlock, mount, patch, remove } from "../../src/blockdom";
|
import { createBlock, mount, patch, remove } from "../../src/runtime/blockdom";
|
||||||
|
import { logStep } from "../helpers";
|
||||||
import { makeTestFixture } from "./helpers";
|
import { makeTestFixture } from "./helpers";
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
@@ -55,3 +56,15 @@ test("is in dom when callback is called", async () => {
|
|||||||
|
|
||||||
mount(tree, fixture);
|
mount(tree, fixture);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("callback ref in callback ref with same block", async () => {
|
||||||
|
const block = createBlock('<p block-ref="0"><block-text-1/><block-child-0/></p>');
|
||||||
|
let refFn = (el: HTMLParagraphElement) => logStep(el.outerHTML);
|
||||||
|
|
||||||
|
const child = block([refFn, "child"], []);
|
||||||
|
const parent = block([refFn, "parent"], [child]);
|
||||||
|
mount(parent, fixture);
|
||||||
|
|
||||||
|
expect(fixture.innerHTML).toBe("<p>parent<p>child</p></p>");
|
||||||
|
expect(["<p>child</p>", "<p>parent<p>child</p></p>"]).toBeLogged();
|
||||||
|
});
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { comment, mount } from "../../src/blockdom";
|
import { comment, mount } from "../../src/runtime/blockdom";
|
||||||
import { makeTestFixture } from "./helpers";
|
import { makeTestFixture } from "./helpers";
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
import { config, createBlock, createCatcher, mount } from "../../src/runtime/blockdom";
|
||||||
|
import { makeTestFixture } from "./helpers";
|
||||||
|
import { mainEventHandler } from "../../src/runtime/event_handling";
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// Setup and helpers
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
let fixture: HTMLElement;
|
||||||
|
config.mainEventHandler = mainEventHandler;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = makeTestFixture();
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
fixture.remove();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("simple event catcher", async () => {
|
||||||
|
const catcher = createCatcher({ click: 0 });
|
||||||
|
const block = createBlock("<div></div>");
|
||||||
|
let n = 0;
|
||||||
|
let ctx = {};
|
||||||
|
let handler = [() => n++, ctx];
|
||||||
|
const tree = catcher(block(), [handler]);
|
||||||
|
|
||||||
|
mount(tree, fixture);
|
||||||
|
expect(fixture.innerHTML).toBe("<div></div>");
|
||||||
|
|
||||||
|
expect(fixture.firstChild).toBeInstanceOf(HTMLDivElement);
|
||||||
|
expect(n).toBe(0);
|
||||||
|
(fixture.firstChild as HTMLDivElement).click();
|
||||||
|
expect(n).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("do not catch events outside of itself", async () => {
|
||||||
|
const catcher = createCatcher({ click: 0 });
|
||||||
|
const childBlock = createBlock("<div></div>");
|
||||||
|
const parentBlock = createBlock("<button><block-child-0/></button>");
|
||||||
|
let n = 0;
|
||||||
|
let ctx = {};
|
||||||
|
let handler = [() => n++, ctx];
|
||||||
|
const tree = parentBlock([], [catcher(childBlock(), [handler])]);
|
||||||
|
|
||||||
|
mount(tree, fixture);
|
||||||
|
expect(fixture.innerHTML).toBe("<button><div></div></button>");
|
||||||
|
|
||||||
|
expect(n).toBe(0);
|
||||||
|
fixture.querySelector("div")!.click();
|
||||||
|
expect(n).toBe(1);
|
||||||
|
fixture.querySelector("button")!.click();
|
||||||
|
expect(n).toBe(1);
|
||||||
|
});
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { html, mount, patch, text } from "../../src/blockdom";
|
import { html, mount, patch, text } from "../../src/runtime/blockdom";
|
||||||
import { makeTestFixture } from "./helpers";
|
import { makeTestFixture } from "./helpers";
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -1,4 +1,13 @@
|
|||||||
import { list, mount, multi, patch, text, createBlock, VNode, withKey } from "../../src/blockdom";
|
import {
|
||||||
|
list,
|
||||||
|
mount,
|
||||||
|
multi,
|
||||||
|
patch,
|
||||||
|
text,
|
||||||
|
createBlock,
|
||||||
|
VNode,
|
||||||
|
withKey,
|
||||||
|
} from "../../src/runtime/blockdom";
|
||||||
import { makeTestFixture } from "./helpers";
|
import { makeTestFixture } from "./helpers";
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { mount, multi, patch, text, createBlock } from "../../src/blockdom";
|
import { mount, multi, patch, text, createBlock } from "../../src/runtime/blockdom";
|
||||||
import { makeTestFixture } from "./helpers";
|
import { makeTestFixture } from "./helpers";
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { createBlock, mount } from "../../src/blockdom";
|
import { createBlock, mount } from "../../src/runtime/blockdom";
|
||||||
import { makeTestFixture } from "./helpers";
|
import { makeTestFixture } from "./helpers";
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { createBlock, mount, multi, patch } from "../../src/blockdom";
|
import { createBlock, mount, multi, patch } from "../../src/runtime/blockdom";
|
||||||
import { makeTestFixture } from "./helpers";
|
import { makeTestFixture } from "./helpers";
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { mount, patch, remove, text } from "../../src/blockdom";
|
import { mount, patch, remove, text } from "../../src/runtime/blockdom";
|
||||||
import { makeTestFixture } from "./helpers";
|
import { makeTestFixture } from "./helpers";
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { createBlock, mount, patch, text, toggler } from "../../src/blockdom";
|
import { createBlock, mount, patch, text, toggler } from "../../src/runtime/blockdom";
|
||||||
import { makeTestFixture } from "./helpers";
|
import { makeTestFixture } from "./helpers";
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`attributes changing a class with t-att-class (preexisting class 1`] = `
|
exports[`attributes changing a class with t-att-class (preexisting class 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div class=\\"hoy\\" block-attribute-0=\\"class\\"/>\`);
|
let block1 = createBlock(\`<div class=\\"hoy\\" block-attribute-0=\\"class\\"/>\`);
|
||||||
|
|
||||||
@@ -15,9 +15,9 @@ exports[`attributes changing a class with t-att-class (preexisting class 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`attributes changing a class with t-att-class 1`] = `
|
exports[`attributes changing a class with t-att-class 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div block-attribute-0=\\"class\\"/>\`);
|
let block1 = createBlock(\`<div block-attribute-0=\\"class\\"/>\`);
|
||||||
|
|
||||||
@@ -29,9 +29,9 @@ exports[`attributes changing a class with t-att-class 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`attributes changing an attribute with t-att- 1`] = `
|
exports[`attributes changing an attribute with t-att- 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div block-attribute-0=\\"value\\"/>\`);
|
let block1 = createBlock(\`<div block-attribute-0=\\"value\\"/>\`);
|
||||||
|
|
||||||
@@ -43,9 +43,9 @@ exports[`attributes changing an attribute with t-att- 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`attributes class and t-att-class should combine together 1`] = `
|
exports[`attributes class and t-att-class should combine together 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div block-attribute-0=\\"class\\" class=\\"hello\\"/>\`);
|
let block1 = createBlock(\`<div block-attribute-0=\\"class\\" class=\\"hello\\"/>\`);
|
||||||
|
|
||||||
@@ -57,9 +57,9 @@ exports[`attributes class and t-att-class should combine together 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`attributes class and t-attf-class with ternary operation 1`] = `
|
exports[`attributes class and t-attf-class with ternary operation 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div class=\\"hello\\" block-attribute-0=\\"class\\"/>\`);
|
let block1 = createBlock(\`<div class=\\"hello\\" block-attribute-0=\\"class\\"/>\`);
|
||||||
|
|
||||||
@@ -71,9 +71,9 @@ exports[`attributes class and t-attf-class with ternary operation 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`attributes dynamic attribute evaluating to 0 1`] = `
|
exports[`attributes dynamic attribute evaluating to 0 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div block-attribute-0=\\"foo\\"/>\`);
|
let block1 = createBlock(\`<div block-attribute-0=\\"foo\\"/>\`);
|
||||||
|
|
||||||
@@ -85,9 +85,9 @@ exports[`attributes dynamic attribute evaluating to 0 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`attributes dynamic attribute falsy variable 1`] = `
|
exports[`attributes dynamic attribute falsy variable 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div block-attribute-0=\\"foo\\"/>\`);
|
let block1 = createBlock(\`<div block-attribute-0=\\"foo\\"/>\`);
|
||||||
|
|
||||||
@@ -99,9 +99,9 @@ exports[`attributes dynamic attribute falsy variable 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`attributes dynamic attribute with a dash 1`] = `
|
exports[`attributes dynamic attribute with a dash 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div block-attribute-0=\\"data-action-id\\"/>\`);
|
let block1 = createBlock(\`<div block-attribute-0=\\"data-action-id\\"/>\`);
|
||||||
|
|
||||||
@@ -113,9 +113,9 @@ exports[`attributes dynamic attribute with a dash 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`attributes dynamic attributes 1`] = `
|
exports[`attributes dynamic attributes 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div block-attribute-0=\\"foo\\"/>\`);
|
let block1 = createBlock(\`<div block-attribute-0=\\"foo\\"/>\`);
|
||||||
|
|
||||||
@@ -126,10 +126,24 @@ exports[`attributes dynamic attributes 1`] = `
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`attributes dynamic class attribute 1`] = `
|
exports[`attributes dynamic attributes with backticks 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div block-attribute-0=\\"foo\\"/>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
let attr1 = \`bar\`;
|
||||||
|
return block1([attr1]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`attributes dynamic class attribute 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div block-attribute-0=\\"class\\"/>\`);
|
let block1 = createBlock(\`<div block-attribute-0=\\"class\\"/>\`);
|
||||||
|
|
||||||
@@ -141,9 +155,9 @@ exports[`attributes dynamic class attribute 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`attributes dynamic class attribute evaluating to 0 1`] = `
|
exports[`attributes dynamic class attribute evaluating to 0 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div block-attribute-0=\\"class\\"/>\`);
|
let block1 = createBlock(\`<div block-attribute-0=\\"class\\"/>\`);
|
||||||
|
|
||||||
@@ -154,10 +168,52 @@ exports[`attributes dynamic class attribute evaluating to 0 1`] = `
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`attributes dynamic empty class attribute 1`] = `
|
exports[`attributes dynamic class attribute that starts and ends with a space 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div block-attribute-0=\\"class\\"/>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
let attr1 = ctx['c'];
|
||||||
|
return block1([attr1]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`attributes dynamic class attribute which is only a space 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div block-attribute-0=\\"class\\"/>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
let attr1 = ctx['c'];
|
||||||
|
return block1([attr1]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`attributes dynamic class attribute with multiple consecutive spaces 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div block-attribute-0=\\"class\\"/>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
let attr1 = ctx['c'];
|
||||||
|
return block1([attr1]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`attributes dynamic empty class attribute 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div block-attribute-0=\\"class\\"/>\`);
|
let block1 = createBlock(\`<div block-attribute-0=\\"class\\"/>\`);
|
||||||
|
|
||||||
@@ -169,9 +225,9 @@ exports[`attributes dynamic empty class attribute 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`attributes dynamic formatted attributes with a dash 1`] = `
|
exports[`attributes dynamic formatted attributes with a dash 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div block-attribute-0=\\"aria-label\\"/>\`);
|
let block1 = createBlock(\`<div block-attribute-0=\\"aria-label\\"/>\`);
|
||||||
|
|
||||||
@@ -183,9 +239,9 @@ exports[`attributes dynamic formatted attributes with a dash 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`attributes dynamic undefined class attribute 1`] = `
|
exports[`attributes dynamic undefined class attribute 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div block-attribute-0=\\"class\\"/>\`);
|
let block1 = createBlock(\`<div block-attribute-0=\\"class\\"/>\`);
|
||||||
|
|
||||||
@@ -197,9 +253,9 @@ exports[`attributes dynamic undefined class attribute 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`attributes dynamic undefined generic attribute 1`] = `
|
exports[`attributes dynamic undefined generic attribute 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div block-attribute-0=\\"thing\\"/>\`);
|
let block1 = createBlock(\`<div block-attribute-0=\\"thing\\"/>\`);
|
||||||
|
|
||||||
@@ -211,9 +267,9 @@ exports[`attributes dynamic undefined generic attribute 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`attributes fixed variable 1`] = `
|
exports[`attributes fixed variable 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div block-attribute-0=\\"foo\\"/>\`);
|
let block1 = createBlock(\`<div block-attribute-0=\\"foo\\"/>\`);
|
||||||
|
|
||||||
@@ -225,9 +281,9 @@ exports[`attributes fixed variable 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`attributes format expression 1`] = `
|
exports[`attributes format expression 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div block-attribute-0=\\"foo\\"/>\`);
|
let block1 = createBlock(\`<div block-attribute-0=\\"foo\\"/>\`);
|
||||||
|
|
||||||
@@ -239,9 +295,9 @@ exports[`attributes format expression 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`attributes format literal 1`] = `
|
exports[`attributes format literal 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div block-attribute-0=\\"foo\\"/>\`);
|
let block1 = createBlock(\`<div block-attribute-0=\\"foo\\"/>\`);
|
||||||
|
|
||||||
@@ -253,9 +309,9 @@ exports[`attributes format literal 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`attributes format multiple 1`] = `
|
exports[`attributes format multiple 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div block-attribute-0=\\"foo\\"/>\`);
|
let block1 = createBlock(\`<div block-attribute-0=\\"foo\\"/>\`);
|
||||||
|
|
||||||
@@ -267,9 +323,9 @@ exports[`attributes format multiple 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`attributes format value 1`] = `
|
exports[`attributes format value 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div block-attribute-0=\\"foo\\"/>\`);
|
let block1 = createBlock(\`<div block-attribute-0=\\"foo\\"/>\`);
|
||||||
|
|
||||||
@@ -281,9 +337,9 @@ exports[`attributes format value 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`attributes from object variables set previously 1`] = `
|
exports[`attributes from object variables set previously 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { isBoundary, withDefault, setContextValue } = helpers;
|
let { isBoundary, withDefault, setContextValue } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><span block-attribute-0=\\"class\\"/></div>\`);
|
let block1 = createBlock(\`<div><span block-attribute-0=\\"class\\"/></div>\`);
|
||||||
@@ -299,9 +355,9 @@ exports[`attributes from object variables set previously 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`attributes from variables set previously (no external node) 1`] = `
|
exports[`attributes from variables set previously (no external node) 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { isBoundary, withDefault, setContextValue } = helpers;
|
let { isBoundary, withDefault, setContextValue } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span block-attribute-0=\\"class\\"/>\`);
|
let block1 = createBlock(\`<span block-attribute-0=\\"class\\"/>\`);
|
||||||
@@ -317,9 +373,9 @@ exports[`attributes from variables set previously (no external node) 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`attributes from variables set previously 1`] = `
|
exports[`attributes from variables set previously 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { isBoundary, withDefault, setContextValue } = helpers;
|
let { isBoundary, withDefault, setContextValue } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><span block-attribute-0=\\"class\\"/></div>\`);
|
let block1 = createBlock(\`<div><span block-attribute-0=\\"class\\"/></div>\`);
|
||||||
@@ -335,9 +391,9 @@ exports[`attributes from variables set previously 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`attributes object 1`] = `
|
exports[`attributes object 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div block-attributes=\\"0\\"/>\`);
|
let block1 = createBlock(\`<div block-attributes=\\"0\\"/>\`);
|
||||||
|
|
||||||
@@ -349,9 +405,9 @@ exports[`attributes object 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`attributes static attributes 1`] = `
|
exports[`attributes static attributes 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div foo=\\"a\\" bar=\\"b\\" baz=\\"c\\"/>\`);
|
let block1 = createBlock(\`<div foo=\\"a\\" bar=\\"b\\" baz=\\"c\\"/>\`);
|
||||||
|
|
||||||
@@ -362,9 +418,9 @@ exports[`attributes static attributes 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`attributes static attributes on void elements 1`] = `
|
exports[`attributes static attributes on void elements 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<img src=\\"/test.skip.jpg\\" alt=\\"Test\\"/>\`);
|
let block1 = createBlock(\`<img src=\\"/test.skip.jpg\\" alt=\\"Test\\"/>\`);
|
||||||
|
|
||||||
@@ -374,10 +430,36 @@ exports[`attributes static attributes on void elements 1`] = `
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`attributes static attributes with dashes 1`] = `
|
exports[`attributes static attributes with backslash or backtick 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div foo=\\"\\\\\\\\a\\" bar=\\"\\\\\\\\n\\" baz=\\"\\\\\`\\"/>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
return block1();
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`attributes static attributes with backticks 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div foo=\\"\\\\\`bar\\\\\`\\"/>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
return block1();
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`attributes static attributes with dashes 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div aria-label=\\"Close\\"/>\`);
|
let block1 = createBlock(\`<div aria-label=\\"Close\\"/>\`);
|
||||||
|
|
||||||
@@ -387,10 +469,24 @@ exports[`attributes static attributes with dashes 1`] = `
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`attributes t-att-class and class should combine together 1`] = `
|
exports[`attributes string interpolation, alternate syntax 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div block-attribute-0=\\"foo\\"/>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
let attr1 = \`b\${ctx['value']}r\`;
|
||||||
|
return block1([attr1]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`attributes t-att-class and class should combine together 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div class=\\"hello\\" block-attribute-0=\\"class\\"/>\`);
|
let block1 = createBlock(\`<div class=\\"hello\\" block-attribute-0=\\"class\\"/>\`);
|
||||||
|
|
||||||
@@ -402,9 +498,9 @@ exports[`attributes t-att-class and class should combine together 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`attributes t-att-class with multiple classes 1`] = `
|
exports[`attributes t-att-class with multiple classes 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div block-attribute-0=\\"class\\"/>\`);
|
let block1 = createBlock(\`<div block-attribute-0=\\"class\\"/>\`);
|
||||||
|
|
||||||
@@ -416,9 +512,9 @@ exports[`attributes t-att-class with multiple classes 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`attributes t-att-class with multiple classes 2`] = `
|
exports[`attributes t-att-class with multiple classes 2`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div block-attribute-0=\\"class\\"/>\`);
|
let block1 = createBlock(\`<div block-attribute-0=\\"class\\"/>\`);
|
||||||
|
|
||||||
@@ -429,10 +525,24 @@ exports[`attributes t-att-class with multiple classes 2`] = `
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`attributes t-att-class with multiple classes, some of which are duplicate 1`] = `
|
exports[`attributes t-att-class with multiple classes 3`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div block-attribute-0=\\"class\\"/>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
let attr1 = {'a b c':ctx['value']};
|
||||||
|
return block1([attr1]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`attributes t-att-class with multiple classes, some of which are duplicate 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div block-attribute-0=\\"class\\"/>\`);
|
let block1 = createBlock(\`<div block-attribute-0=\\"class\\"/>\`);
|
||||||
|
|
||||||
@@ -444,9 +554,9 @@ exports[`attributes t-att-class with multiple classes, some of which are duplica
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`attributes t-att-class with object 1`] = `
|
exports[`attributes t-att-class with object 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div class=\\"static\\" block-attribute-0=\\"class\\"/>\`);
|
let block1 = createBlock(\`<div class=\\"static\\" block-attribute-0=\\"class\\"/>\`);
|
||||||
|
|
||||||
@@ -457,10 +567,38 @@ exports[`attributes t-att-class with object 1`] = `
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`attributes t-attf-class 1`] = `
|
exports[`attributes t-att-class with object 2`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div block-attribute-0=\\"class\\"/>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
let attr1 = {' a ':ctx['value']};
|
||||||
|
return block1([attr1]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`attributes t-att-class with object 3`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div block-attribute-0=\\"class\\"/>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
let attr1 = {' ':ctx['value']};
|
||||||
|
return block1([attr1]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`attributes t-attf-class 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div block-attribute-0=\\"class\\"/>\`);
|
let block1 = createBlock(\`<div block-attribute-0=\\"class\\"/>\`);
|
||||||
|
|
||||||
@@ -472,9 +610,9 @@ exports[`attributes t-attf-class 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`attributes t-attf-class should combine with class 1`] = `
|
exports[`attributes t-attf-class should combine with class 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div class=\\"hello\\" block-attribute-0=\\"class\\"/>\`);
|
let block1 = createBlock(\`<div class=\\"hello\\" block-attribute-0=\\"class\\"/>\`);
|
||||||
|
|
||||||
@@ -486,9 +624,9 @@ exports[`attributes t-attf-class should combine with class 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`attributes t-attf-class with multiple classes 1`] = `
|
exports[`attributes t-attf-class with multiple classes 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div block-attribute-0=\\"class\\"/>\`);
|
let block1 = createBlock(\`<div block-attribute-0=\\"class\\"/>\`);
|
||||||
|
|
||||||
@@ -500,9 +638,9 @@ exports[`attributes t-attf-class with multiple classes 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`attributes t-attf-class with multiple classes separated by multiple spaces 1`] = `
|
exports[`attributes t-attf-class with multiple classes separated by multiple spaces 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div block-attribute-0=\\"class\\"/>\`);
|
let block1 = createBlock(\`<div block-attribute-0=\\"class\\"/>\`);
|
||||||
|
|
||||||
@@ -514,9 +652,9 @@ exports[`attributes t-attf-class with multiple classes separated by multiple spa
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`attributes tuple literal 1`] = `
|
exports[`attributes tuple literal 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div block-attributes=\\"0\\"/>\`);
|
let block1 = createBlock(\`<div block-attributes=\\"0\\"/>\`);
|
||||||
|
|
||||||
@@ -528,9 +666,9 @@ exports[`attributes tuple literal 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`attributes tuple variable 1`] = `
|
exports[`attributes tuple variable 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div block-attributes=\\"0\\"/>\`);
|
let block1 = createBlock(\`<div block-attributes=\\"0\\"/>\`);
|
||||||
|
|
||||||
@@ -542,9 +680,9 @@ exports[`attributes tuple variable 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`attributes two classes 1`] = `
|
exports[`attributes two classes 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div class=\\"a b\\"/>\`);
|
let block1 = createBlock(\`<div class=\\"a b\\"/>\`);
|
||||||
|
|
||||||
@@ -555,9 +693,9 @@ exports[`attributes two classes 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`attributes two dynamic attributes 1`] = `
|
exports[`attributes two dynamic attributes 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div block-attribute-0=\\"foo\\" block-attribute-1=\\"bar\\"/>\`);
|
let block1 = createBlock(\`<div block-attribute-0=\\"foo\\" block-attribute-1=\\"bar\\"/>\`);
|
||||||
|
|
||||||
@@ -570,9 +708,9 @@ exports[`attributes two dynamic attributes 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`attributes updating classes (with obj notation) 1`] = `
|
exports[`attributes updating classes (with obj notation) 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div class=\\"hoy\\" block-attribute-0=\\"class\\"/>\`);
|
let block1 = createBlock(\`<div class=\\"hoy\\" block-attribute-0=\\"class\\"/>\`);
|
||||||
|
|
||||||
@@ -583,10 +721,24 @@ exports[`attributes updating classes (with obj notation) 1`] = `
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`attributes various escapes 1`] = `
|
exports[`attributes updating property with falsy value 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<input block-attribute-0=\\"value\\"/>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
let attr1 = new String((ctx['v']) || \\"\\");
|
||||||
|
return block1([attr1]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`attributes various escapes 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div foo=\\"<foo\\" block-attribute-0=\\"bar\\" block-attribute-1=\\"baz\\" block-attributes=\\"2\\"/>\`);
|
let block1 = createBlock(\`<div foo=\\"<foo\\" block-attribute-0=\\"bar\\" block-attribute-1=\\"baz\\" block-attributes=\\"2\\"/>\`);
|
||||||
|
|
||||||
@@ -600,9 +752,9 @@ exports[`attributes various escapes 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`attributes various escapes 2 1`] = `
|
exports[`attributes various escapes 2 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div> < </div>\`);
|
let block1 = createBlock(\`<div> < </div>\`);
|
||||||
|
|
||||||
@@ -613,79 +765,107 @@ exports[`attributes various escapes 2 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`special cases for some specific html attributes/properties input of type checkbox with t-att-indeterminate 1`] = `
|
exports[`special cases for some specific html attributes/properties input of type checkbox with t-att-indeterminate 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<input type=\\"checkbox\\" block-attribute-0=\\"indeterminate\\"/>\`);
|
let block1 = createBlock(\`<input type=\\"checkbox\\" block-attribute-0=\\"indeterminate\\"/>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let attr1 = ctx['v'];
|
let attr1 = new Boolean(ctx['v']);
|
||||||
return block1([attr1]);
|
return block1([attr1]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`special cases for some specific html attributes/properties input type= checkbox, with t-att-checked 1`] = `
|
exports[`special cases for some specific html attributes/properties input type= checkbox, with t-att-checked 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<input type=\\"checkbox\\" block-attribute-0=\\"checked\\"/>\`);
|
let block1 = createBlock(\`<input type=\\"checkbox\\" block-attribute-0=\\"checked\\"/>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let attr1 = ctx['flag'];
|
let attr1 = new Boolean(ctx['flag']);
|
||||||
|
return block1([attr1]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`special cases for some specific html attributes/properties input with t-att-value (patching with same value 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<input block-attribute-0=\\"value\\"/>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
let attr1 = new String((ctx['v']) || \\"\\");
|
||||||
return block1([attr1]);
|
return block1([attr1]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`special cases for some specific html attributes/properties input with t-att-value 1`] = `
|
exports[`special cases for some specific html attributes/properties input with t-att-value 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<input block-attribute-0=\\"value\\"/>\`);
|
let block1 = createBlock(\`<input block-attribute-0=\\"value\\"/>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let attr1 = ctx['v'];
|
let attr1 = new String((ctx['v']) || \\"\\");
|
||||||
|
return block1([attr1]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`special cases for some specific html attributes/properties input, type checkbox, with t-att-checked (patching with same value 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<input type=\\"checkbox\\" block-attribute-0=\\"checked\\"/>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
let attr1 = new Boolean(ctx['v']);
|
||||||
return block1([attr1]);
|
return block1([attr1]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`special cases for some specific html attributes/properties select with t-att-value 1`] = `
|
exports[`special cases for some specific html attributes/properties select with t-att-value 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<select block-attribute-0=\\"value\\"><option value=\\"potato\\">Potato</option><option value=\\"tomato\\">Tomato</option><option value=\\"onion\\">Onion</option></select>\`);
|
let block1 = createBlock(\`<select block-attribute-0=\\"value\\"><option value=\\"potato\\">Potato</option><option value=\\"tomato\\">Tomato</option><option value=\\"onion\\">Onion</option></select>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let attr1 = ctx['value'];
|
let attr1 = new String((ctx['value']) || \\"\\");
|
||||||
return block1([attr1]);
|
return block1([attr1]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`special cases for some specific html attributes/properties textarea with t-att-value 1`] = `
|
exports[`special cases for some specific html attributes/properties textarea with t-att-value 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<textarea block-attribute-0=\\"value\\"/>\`);
|
let block1 = createBlock(\`<textarea block-attribute-0=\\"value\\"/>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let attr1 = ctx['v'];
|
let attr1 = new String((ctx['v']) || \\"\\");
|
||||||
return block1([attr1]);
|
return block1([attr1]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`special cases for some specific html attributes/properties various boolean html attributes 1`] = `
|
exports[`special cases for some specific html attributes/properties various boolean html attributes 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><input type=\\"checkbox\\" checked=\\"checked\\"/><input checked=\\"checked\\"/><div checked=\\"checked\\"/><div selected=\\"selected\\"/><option selected=\\"selected\\" other=\\"1\\"/><input readonly=\\"readonly\\"/><button disabled=\\"disabled\\"/></div>\`);
|
let block1 = createBlock(\`<div><input type=\\"checkbox\\" checked=\\"checked\\"/><input checked=\\"checked\\"/><div checked=\\"checked\\"/><div selected=\\"selected\\"/><option selected=\\"selected\\" other=\\"1\\"/><input readonly=\\"readonly\\"/><button disabled=\\"disabled\\"/></div>\`);
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`comments only a comment 1`] = `
|
exports[`comments only a comment 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
return comment(\` comment\`);
|
return comment(\` comment\`);
|
||||||
@@ -12,9 +12,9 @@ exports[`comments only a comment 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`comments properly handle comments 1`] = `
|
exports[`comments properly handle comments 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div>hello <!-- comment-->owl</div>\`);
|
let block1 = createBlock(\`<div>hello <!-- comment-->owl</div>\`);
|
||||||
|
|
||||||
@@ -25,9 +25,9 @@ exports[`comments properly handle comments 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`comments properly handle comments between t-if/t-else 1`] = `
|
exports[`comments properly handle comments between t-if/t-else 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
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(\`<span>true</span>\`);
|
let block2 = createBlock(\`<span>true</span>\`);
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`t-on can bind event handler 1`] = `
|
exports[`t-on can bind event handler 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<button block-handler-0=\\"click\\">Click</button>\`);
|
let block1 = createBlock(\`<button block-handler-0=\\"click\\">Click</button>\`);
|
||||||
|
|
||||||
@@ -15,9 +15,9 @@ exports[`t-on can bind event handler 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-on can bind handlers with arguments 1`] = `
|
exports[`t-on can bind handlers with arguments 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<button block-handler-0=\\"click\\">Click</button>\`);
|
let block1 = createBlock(\`<button block-handler-0=\\"click\\">Click</button>\`);
|
||||||
|
|
||||||
@@ -30,9 +30,9 @@ exports[`t-on can bind handlers with arguments 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-on can bind handlers with empty object 1`] = `
|
exports[`t-on can bind handlers with empty object 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<button block-handler-0=\\"click\\">Click</button>\`);
|
let block1 = createBlock(\`<button block-handler-0=\\"click\\">Click</button>\`);
|
||||||
|
|
||||||
@@ -45,9 +45,9 @@ exports[`t-on can bind handlers with empty object 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-on can bind handlers with empty object (with non empty inner string) 1`] = `
|
exports[`t-on can bind handlers with empty object (with non empty inner string) 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<button block-handler-0=\\"click\\">Click</button>\`);
|
let block1 = createBlock(\`<button block-handler-0=\\"click\\">Click</button>\`);
|
||||||
|
|
||||||
@@ -60,9 +60,9 @@ exports[`t-on can bind handlers with empty object (with non empty inner string)
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-on can bind handlers with empty object (with non empty inner string) 2`] = `
|
exports[`t-on can bind handlers with empty object (with non empty inner string) 2`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { prepareList, withKey } = helpers;
|
let { prepareList, withKey } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<ul><block-child-0/></ul>\`);
|
let block1 = createBlock(\`<ul><block-child-0/></ul>\`);
|
||||||
@@ -70,26 +70,26 @@ exports[`t-on can bind handlers with empty object (with non empty inner string)
|
|||||||
|
|
||||||
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(['someval']);
|
const [k_block2, v_block2, l_block2, c_block2] = prepareList(['someval']);;
|
||||||
for (let i1 = 0; i1 < l_block2; i1++) {
|
for (let i1 = 0; i1 < l_block2; i1++) {
|
||||||
ctx[\`action\`] = v_block2[i1];
|
ctx[\`action\`] = v_block2[i1];
|
||||||
ctx[\`action_index\`] = i1;
|
ctx[\`action_index\`] = i1;
|
||||||
let key1 = ctx['action_index'];
|
const key1 = ctx['action_index'];
|
||||||
const v1 = ctx['activate'];
|
const v1 = ctx['activate'];
|
||||||
const v2 = ctx['action'];
|
const v2 = ctx['action'];
|
||||||
let hdlr1 = [()=>v1(v2), ctx];
|
let hdlr1 = [()=>v1(v2), ctx];
|
||||||
c_block2[i1] = withKey(block3([hdlr1]), key1);
|
c_block2[i1] = withKey(block3([hdlr1]), key1);
|
||||||
}
|
}
|
||||||
let b2 = list(c_block2);
|
const b2 = list(c_block2);
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-on can bind handlers with object arguments 1`] = `
|
exports[`t-on can bind handlers with object arguments 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<button block-handler-0=\\"click\\">Click</button>\`);
|
let block1 = createBlock(\`<button block-handler-0=\\"click\\">Click</button>\`);
|
||||||
|
|
||||||
@@ -102,9 +102,9 @@ exports[`t-on can bind handlers with object arguments 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-on can bind two event handlers 1`] = `
|
exports[`t-on can bind two event handlers 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<button block-handler-0=\\"click\\" block-handler-1=\\"dblclick\\">Click</button>\`);
|
let block1 = createBlock(\`<button block-handler-0=\\"click\\" block-handler-1=\\"dblclick\\">Click</button>\`);
|
||||||
|
|
||||||
@@ -117,9 +117,9 @@ exports[`t-on can bind two event handlers 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-on handler is bound to proper owner 1`] = `
|
exports[`t-on handler is bound to proper owner 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<button block-handler-0=\\"click\\">Click</button>\`);
|
let block1 = createBlock(\`<button block-handler-0=\\"click\\">Click</button>\`);
|
||||||
|
|
||||||
@@ -131,19 +131,19 @@ exports[`t-on handler is bound to proper owner 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-on handler is bound to proper owner, part 2 1`] = `
|
exports[`t-on handler is bound to proper owner, part 2 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { prepareList, withKey } = helpers;
|
let { prepareList, withKey } = helpers;
|
||||||
|
|
||||||
let block2 = createBlock(\`<button block-handler-0=\\"click\\">Click</button>\`);
|
let block2 = createBlock(\`<button block-handler-0=\\"click\\">Click</button>\`);
|
||||||
|
|
||||||
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([1]);
|
const [k_block1, v_block1, l_block1, c_block1] = prepareList([1]);;
|
||||||
for (let i1 = 0; i1 < l_block1; i1++) {
|
for (let i1 = 0; i1 < l_block1; i1++) {
|
||||||
ctx[\`value\`] = v_block1[i1];
|
ctx[\`value\`] = v_block1[i1];
|
||||||
let key1 = ctx['value'];
|
const key1 = ctx['value'];
|
||||||
let hdlr1 = [ctx['add'], ctx];
|
let hdlr1 = [ctx['add'], ctx];
|
||||||
c_block1[i1] = withKey(block2([hdlr1]), key1);
|
c_block1[i1] = withKey(block2([hdlr1]), key1);
|
||||||
}
|
}
|
||||||
@@ -153,11 +153,10 @@ exports[`t-on handler is bound to proper owner, part 2 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-on handler is bound to proper owner, part 3 1`] = `
|
exports[`t-on handler is bound to proper owner, part 3 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { getTemplate } = helpers;
|
const callTemplate_1 = app.getTemplate(\`sub\`);
|
||||||
const callTemplate_1 = getTemplate(\`sub\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
return callTemplate_1.call(this, ctx, node, key + \`__1\`);
|
return callTemplate_1.call(this, ctx, node, key + \`__1\`);
|
||||||
@@ -166,9 +165,9 @@ exports[`t-on handler is bound to proper owner, part 3 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-on handler is bound to proper owner, part 3 2`] = `
|
exports[`t-on handler is bound to proper owner, part 3 2`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<button block-handler-0=\\"click\\">Click</button>\`);
|
let block1 = createBlock(\`<button block-handler-0=\\"click\\">Click</button>\`);
|
||||||
|
|
||||||
@@ -180,22 +179,22 @@ exports[`t-on handler is bound to proper owner, part 3 2`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-on handler is bound to proper owner, part 4 1`] = `
|
exports[`t-on handler is bound to proper owner, part 4 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { prepareList, getTemplate, withKey } = helpers;
|
let { prepareList, withKey } = helpers;
|
||||||
const callTemplate_1 = getTemplate(\`sub\`);
|
const callTemplate_1 = app.getTemplate(\`sub\`);
|
||||||
|
|
||||||
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([1]);
|
const [k_block1, v_block1, l_block1, c_block1] = prepareList([1]);;
|
||||||
for (let i1 = 0; i1 < l_block1; i1++) {
|
for (let i1 = 0; i1 < l_block1; i1++) {
|
||||||
ctx[\`value\`] = v_block1[i1];
|
ctx[\`value\`] = v_block1[i1];
|
||||||
ctx[\`value_first\`] = i1 === 0;
|
ctx[\`value_first\`] = i1 === 0;
|
||||||
ctx[\`value_last\`] = i1 === v_block1.length - 1;
|
ctx[\`value_last\`] = i1 === v_block1.length - 1;
|
||||||
ctx[\`value_index\`] = i1;
|
ctx[\`value_index\`] = i1;
|
||||||
ctx[\`value_value\`] = k_block1[i1];
|
ctx[\`value_value\`] = k_block1[i1];
|
||||||
let key1 = ctx['value'];
|
const key1 = ctx['value'];
|
||||||
c_block1[i1] = withKey(callTemplate_1.call(this, ctx, node, key + \`__1__\${key1}\`), key1);
|
c_block1[i1] = withKey(callTemplate_1.call(this, ctx, node, key + \`__1__\${key1}\`), key1);
|
||||||
}
|
}
|
||||||
return list(c_block1);
|
return list(c_block1);
|
||||||
@@ -204,9 +203,9 @@ exports[`t-on handler is bound to proper owner, part 4 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-on handler is bound to proper owner, part 4 2`] = `
|
exports[`t-on handler is bound to proper owner, part 4 2`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<button block-handler-0=\\"click\\">Click</button>\`);
|
let block1 = createBlock(\`<button block-handler-0=\\"click\\">Click</button>\`);
|
||||||
|
|
||||||
@@ -218,9 +217,9 @@ exports[`t-on handler is bound to proper owner, part 4 2`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-on receive event in first argument 1`] = `
|
exports[`t-on receive event in first argument 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<button block-handler-0=\\"click\\">Click</button>\`);
|
let block1 = createBlock(\`<button block-handler-0=\\"click\\">Click</button>\`);
|
||||||
|
|
||||||
@@ -232,9 +231,9 @@ exports[`t-on receive event in first argument 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-on t-on modifiers (native listener) basic support for native listener 1`] = `
|
exports[`t-on t-on modifiers (native listener) basic support for native listener 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div class=\\"myClass\\" block-handler-0=\\"click\\"><button block-handler-1=\\"click\\">Button</button></div>\`);
|
let block1 = createBlock(\`<div class=\\"myClass\\" block-handler-0=\\"click\\"><button block-handler-1=\\"click\\">Button</button></div>\`);
|
||||||
|
|
||||||
@@ -247,9 +246,9 @@ exports[`t-on t-on modifiers (native listener) basic support for native listener
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-on t-on modifiers (native listener) t-on combined with t-esc 1`] = `
|
exports[`t-on t-on modifiers (native listener) t-on combined with t-esc 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><button block-handler-0=\\"click\\"><block-text-1/></button></div>\`);
|
let block1 = createBlock(\`<div><button block-handler-0=\\"click\\"><block-text-1/></button></div>\`);
|
||||||
|
|
||||||
@@ -262,25 +261,25 @@ exports[`t-on t-on modifiers (native listener) t-on combined with t-esc 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-on t-on modifiers (native listener) t-on combined with t-out 1`] = `
|
exports[`t-on t-on modifiers (native listener) t-on combined with t-out 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { safeOutput } = helpers;
|
let { safeOutput } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><button block-handler-0=\\"click\\"><block-child-0/></button></div>\`);
|
let block1 = createBlock(\`<div><button block-handler-0=\\"click\\"><block-child-0/></button></div>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let hdlr1 = [ctx['onClick'], ctx];
|
let hdlr1 = [ctx['onClick'], ctx];
|
||||||
let b2 = safeOutput(ctx['html']);
|
const b2 = safeOutput(ctx['html']);
|
||||||
return block1([hdlr1], [b2]);
|
return block1([hdlr1], [b2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-on t-on modifiers (native listener) t-on with .capture modifier 1`] = `
|
exports[`t-on t-on modifiers (native listener) t-on with .capture modifier 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div block-handler-0=\\"click.capture\\"><button block-handler-1=\\"click\\">Button</button></div>\`);
|
let block1 = createBlock(\`<div block-handler-0=\\"click.capture\\"><button block-handler-1=\\"click\\">Button</button></div>\`);
|
||||||
|
|
||||||
@@ -293,9 +292,9 @@ exports[`t-on t-on modifiers (native listener) t-on with .capture modifier 1`] =
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-on t-on modifiers (native listener) t-on with empty handler (only modifiers) 1`] = `
|
exports[`t-on t-on modifiers (native listener) t-on with empty handler (only modifiers) 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><button block-handler-0=\\"click.prevent\\">Button</button></div>\`);
|
let block1 = createBlock(\`<div><button block-handler-0=\\"click.prevent\\">Button</button></div>\`);
|
||||||
|
|
||||||
@@ -307,9 +306,9 @@ exports[`t-on t-on modifiers (native listener) t-on with empty handler (only mod
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-on t-on modifiers (native listener) t-on with prevent and self modifiers (order matters) 1`] = `
|
exports[`t-on t-on modifiers (native listener) t-on with prevent and self modifiers (order matters) 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><button block-handler-0=\\"click.prevent.self\\"><span>Button</span></button></div>\`);
|
let block1 = createBlock(\`<div><button block-handler-0=\\"click.prevent.self\\"><span>Button</span></button></div>\`);
|
||||||
|
|
||||||
@@ -321,9 +320,9 @@ exports[`t-on t-on modifiers (native listener) t-on with prevent and self modifi
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-on t-on modifiers (native listener) t-on with prevent and/or stop modifiers 1`] = `
|
exports[`t-on t-on modifiers (native listener) t-on with prevent and/or stop modifiers 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
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>\`);
|
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>\`);
|
||||||
|
|
||||||
@@ -337,9 +336,9 @@ exports[`t-on t-on modifiers (native listener) t-on with prevent and/or stop mod
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-on t-on modifiers (native listener) t-on with prevent modifier in t-foreach 1`] = `
|
exports[`t-on t-on modifiers (native listener) t-on with prevent modifier in t-foreach 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { prepareList, withKey } = helpers;
|
let { prepareList, withKey } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
@@ -347,26 +346,26 @@ exports[`t-on t-on modifiers (native listener) t-on with prevent modifier in t-f
|
|||||||
|
|
||||||
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(ctx['projects']);
|
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['projects']);;
|
||||||
for (let i1 = 0; i1 < l_block2; i1++) {
|
for (let i1 = 0; i1 < l_block2; i1++) {
|
||||||
ctx[\`project\`] = v_block2[i1];
|
ctx[\`project\`] = v_block2[i1];
|
||||||
let key1 = ctx['project'];
|
const key1 = ctx['project'];
|
||||||
const v1 = ctx['onEdit'];
|
const v1 = ctx['onEdit'];
|
||||||
const v2 = ctx['project'];
|
const v2 = ctx['project'];
|
||||||
let hdlr1 = [\\"prevent\\", ev=>v1(v2.id,ev), ctx];
|
let hdlr1 = [\\"prevent\\", _ev=>v1(v2.id,_ev), ctx];
|
||||||
let txt1 = ctx['project'].name;
|
let txt1 = ctx['project'].name;
|
||||||
c_block2[i1] = withKey(block3([hdlr1, txt1]), key1);
|
c_block2[i1] = withKey(block3([hdlr1, txt1]), key1);
|
||||||
}
|
}
|
||||||
let b2 = list(c_block2);
|
const b2 = list(c_block2);
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-on t-on modifiers (native listener) t-on with self and prevent modifiers (order matters) 1`] = `
|
exports[`t-on t-on modifiers (native listener) t-on with self and prevent modifiers (order matters) 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><button block-handler-0=\\"click.self.prevent\\"><span>Button</span></button></div>\`);
|
let block1 = createBlock(\`<div><button block-handler-0=\\"click.self.prevent\\"><span>Button</span></button></div>\`);
|
||||||
|
|
||||||
@@ -378,9 +377,9 @@ exports[`t-on t-on modifiers (native listener) t-on with self and prevent modifi
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-on t-on modifiers (native listener) t-on with self modifier 1`] = `
|
exports[`t-on t-on modifiers (native listener) t-on with self modifier 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><button block-handler-0=\\"click\\"><span>Button</span></button><button block-handler-1=\\"click.self\\"><span>Button</span></button></div>\`);
|
let block1 = createBlock(\`<div><button block-handler-0=\\"click\\"><span>Button</span></button><button block-handler-1=\\"click.self\\"><span>Button</span></button></div>\`);
|
||||||
|
|
||||||
@@ -393,9 +392,9 @@ exports[`t-on t-on modifiers (native listener) t-on with self modifier 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-on t-on modifiers (synthetic listener) basic support for synthetic 1`] = `
|
exports[`t-on t-on modifiers (synthetic listener) basic support for synthetic 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div block-handler-0=\\"click.synthetic\\"><button block-handler-1=\\"click.synthetic\\">Button</button></div>\`);
|
let block1 = createBlock(\`<div block-handler-0=\\"click.synthetic\\"><button block-handler-1=\\"click.synthetic\\">Button</button></div>\`);
|
||||||
|
|
||||||
@@ -408,9 +407,9 @@ exports[`t-on t-on modifiers (synthetic listener) basic support for synthetic 1`
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-on t-on with inline statement (function call) 1`] = `
|
exports[`t-on t-on with inline statement (function call) 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<button block-handler-0=\\"click\\">Click</button>\`);
|
let block1 = createBlock(\`<button block-handler-0=\\"click\\">Click</button>\`);
|
||||||
|
|
||||||
@@ -423,9 +422,9 @@ exports[`t-on t-on with inline statement (function call) 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-on t-on with inline statement 1`] = `
|
exports[`t-on t-on with inline statement 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<button block-handler-0=\\"click\\">Click</button>\`);
|
let block1 = createBlock(\`<button block-handler-0=\\"click\\">Click</button>\`);
|
||||||
|
|
||||||
@@ -438,9 +437,9 @@ exports[`t-on t-on with inline statement 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-on t-on with inline statement, part 2 1`] = `
|
exports[`t-on t-on with inline statement, part 2 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<button block-handler-0=\\"click\\">Toggle</button>\`);
|
let block1 = createBlock(\`<button block-handler-0=\\"click\\">Toggle</button>\`);
|
||||||
|
|
||||||
@@ -453,9 +452,9 @@ exports[`t-on t-on with inline statement, part 2 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-on t-on with inline statement, part 3 1`] = `
|
exports[`t-on t-on with inline statement, part 3 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<button block-handler-0=\\"click\\">Toggle</button>\`);
|
let block1 = createBlock(\`<button block-handler-0=\\"click\\">Toggle</button>\`);
|
||||||
|
|
||||||
@@ -469,25 +468,24 @@ exports[`t-on t-on with inline statement, part 3 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-on t-on with t-call 1`] = `
|
exports[`t-on t-on with t-call 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { getTemplate } = helpers;
|
const callTemplate_1 = app.getTemplate(\`sub\`);
|
||||||
const callTemplate_1 = getTemplate(\`sub\`);
|
|
||||||
|
|
||||||
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 = \\"\\") {
|
||||||
let b2 = callTemplate_1.call(this, ctx, node, key + \`__1\`);
|
const b2 = callTemplate_1.call(this, ctx, node, key + \`__1\`);
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-on t-on with t-call 2`] = `
|
exports[`t-on t-on with t-call 2`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<p block-handler-0=\\"click\\">lucas</p>\`);
|
let block1 = createBlock(\`<p block-handler-0=\\"click\\">lucas</p>\`);
|
||||||
|
|
||||||
@@ -499,31 +497,31 @@ exports[`t-on t-on with t-call 2`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-on t-on, with arguments and t-call 1`] = `
|
exports[`t-on t-on, with arguments and t-call 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { getTemplate } = helpers;
|
const callTemplate_1 = app.getTemplate(\`sub\`);
|
||||||
const callTemplate_1 = getTemplate(\`sub\`);
|
|
||||||
|
|
||||||
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 = \\"\\") {
|
||||||
let b2 = callTemplate_1.call(this, ctx, node, key + \`__1\`);
|
const b2 = callTemplate_1.call(this, ctx, node, key + \`__1\`);
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-on t-on, with arguments and t-call 2`] = `
|
exports[`t-on t-on, with arguments and t-call 2`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<p block-handler-0=\\"click\\">lucas</p>\`);
|
let block1 = createBlock(\`<p block-handler-0=\\"click\\">lucas</p>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
const v1 = ctx['value'];
|
const v1 = ctx['this'];
|
||||||
let hdlr1 = [()=>this.update(v1), ctx];
|
const v2 = ctx['value'];
|
||||||
|
let hdlr1 = [()=>v1.update(v2), ctx];
|
||||||
return block1([hdlr1]);
|
return block1([hdlr1]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`misc complex template 1`] = `
|
exports[`misc complex template 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { prepareList, withKey } = helpers;
|
let { prepareList, withKey } = helpers;
|
||||||
|
const comp1 = app.createComponent(\`SlotButton\`, true, false, false, false);
|
||||||
|
|
||||||
let block1 = createBlock(\`<div block-attribute-0=\\"class\\"><div block-attribute-1=\\"class\\"><div class=\\"batch_header\\"><a block-attribute-2=\\"href\\" block-attribute-3=\\"class\\" title=\\"View Batch\\"><block-text-4/><block-child-0/><i class=\\"arrow fa fa-window-maximize\\"/></a></div><block-child-1/><div class=\\"batch_slots\\"><block-child-2/><block-child-3/></div><div class=\\"batch_commits\\"><block-child-4/></div></div></div>\`);
|
let block1 = createBlock(\`<div block-attribute-0=\\"class\\"><div block-attribute-1=\\"class\\"><div class=\\"batch_header\\"><a block-attribute-2=\\"href\\" block-attribute-3=\\"class\\" title=\\"View Batch\\"><block-text-4/><block-child-0/><i class=\\"arrow fa fa-window-maximize\\"/></a></div><block-child-1/><div class=\\"batch_slots\\"><block-child-2/><block-child-3/></div><div class=\\"batch_commits\\"><block-child-4/></div></div></div>\`);
|
||||||
let block2 = createBlock(\`<i class=\\"fa fa-exclamation-triangle\\"/>\`);
|
let block2 = createBlock(\`<i class=\\"fa fa-exclamation-triangle\\"/>\`);
|
||||||
@@ -30,28 +31,28 @@ exports[`misc complex template 1`] = `
|
|||||||
b3 = block3();
|
b3 = block3();
|
||||||
}
|
}
|
||||||
ctx = Object.create(ctx);
|
ctx = Object.create(ctx);
|
||||||
const [k_block4, v_block4, l_block4, c_block4] = prepareList(ctx['batch'].slot_ids.filter(slot=>slot.build_id.id&&!slot.trigger_id.manual&&(ctx['options'].trigger_display[slot.trigger_id.id])));
|
const [k_block4, v_block4, l_block4, c_block4] = prepareList(ctx['batch'].slot_ids.filter(_slot=>_slot.build_id.id&&!_slot.trigger_id.manual&&(ctx['options'].trigger_display[_slot.trigger_id.id])));;
|
||||||
for (let i1 = 0; i1 < l_block4; i1++) {
|
for (let i1 = 0; i1 < l_block4; i1++) {
|
||||||
ctx[\`slot\`] = v_block4[i1];
|
ctx[\`slot\`] = v_block4[i1];
|
||||||
let key1 = ctx['slot'].id;
|
const key1 = ctx['slot'].id;
|
||||||
c_block4[i1] = withKey(component(\`SlotButton\`, {class: ctx['slot_container'],slot: ctx['slot']}, key + \`__1__\${key1}\`, node, ctx), key1);
|
c_block4[i1] = withKey(comp1({class: ctx['slot_container'],slot: ctx['slot']}, key + \`__1__\${key1}\`, node, this, null), key1);
|
||||||
}
|
}
|
||||||
ctx = ctx.__proto__;
|
ctx = ctx.__proto__;
|
||||||
b4 = list(c_block4);
|
b4 = list(c_block4);
|
||||||
ctx = Object.create(ctx);
|
ctx = Object.create(ctx);
|
||||||
const [k_block6, v_block6, l_block6, c_block6] = prepareList([1,2,3,4]);
|
const [k_block6, v_block6, l_block6, c_block6] = prepareList([1,2,3,4]);;
|
||||||
for (let i1 = 0; i1 < l_block6; i1++) {
|
for (let i1 = 0; i1 < l_block6; i1++) {
|
||||||
ctx[\`x\`] = v_block6[i1];
|
ctx[\`x\`] = v_block6[i1];
|
||||||
let key1 = ctx['x'];
|
const key1 = ctx['x'];
|
||||||
c_block6[i1] = withKey(block7(), key1);
|
c_block6[i1] = withKey(block7(), key1);
|
||||||
}
|
}
|
||||||
ctx = ctx.__proto__;
|
ctx = ctx.__proto__;
|
||||||
b6 = list(c_block6);
|
b6 = list(c_block6);
|
||||||
ctx = Object.create(ctx);
|
ctx = Object.create(ctx);
|
||||||
const [k_block8, v_block8, l_block8, c_block8] = prepareList(ctx['commit_links']);
|
const [k_block8, v_block8, l_block8, c_block8] = prepareList(ctx['commit_links']);;
|
||||||
for (let i1 = 0; i1 < l_block8; i1++) {
|
for (let i1 = 0; i1 < l_block8; i1++) {
|
||||||
ctx[\`commit_link\`] = v_block8[i1];
|
ctx[\`commit_link\`] = v_block8[i1];
|
||||||
let key1 = ctx['commit_link'].id;
|
const key1 = ctx['commit_link'].id;
|
||||||
let b10,b11,b12,b13;
|
let b10,b11,b12,b13;
|
||||||
let attr5 = \`/runbot/commit/\${ctx['commit_link'].commit_id}\`;
|
let attr5 = \`/runbot/commit/\${ctx['commit_link'].commit_id}\`;
|
||||||
let attr6 = \`badge badge-light batch_commit match_type_\${ctx['commit_link'].match_type}\`;
|
let attr6 = \`badge badge-light batch_commit match_type_\${ctx['commit_link'].match_type}\`;
|
||||||
@@ -79,15 +80,15 @@ exports[`misc complex template 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`misc global 1`] = `
|
exports[`misc global 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { prepareList, isBoundary, withDefault, setContextValue, getTemplate, zero, withKey } = helpers;
|
let { prepareList, isBoundary, withDefault, setContextValue, zero, withKey } = helpers;
|
||||||
const callTemplate_1 = getTemplate(\`_callee-uses-foo\`);
|
const callTemplate_1 = app.getTemplate(\`_callee-uses-foo\`);
|
||||||
const callTemplate_2 = getTemplate(\`_callee-uses-foo\`);
|
const callTemplate_2 = app.getTemplate(\`_callee-uses-foo\`);
|
||||||
const callTemplate_3 = getTemplate(\`_callee-uses-foo\`);
|
const callTemplate_3 = app.getTemplate(\`_callee-uses-foo\`);
|
||||||
const callTemplate_4 = getTemplate(\`_callee-asc\`);
|
const callTemplate_4 = app.getTemplate(\`_callee-asc\`);
|
||||||
const callTemplate_5 = getTemplate(\`_callee-asc-toto\`);
|
const callTemplate_5 = app.getTemplate(\`_callee-asc-toto\`);
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
|
||||||
let block4 = createBlock(\`<span><block-text-0/></span>\`);
|
let block4 = createBlock(\`<span><block-text-0/></span>\`);
|
||||||
@@ -96,44 +97,44 @@ exports[`misc global 1`] = `
|
|||||||
ctx = Object.create(ctx);
|
ctx = Object.create(ctx);
|
||||||
ctx[isBoundary] = 1
|
ctx[isBoundary] = 1
|
||||||
ctx = Object.create(ctx);
|
ctx = Object.create(ctx);
|
||||||
const [k_block2, v_block2, l_block2, c_block2] = prepareList([4,5,6]);
|
const [k_block2, v_block2, l_block2, c_block2] = prepareList([4,5,6]);;
|
||||||
for (let i1 = 0; i1 < l_block2; i1++) {
|
for (let i1 = 0; i1 < l_block2; i1++) {
|
||||||
ctx[\`value\`] = v_block2[i1];
|
ctx[\`value\`] = v_block2[i1];
|
||||||
ctx[\`value_first\`] = i1 === 0;
|
ctx[\`value_first\`] = i1 === 0;
|
||||||
ctx[\`value_last\`] = i1 === v_block2.length - 1;
|
ctx[\`value_last\`] = i1 === v_block2.length - 1;
|
||||||
ctx[\`value_index\`] = i1;
|
ctx[\`value_index\`] = i1;
|
||||||
ctx[\`value_value\`] = k_block2[i1];
|
ctx[\`value_value\`] = k_block2[i1];
|
||||||
let key1 = ctx['value'];
|
const key1 = ctx['value'];
|
||||||
let txt1 = ctx['value'];
|
let txt1 = ctx['value'];
|
||||||
let b4 = block4([txt1]);
|
const b4 = block4([txt1]);
|
||||||
ctx = Object.create(ctx);
|
ctx = Object.create(ctx);
|
||||||
ctx[isBoundary] = 1;
|
ctx[isBoundary] = 1;
|
||||||
ctx = Object.create(ctx);
|
ctx = Object.create(ctx);
|
||||||
ctx[isBoundary] = 1;
|
ctx[isBoundary] = 1;
|
||||||
setContextValue(ctx, \\"foo\\", 'aaa');
|
setContextValue(ctx, \\"foo\\", 'aaa');
|
||||||
let b6 = callTemplate_1.call(this, ctx, node, key + \`__1__\${key1}\`);
|
const b6 = callTemplate_1.call(this, ctx, node, key + \`__1__\${key1}\`);
|
||||||
ctx = ctx.__proto__;
|
ctx = ctx.__proto__;
|
||||||
let b7 = callTemplate_2.call(this, ctx, node, key + \`__2__\${key1}\`);
|
const b7 = callTemplate_2.call(this, ctx, node, key + \`__2__\${key1}\`);
|
||||||
setContextValue(ctx, \\"foo\\", 'bbb');
|
setContextValue(ctx, \\"foo\\", 'bbb');
|
||||||
let b8 = callTemplate_3.call(this, ctx, node, key + \`__3__\${key1}\`);
|
const b8 = callTemplate_3.call(this, ctx, node, key + \`__3__\${key1}\`);
|
||||||
let b5 = multi([b6, b7, b8]);
|
const b5 = multi([b6, b7, b8]);
|
||||||
ctx[zero] = b5;
|
ctx[zero] = b5;
|
||||||
let b9 = callTemplate_4.call(this, ctx, node, key + \`__4__\${key1}\`);
|
const b9 = callTemplate_4.call(this, ctx, node, key + \`__4__\${key1}\`);
|
||||||
ctx = ctx.__proto__;
|
ctx = ctx.__proto__;
|
||||||
c_block2[i1] = withKey(multi([b4, b9]), key1);
|
c_block2[i1] = withKey(multi([b4, b9]), key1);
|
||||||
}
|
}
|
||||||
ctx = ctx.__proto__;
|
ctx = ctx.__proto__;
|
||||||
let b2 = list(c_block2);
|
const b2 = list(c_block2);
|
||||||
let b10 = callTemplate_5.call(this, ctx, node, key + \`__5\`);
|
const b10 = callTemplate_5.call(this, ctx, node, key + \`__5\`);
|
||||||
return block1([], [b2, b10]);
|
return block1([], [b2, b10]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`misc global 2`] = `
|
exports[`misc global 2`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { withDefault } = helpers;
|
let { withDefault } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
||||||
@@ -146,43 +147,45 @@ exports[`misc global 2`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`misc global 3`] = `
|
exports[`misc global 3`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { zero } = helpers;
|
let { zero } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<año block-attribute-0=\\"falló\\"><block-child-0/></año>\`);
|
let block1 = createBlock(\`<año block-attribute-0=\\"falló\\"><block-child-0/></año>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let attr1 = 'agüero';
|
let attr1 = 'agüero';
|
||||||
let b2 = ctx[zero];
|
const b2 = ctx[zero];
|
||||||
return block1([attr1], [b2]);
|
return block1([attr1], [b2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`misc global 4`] = `
|
exports[`misc global 4`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { safeOutput, withDefault } = helpers;
|
let { safeOutput } = 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 = \\"\\") {
|
||||||
let b3 = text(\`toto default\`);
|
const b3 = text(\`toto default\`);
|
||||||
let b2 = withDefault(safeOutput(ctx['toto']), b3);
|
const b2 = safeOutput(ctx['toto'], b3);
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`misc other complex template 1`] = `
|
exports[`misc other complex template 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { prepareList, withKey, getTemplate } = helpers;
|
let { prepareList, withKey, singleRefSetter } = helpers;
|
||||||
const callTemplate_1 = getTemplate(\`LOAD_INFOS_TEMPLATE\`);
|
const callTemplate_1 = app.getTemplate(\`LOAD_INFOS_TEMPLATE\`);
|
||||||
|
const comp1 = app.createComponent(\`BundlesList\`, true, false, false, false);
|
||||||
|
const comp2 = app.createComponent(\`BundlesList\`, true, false, false, false);
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><header><nav class=\\"navbar navbar-expand-md navbar-light bg-light\\"><a block-attribute-0=\\"href\\"><b style=\\"color:#777;\\"><block-text-1/></b></a><button type=\\"button\\" class=\\"navbar-toggler\\" data-toggle=\\"collapse\\" data-target=\\"#top_menu_collapse\\"><span class=\\"navbar-toggler-icon\\"/></button><div class=\\"collapse navbar-collapse\\" id=\\"top_menu_collapse\\" aria-expanded=\\"false\\"><ul class=\\"nav navbar-nav ml-auto text-right\\" id=\\"top_menu\\"><block-child-0/><li class=\\"nav-item divider\\"/><block-child-1/></ul><div><div class=\\"input-group input-group-sm\\"><div class=\\"input-group-prepend input-group-sm\\"><button class=\\"btn btn-default fa fa-cog\\" title=\\"Settings\\" block-handler-2=\\"click\\"/><button class=\\"btn btn-default\\" block-handler-3=\\"click\\"> More </button><block-child-2/></div><input class=\\"form-control\\" type=\\"text\\" placeholder=\\"Search\\" aria-label=\\"Search\\" name=\\"search\\" block-attribute-4=\\"value\\" block-handler-5=\\"keyup\\" block-handler-6=\\"change\\" block-ref=\\"7\\"/><div class=\\"input-group-append\\"><button class=\\"btn btn-default fa fa-eraser\\" block-handler-8=\\"click\\"/></div></div></div></div></nav></header><div class=\\"container-fluid\\" block-ref=\\"9\\"><div class=\\"row\\"><!--div class=\\"form-group col-md-6\\">
|
let block1 = createBlock(\`<div><header><nav class=\\"navbar navbar-expand-md navbar-light bg-light\\"><a block-attribute-0=\\"href\\"><b style=\\"color:#777;\\"><block-text-1/></b></a><button type=\\"button\\" class=\\"navbar-toggler\\" data-toggle=\\"collapse\\" data-target=\\"#top_menu_collapse\\"><span class=\\"navbar-toggler-icon\\"/></button><div class=\\"collapse navbar-collapse\\" id=\\"top_menu_collapse\\" aria-expanded=\\"false\\"><ul class=\\"nav navbar-nav ml-auto text-right\\" id=\\"top_menu\\"><block-child-0/><li class=\\"nav-item divider\\"/><block-child-1/></ul><div><div class=\\"input-group input-group-sm\\"><div class=\\"input-group-prepend input-group-sm\\"><button class=\\"btn btn-default fa fa-cog\\" title=\\"Settings\\" block-handler-2=\\"click\\"/><button class=\\"btn btn-default\\" block-handler-3=\\"click\\"> More </button><block-child-2/></div><input class=\\"form-control\\" type=\\"text\\" placeholder=\\"Search\\" aria-label=\\"Search\\" name=\\"search\\" block-attribute-4=\\"value\\" block-handler-5=\\"keyup\\" block-handler-6=\\"change\\" block-ref=\\"7\\"/><div class=\\"input-group-append\\"><button class=\\"btn btn-default fa fa-eraser\\" block-handler-8=\\"click\\"/></div></div></div></div></nav></header><div class=\\"container-fluid\\" block-ref=\\"9\\"><div class=\\"row\\"><!--div class=\\"form-group col-md-6\\">
|
||||||
<h5>Search options</h5>
|
<h5>Search options</h5>
|
||||||
@@ -214,17 +217,17 @@ exports[`misc other complex template 1`] = `
|
|||||||
let block25 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
|
let block25 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
const refs = ctx.__owl__.refs;
|
const refs = this.__owl__.refs;
|
||||||
const ref1 = (el) => refs[\`search_input\`] = el;
|
const ref1 = singleRefSetter(refs, \`search_input\`);
|
||||||
const ref2 = (el) => refs[\`settings_menu\`] = el;
|
const ref2 = singleRefSetter(refs, \`settings_menu\`);
|
||||||
let b2,b4,b14,b17,b22,b23,b24,b25;
|
let b2,b4,b14,b17,b22,b23,b24,b25;
|
||||||
let attr1 = \`/runbot/\${ctx['project'].slug}\`;
|
let attr1 = \`/runbot/\${ctx['project'].slug}\`;
|
||||||
let txt1 = ctx['project'].name;
|
let txt1 = ctx['project'].name;
|
||||||
ctx = Object.create(ctx);
|
ctx = Object.create(ctx);
|
||||||
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['projects']);
|
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['projects']);;
|
||||||
for (let i1 = 0; i1 < l_block2; i1++) {
|
for (let i1 = 0; i1 < l_block2; i1++) {
|
||||||
ctx[\`project\`] = v_block2[i1];
|
ctx[\`project\`] = v_block2[i1];
|
||||||
let key1 = ctx['project'].id;
|
const key1 = ctx['project'].id;
|
||||||
let hdlr1 = [ctx['selectProject'](ctx['project']), ctx];
|
let hdlr1 = [ctx['selectProject'](ctx['project']), ctx];
|
||||||
let txt2 = ctx['project'].name;
|
let txt2 = ctx['project'].name;
|
||||||
c_block2[i1] = withKey(block3([hdlr1, txt2]), key1);
|
c_block2[i1] = withKey(block3([hdlr1, txt2]), key1);
|
||||||
@@ -241,12 +244,12 @@ exports[`misc other complex template 1`] = `
|
|||||||
if (ctx['nb_assigned_errors']&&ctx['nb_assigned_errors']>0) {
|
if (ctx['nb_assigned_errors']&&ctx['nb_assigned_errors']>0) {
|
||||||
let attr3 = \`You have \${ctx['nb_assigned_errors']} random bug assigned\`;
|
let attr3 = \`You have \${ctx['nb_assigned_errors']} random bug assigned\`;
|
||||||
let txt3 = ctx['nb_assigned_errors'];
|
let txt3 = ctx['nb_assigned_errors'];
|
||||||
let b8 = block8([attr3, txt3]);
|
const b8 = block8([attr3, txt3]);
|
||||||
let b9 = block9();
|
const b9 = block9();
|
||||||
b7 = multi([b8, b9]);
|
b7 = multi([b8, b9]);
|
||||||
} else if (ctx['nb_build_errors']&&ctx['nb_build_errors']>0) {
|
} else if (ctx['nb_build_errors']&&ctx['nb_build_errors']>0) {
|
||||||
let b11 = block11();
|
const b11 = block11();
|
||||||
let b12 = block12();
|
const b12 = block12();
|
||||||
b10 = multi([b11, b12]);
|
b10 = multi([b11, b12]);
|
||||||
}
|
}
|
||||||
let txt4 = ctx['user'].name.length>25?ctx['user'].namesubstring(0,23)+'...':ctx['user'].name;
|
let txt4 = ctx['user'].name.length>25?ctx['user'].namesubstring(0,23)+'...':ctx['user'].name;
|
||||||
@@ -261,34 +264,34 @@ exports[`misc other complex template 1`] = `
|
|||||||
let hdlr3 = [ctx['toggleMore'], ctx];
|
let hdlr3 = [ctx['toggleMore'], ctx];
|
||||||
if (ctx['categories']&&ctx['categories'].length>1) {
|
if (ctx['categories']&&ctx['categories'].length>1) {
|
||||||
ctx = Object.create(ctx);
|
ctx = Object.create(ctx);
|
||||||
const [k_block15, v_block15, l_block15, c_block15] = prepareList(ctx['categories']);
|
const [k_block15, v_block15, l_block15, c_block15] = prepareList(ctx['categories']);;
|
||||||
for (let i1 = 0; i1 < l_block15; i1++) {
|
for (let i1 = 0; i1 < l_block15; i1++) {
|
||||||
ctx[\`category\`] = v_block15[i1];
|
ctx[\`category\`] = v_block15[i1];
|
||||||
let key1 = ctx['category'].id;
|
const key1 = ctx['category'].id;
|
||||||
let attr6 = ctx['category'].id;
|
let attr6 = ctx['category'].id;
|
||||||
let attr7 = ctx['category'].id==ctx['options'].active_category_id;
|
let attr7 = new Boolean(ctx['category'].id==ctx['options'].active_category_id);
|
||||||
let txt5 = ctx['category'].name;
|
let txt5 = ctx['category'].name;
|
||||||
c_block15[i1] = withKey(block16([attr6, attr7, txt5]), key1);
|
c_block15[i1] = withKey(block16([attr6, attr7, txt5]), key1);
|
||||||
}
|
}
|
||||||
ctx = ctx.__proto__;
|
ctx = ctx.__proto__;
|
||||||
let b15 = list(c_block15);
|
const b15 = list(c_block15);
|
||||||
b14 = block14([], [b15]);
|
b14 = block14([], [b15]);
|
||||||
}
|
}
|
||||||
let attr8 = ctx['search'].value;
|
let attr8 = new String((ctx['search'].value) || \\"\\");
|
||||||
let hdlr4 = [ctx['updateFilter'], ctx];
|
let hdlr4 = [ctx['updateFilter'], ctx];
|
||||||
let hdlr5 = [ctx['updateFilter'], ctx];
|
let hdlr5 = [ctx['updateFilter'], ctx];
|
||||||
let hdlr6 = [ctx['clearSearch'], ctx];
|
let hdlr6 = [ctx['clearSearch'], ctx];
|
||||||
if (ctx['triggers']) {
|
if (ctx['triggers']) {
|
||||||
ctx = Object.create(ctx);
|
ctx = Object.create(ctx);
|
||||||
const [k_block18, v_block18, l_block18, c_block18] = prepareList(ctx['triggers']);
|
const [k_block18, v_block18, l_block18, c_block18] = prepareList(ctx['triggers']);;
|
||||||
for (let i1 = 0; i1 < l_block18; i1++) {
|
for (let i1 = 0; i1 < l_block18; i1++) {
|
||||||
ctx[\`trigger\`] = v_block18[i1];
|
ctx[\`trigger\`] = v_block18[i1];
|
||||||
let key1 = ctx['trigger'].id;
|
const key1 = ctx['trigger'].id;
|
||||||
let b20;
|
let b20;
|
||||||
if (!ctx['trigger'].manual&&ctx['trigger'].project_id===ctx['project'].id&&ctx['trigger'].category_id===ctx['options'].active_category_id) {
|
if (!ctx['trigger'].manual&&ctx['trigger'].project_id===ctx['project'].id&&ctx['trigger'].category_id===ctx['options'].active_category_id) {
|
||||||
let attr9 = \`trigger_\${ctx['trigger'].id}\`;
|
let attr9 = \`trigger_\${ctx['trigger'].id}\`;
|
||||||
let attr10 = \`trigger_\${ctx['trigger'].id}\`;
|
let attr10 = \`trigger_\${ctx['trigger'].id}\`;
|
||||||
let attr11 = ctx['options'].trigger_display[ctx['trigger'].id];
|
let attr11 = new Boolean(ctx['options'].trigger_display[ctx['trigger'].id]);
|
||||||
let attr12 = ctx['trigger'].id;
|
let attr12 = ctx['trigger'].id;
|
||||||
let hdlr7 = [ctx['updateTriggerDisplay'], ctx];
|
let hdlr7 = [ctx['updateTriggerDisplay'], ctx];
|
||||||
let attr13 = \`trigger_\${ctx['trigger'].id}\`;
|
let attr13 = \`trigger_\${ctx['trigger'].id}\`;
|
||||||
@@ -298,12 +301,12 @@ exports[`misc other complex template 1`] = `
|
|||||||
c_block18[i1] = withKey(multi([b20]), key1);
|
c_block18[i1] = withKey(multi([b20]), key1);
|
||||||
}
|
}
|
||||||
ctx = ctx.__proto__;
|
ctx = ctx.__proto__;
|
||||||
let b18 = list(c_block18);
|
const b18 = list(c_block18);
|
||||||
let hdlr8 = [ctx['triggerAll'], ctx];
|
let hdlr8 = [ctx['triggerAll'], ctx];
|
||||||
let hdlr9 = [ctx['triggerNone'], ctx];
|
let hdlr9 = [ctx['triggerNone'], ctx];
|
||||||
let hdlr10 = [ctx['triggerDefault'], ctx];
|
let hdlr10 = [ctx['triggerDefault'], ctx];
|
||||||
let hdlr11 = [ctx['toggleSettingsMenu'], ctx];
|
let hdlr11 = [ctx['toggleSettingsMenu'], ctx];
|
||||||
let b21 = block21([hdlr8, hdlr9, hdlr10, hdlr11]);
|
const b21 = block21([hdlr8, hdlr9, hdlr10, hdlr11]);
|
||||||
b17 = multi([b18, b21]);
|
b17 = multi([b18, b21]);
|
||||||
}
|
}
|
||||||
if (ctx['load_infos']) {
|
if (ctx['load_infos']) {
|
||||||
@@ -316,8 +319,8 @@ exports[`misc other complex template 1`] = `
|
|||||||
if (!ctx['project']) {
|
if (!ctx['project']) {
|
||||||
b24 = block24();
|
b24 = block24();
|
||||||
} else {
|
} else {
|
||||||
let b26 = component(\`BundlesList\`, {bundles: ctx['bundles'].sticky,category_custom_views: ctx['category_custom_views'],search: ctx['search']}, key + \`__2\`, node, ctx);
|
const b26 = comp1({bundles: ctx['bundles'].sticky,category_custom_views: ctx['category_custom_views'],search: ctx['search']}, key + \`__2\`, node, this, null);
|
||||||
let b27 = component(\`BundlesList\`, {bundles: ctx['bundles'].dev,search: ctx['search']}, key + \`__3\`, node, ctx);
|
const b27 = comp2({bundles: ctx['bundles'].dev,search: ctx['search']}, key + \`__3\`, node, this, null);
|
||||||
b25 = block25([], [b26, b27]);
|
b25 = block25([], [b26, b27]);
|
||||||
}
|
}
|
||||||
return block1([attr1, txt1, hdlr2, hdlr3, attr8, hdlr4, hdlr5, ref1, hdlr6, ref2], [b2, b4, b14, b17, b22, b23, b24, b25]);
|
return block1([attr1, txt1, hdlr2, hdlr3, attr8, hdlr4, hdlr5, ref1, hdlr6, ref2], [b2, b4, b14, b17, b22, b23, b24, b25]);
|
||||||
|
|||||||
@@ -1,23 +1,23 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`memory t-foreach does not leak stuff in global scope 1`] = `
|
exports[`memory t-foreach does not leak stuff in global scope 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { prepareList, withKey } = helpers;
|
let { prepareList, withKey } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<p><block-child-0/></p>\`);
|
let block1 = createBlock(\`<p><block-child-0/></p>\`);
|
||||||
|
|
||||||
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([3,2,1]);
|
const [k_block2, v_block2, l_block2, c_block2] = prepareList([3,2,1]);;
|
||||||
for (let i1 = 0; i1 < l_block2; i1++) {
|
for (let i1 = 0; i1 < l_block2; i1++) {
|
||||||
ctx[\`item\`] = v_block2[i1];
|
ctx[\`item\`] = v_block2[i1];
|
||||||
ctx[\`item_index\`] = i1;
|
ctx[\`item_index\`] = i1;
|
||||||
let key1 = ctx['item_index'];
|
const key1 = ctx['item_index'];
|
||||||
c_block2[i1] = withKey(text(ctx['item']), key1);
|
c_block2[i1] = withKey(text(ctx['item']), key1);
|
||||||
}
|
}
|
||||||
let b2 = list(c_block2);
|
const b2 = list(c_block2);
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`simple templates, mostly static can render a table row 1`] = `
|
exports[`simple templates, mostly static can render a table row 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<tr><td>cell</td></tr>\`);
|
let block1 = createBlock(\`<tr><td>cell</td></tr>\`);
|
||||||
|
|
||||||
@@ -14,9 +14,9 @@ exports[`simple templates, mostly static can render a table row 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`simple templates, mostly static div with a class attribute 1`] = `
|
exports[`simple templates, mostly static div with a class attribute 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div class=\\"abc\\">foo</div>\`);
|
let block1 = createBlock(\`<div class=\\"abc\\">foo</div>\`);
|
||||||
|
|
||||||
@@ -27,9 +27,9 @@ exports[`simple templates, mostly static div with a class attribute 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`simple templates, mostly static div with a class attribute with a quote 1`] = `
|
exports[`simple templates, mostly static div with a class attribute with a quote 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div class=\\"a'bc\\">word</div>\`);
|
let block1 = createBlock(\`<div class=\\"a'bc\\">word</div>\`);
|
||||||
|
|
||||||
@@ -40,9 +40,9 @@ exports[`simple templates, mostly static div with a class attribute with a quote
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`simple templates, mostly static div with a span child node 1`] = `
|
exports[`simple templates, mostly static div with a span child node 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><span>word</span></div>\`);
|
let block1 = createBlock(\`<div><span>word</span></div>\`);
|
||||||
|
|
||||||
@@ -53,9 +53,9 @@ exports[`simple templates, mostly static div with a span child node 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`simple templates, mostly static div with an arbitrary attribute with a quote 1`] = `
|
exports[`simple templates, mostly static div with an arbitrary attribute with a quote 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div abc=\\"a'bc\\">word</div>\`);
|
let block1 = createBlock(\`<div abc=\\"a'bc\\">word</div>\`);
|
||||||
|
|
||||||
@@ -66,9 +66,9 @@ exports[`simple templates, mostly static div with an arbitrary attribute with a
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`simple templates, mostly static div with an empty class attribute 1`] = `
|
exports[`simple templates, mostly static div with an empty class attribute 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div>word</div>\`);
|
let block1 = createBlock(\`<div>word</div>\`);
|
||||||
|
|
||||||
@@ -79,9 +79,9 @@ exports[`simple templates, mostly static div with an empty class attribute 1`] =
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`simple templates, mostly static div with content 1`] = `
|
exports[`simple templates, mostly static div with content 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div>foo</div>\`);
|
let block1 = createBlock(\`<div>foo</div>\`);
|
||||||
|
|
||||||
@@ -92,9 +92,9 @@ exports[`simple templates, mostly static div with content 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`simple templates, mostly static dom node with t-esc 1`] = `
|
exports[`simple templates, mostly static dom node with t-esc 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
||||||
|
|
||||||
@@ -106,9 +106,9 @@ exports[`simple templates, mostly static dom node with t-esc 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`simple templates, mostly static dom node with t-esc 2`] = `
|
exports[`simple templates, mostly static dom node with t-esc 2`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
||||||
|
|
||||||
@@ -120,9 +120,9 @@ exports[`simple templates, mostly static dom node with t-esc 2`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`simple templates, mostly static dynamic text value 1`] = `
|
exports[`simple templates, mostly static dynamic text value 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
return text(ctx['text']);
|
return text(ctx['text']);
|
||||||
@@ -131,9 +131,9 @@ exports[`simple templates, mostly static dynamic text value 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`simple templates, mostly static empty div 1`] = `
|
exports[`simple templates, mostly static empty div 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div/>\`);
|
let block1 = createBlock(\`<div/>\`);
|
||||||
|
|
||||||
@@ -144,9 +144,9 @@ exports[`simple templates, mostly static empty div 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`simple templates, mostly static empty string 1`] = `
|
exports[`simple templates, mostly static empty string 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
return text(\`\`);
|
return text(\`\`);
|
||||||
@@ -155,9 +155,9 @@ exports[`simple templates, mostly static empty string 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`simple templates, mostly static empty string in a template set 1`] = `
|
exports[`simple templates, mostly static empty string in a template set 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
return text(\`\`);
|
return text(\`\`);
|
||||||
@@ -166,9 +166,9 @@ exports[`simple templates, mostly static empty string in a template set 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`simple templates, mostly static inline template string in t-esc 1`] = `
|
exports[`simple templates, mostly static inline template string in t-esc 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
return text(\`text\`);
|
return text(\`text\`);
|
||||||
@@ -177,9 +177,9 @@ exports[`simple templates, mostly static inline template string in t-esc 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`simple templates, mostly static inline template string with content in t-esc 1`] = `
|
exports[`simple templates, mostly static inline template string with content in t-esc 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { isBoundary, withDefault, setContextValue } = helpers;
|
let { isBoundary, withDefault, setContextValue } = helpers;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
@@ -192,9 +192,9 @@ exports[`simple templates, mostly static inline template string with content in
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`simple templates, mostly static inline template string with variable in context 1`] = `
|
exports[`simple templates, mostly static inline template string with variable in context 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
return text(\`text \${ctx['v']}\`);
|
return text(\`text \${ctx['v']}\`);
|
||||||
@@ -203,25 +203,25 @@ exports[`simple templates, mostly static inline template string with variable in
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`simple templates, mostly static multiple root nodes 1`] = `
|
exports[`simple templates, mostly static multiple root nodes 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block2 = createBlock(\`<div>foo</div>\`);
|
let block2 = createBlock(\`<div>foo</div>\`);
|
||||||
let block3 = createBlock(\`<span>hey</span>\`);
|
let block3 = createBlock(\`<span>hey</span>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let b2 = block2();
|
const b2 = block2();
|
||||||
let b3 = block3();
|
const b3 = block3();
|
||||||
return multi([b2, b3]);
|
return multi([b2, b3]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`simple templates, mostly static simple string 1`] = `
|
exports[`simple templates, mostly static simple string 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
return text(\`hello vdom\`);
|
return text(\`hello vdom\`);
|
||||||
@@ -230,9 +230,9 @@ exports[`simple templates, mostly static simple string 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`simple templates, mostly static simple string in t tag 1`] = `
|
exports[`simple templates, mostly static simple string in t tag 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
return text(\`hello vdom\`);
|
return text(\`hello vdom\`);
|
||||||
@@ -241,35 +241,35 @@ exports[`simple templates, mostly static simple string in t tag 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`simple templates, mostly static static text and dynamic text (no t tag) 1`] = `
|
exports[`simple templates, mostly static static text and dynamic text (no t tag) 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let b2 = text(\`hello \`);
|
const b2 = text(\`hello \`);
|
||||||
let b3 = text(ctx['text']);
|
const b3 = text(ctx['text']);
|
||||||
return multi([b2, b3]);
|
return multi([b2, b3]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`simple templates, mostly static static text and dynamic text 1`] = `
|
exports[`simple templates, mostly static static text and dynamic text 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let b2 = text(\`hello \`);
|
const b2 = text(\`hello \`);
|
||||||
let b3 = text(ctx['text']);
|
const b3 = text(ctx['text']);
|
||||||
return multi([b2, b3]);
|
return multi([b2, b3]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`simple templates, mostly static t-esc in dom node 1`] = `
|
exports[`simple templates, mostly static t-esc in dom node 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
||||||
|
|
||||||
@@ -281,9 +281,9 @@ exports[`simple templates, mostly static t-esc in dom node 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`simple templates, mostly static t-esc in dom node, variations 1`] = `
|
exports[`simple templates, mostly static t-esc in dom node, variations 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div>hello <block-text-0/></div>\`);
|
let block1 = createBlock(\`<div>hello <block-text-0/></div>\`);
|
||||||
|
|
||||||
@@ -295,9 +295,9 @@ exports[`simple templates, mostly static t-esc in dom node, variations 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`simple templates, mostly static t-esc in dom node, variations 2`] = `
|
exports[`simple templates, mostly static t-esc in dom node, variations 2`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div>hello <block-text-0/> world</div>\`);
|
let block1 = createBlock(\`<div>hello <block-text-0/> world</div>\`);
|
||||||
|
|
||||||
@@ -309,9 +309,9 @@ exports[`simple templates, mostly static t-esc in dom node, variations 2`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`simple templates, mostly static template with multiple t tag with multiple content 1`] = `
|
exports[`simple templates, mostly static template with multiple t tag with multiple content 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/><block-text-1/>Loading<block-text-2/></div>\`);
|
let block1 = createBlock(\`<div><block-text-0/><block-text-1/>Loading<block-text-2/></div>\`);
|
||||||
|
|
||||||
@@ -325,9 +325,9 @@ exports[`simple templates, mostly static template with multiple t tag with multi
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`simple templates, mostly static template with t tag with multiple content 1`] = `
|
exports[`simple templates, mostly static template with t tag with multiple content 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div>Loading<block-child-0/></div>\`);
|
let block1 = createBlock(\`<div>Loading<block-child-0/></div>\`);
|
||||||
|
|
||||||
@@ -342,35 +342,35 @@ exports[`simple templates, mostly static template with t tag with multiple conte
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`simple templates, mostly static two t-escs next to each other 1`] = `
|
exports[`simple templates, mostly static two t-escs next to each other 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let b2 = text(ctx['text1']);
|
const b2 = text(ctx['text1']);
|
||||||
let b3 = text(ctx['text2']);
|
const b3 = text(ctx['text2']);
|
||||||
return multi([b2, b3]);
|
return multi([b2, b3]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`simple templates, mostly static two t-escs next to each other 2`] = `
|
exports[`simple templates, mostly static two t-escs next to each other 2`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let b2 = text(ctx['text1']);
|
const b2 = text(ctx['text1']);
|
||||||
let b3 = text(ctx['text2']);
|
const b3 = text(ctx['text2']);
|
||||||
return multi([b2, b3]);
|
return multi([b2, b3]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`simple templates, mostly static two t-escs next to each other, in a div 1`] = `
|
exports[`simple templates, mostly static two t-escs next to each other, in a div 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/><block-text-1/></div>\`);
|
let block1 = createBlock(\`<div><block-text-0/><block-text-1/></div>\`);
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`properly support svg add proper namespace to g tags 1`] = `
|
exports[`properly support svg add proper namespace to g tags 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
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>\`);
|
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>\`);
|
||||||
|
|
||||||
@@ -14,9 +14,9 @@ exports[`properly support svg add proper namespace to g tags 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`properly support svg add proper namespace to svg 1`] = `
|
exports[`properly support svg add proper namespace to svg 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
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>\`);
|
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>\`);
|
||||||
|
|
||||||
@@ -27,9 +27,9 @@ exports[`properly support svg add proper namespace to svg 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`properly support svg namespace to g tags not added if already in svg namespace 1`] = `
|
exports[`properly support svg namespace to g tags not added if already in svg namespace 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<svg block-ns=\\"http://www.w3.org/2000/svg\\"><g/></svg>\`);
|
let block1 = createBlock(\`<svg block-ns=\\"http://www.w3.org/2000/svg\\"><g/></svg>\`);
|
||||||
|
|
||||||
@@ -40,9 +40,9 @@ exports[`properly support svg namespace to g tags not added if already in svg na
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`properly support svg namespace to svg tags added even if already in svg namespace 1`] = `
|
exports[`properly support svg namespace to svg tags added even if already in svg namespace 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<svg block-ns=\\"http://www.w3.org/2000/svg\\"><svg/></svg>\`);
|
let block1 = createBlock(\`<svg block-ns=\\"http://www.w3.org/2000/svg\\"><svg/></svg>\`);
|
||||||
|
|
||||||
@@ -52,10 +52,73 @@ exports[`properly support svg namespace to svg tags added even if already in svg
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`properly support svg svg namespace added to sub-blocks 1`] = `
|
exports[`properly support svg svg creates new block if it is within html -- 2 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
let block2 = createBlock(\`<svg block-ns=\\"http://www.w3.org/2000/svg\\"><polygon fill=\\"#000000\\" points=\\"0 0 4 4 8 0\\" transform=\\"translate(5 7)\\"/><block-child-0/></svg>\`);
|
||||||
|
let block3 = createBlock(\`<path block-ns=\\"http://www.w3.org/2000/svg\\"/>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
let b3;
|
||||||
|
if (ctx['hasPath']) {
|
||||||
|
b3 = block3();
|
||||||
|
}
|
||||||
|
const b2 = block2([], [b3]);
|
||||||
|
return block1([], [b2]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`properly support svg svg creates new block if it is within html 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
let block2 = createBlock(\`<svg block-ns=\\"http://www.w3.org/2000/svg\\"><polygon fill=\\"#000000\\" points=\\"0 0 4 4 8 0\\" transform=\\"translate(5 7)\\"/></svg>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
const b2 = block2();
|
||||||
|
return block1([], [b2]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`properly support svg svg namespace added to sub templates if root tag is path 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
const callTemplate_1 = app.getTemplate(\`path\`);
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<svg block-ns=\\"http://www.w3.org/2000/svg\\"><block-child-0/></svg>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
const b2 = callTemplate_1.call(this, ctx, node, key + \`__1\`);
|
||||||
|
return block1([], [b2]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`properly support svg svg namespace added to sub templates if root tag is path 2`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<path block-ns=\\"http://www.w3.org/2000/svg\\"/>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
return block1();
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`properly support svg svg namespace added to sub-blocks 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<svg block-ns=\\"http://www.w3.org/2000/svg\\"><block-child-0/></svg>\`);
|
let block1 = createBlock(\`<svg block-ns=\\"http://www.w3.org/2000/svg\\"><block-child-0/></svg>\`);
|
||||||
let block2 = createBlock(\`<path block-ns=\\"http://www.w3.org/2000/svg\\"/>\`);
|
let block2 = createBlock(\`<path block-ns=\\"http://www.w3.org/2000/svg\\"/>\`);
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,9 +1,9 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`debugging t-debug 1`] = `
|
exports[`debugging t-debug 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
let block2 = createBlock(\`<span>hey</span>\`);
|
let block2 = createBlock(\`<span>hey</span>\`);
|
||||||
@@ -21,9 +21,9 @@ exports[`debugging t-debug 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`debugging t-debug on sub template 1`] = `
|
exports[`debugging t-debug on sub template 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<p>coucou</p>\`);
|
let block1 = createBlock(\`<p>coucou</p>\`);
|
||||||
|
|
||||||
@@ -35,25 +35,24 @@ exports[`debugging t-debug on sub template 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`debugging t-debug on sub template 2`] = `
|
exports[`debugging t-debug on sub template 2`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { getTemplate } = helpers;
|
const callTemplate_1 = app.getTemplate(\`sub\`);
|
||||||
const callTemplate_1 = getTemplate(\`sub\`);
|
|
||||||
|
|
||||||
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 = \\"\\") {
|
||||||
let b2 = callTemplate_1.call(this, ctx, node, key + \`__1\`);
|
const b2 = callTemplate_1.call(this, ctx, node, key + \`__1\`);
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`debugging t-log 1`] = `
|
exports[`debugging t-log 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { isBoundary, withDefault, setContextValue } = helpers;
|
let { isBoundary, withDefault, setContextValue } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div/>\`);
|
let block1 = createBlock(\`<div/>\`);
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`t-esc div with falsy values 1`] = `
|
exports[`t-esc div with falsy values 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><p><block-text-0/></p><p><block-text-1/></p><p><block-text-2/></p><p><block-text-3/></p><p><block-text-4/></p></div>\`);
|
let block1 = createBlock(\`<div><p><block-text-0/></p><p><block-text-1/></p><p><block-text-2/></p><p><block-text-3/></p><p><block-text-4/></p></div>\`);
|
||||||
|
|
||||||
@@ -19,9 +19,9 @@ exports[`t-esc div with falsy values 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-esc escaping 1`] = `
|
exports[`t-esc escaping 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
||||||
|
|
||||||
@@ -33,9 +33,9 @@ exports[`t-esc escaping 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-esc escaping on a node 1`] = `
|
exports[`t-esc escaping on a node 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
||||||
|
|
||||||
@@ -47,9 +47,9 @@ exports[`t-esc escaping on a node 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-esc escaping on a node with a body 1`] = `
|
exports[`t-esc escaping on a node with a body 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { withDefault } = helpers;
|
let { withDefault } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
||||||
@@ -62,9 +62,9 @@ exports[`t-esc escaping on a node with a body 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-esc escaping on a node with a body, as a default 1`] = `
|
exports[`t-esc escaping on a node with a body, as a default 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { withDefault } = helpers;
|
let { withDefault } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
||||||
@@ -77,29 +77,29 @@ exports[`t-esc escaping on a node with a body, as a default 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-esc falsy values in text nodes 1`] = `
|
exports[`t-esc falsy values in text nodes 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let b2 = text(ctx['v1']);
|
const b2 = text(ctx['v1']);
|
||||||
let b3 = text(\`:\`);
|
const b3 = text(\`:\`);
|
||||||
let b4 = text(ctx['v2']);
|
const b4 = text(ctx['v2']);
|
||||||
let b5 = text(\`:\`);
|
const b5 = text(\`:\`);
|
||||||
let b6 = text(ctx['v3']);
|
const b6 = text(ctx['v3']);
|
||||||
let b7 = text(\`:\`);
|
const b7 = text(\`:\`);
|
||||||
let b8 = text(ctx['v4']);
|
const b8 = text(ctx['v4']);
|
||||||
let b9 = text(\`:\`);
|
const b9 = text(\`:\`);
|
||||||
let b10 = text(ctx['v5']);
|
const b10 = text(ctx['v5']);
|
||||||
return multi([b2, b3, b4, b5, b6, b7, b8, b9, b10]);
|
return multi([b2, b3, b4, b5, b6, b7, b8, b9, b10]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-esc literal 1`] = `
|
exports[`t-esc literal 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
||||||
|
|
||||||
@@ -111,9 +111,9 @@ exports[`t-esc literal 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-esc t-esc is escaped 1`] = `
|
exports[`t-esc t-esc is escaped 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { isBoundary, withDefault, LazyValue } = helpers;
|
let { isBoundary, withDefault, LazyValue } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
||||||
@@ -126,7 +126,32 @@ exports[`t-esc t-esc is escaped 1`] = `
|
|||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
ctx = Object.create(ctx);
|
ctx = Object.create(ctx);
|
||||||
ctx[isBoundary] = 1
|
ctx[isBoundary] = 1
|
||||||
ctx[\`var\`] = new LazyValue(value1, ctx, node);
|
ctx[\`var\`] = new LazyValue(value1, ctx, this, node, key);
|
||||||
|
let txt1 = ctx['var'];
|
||||||
|
return block1([txt1]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`t-esc t-esc with the 0 number 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
return text(ctx['var']);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`t-esc t-esc with the 0 number, in a p 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<p><block-text-0/></p>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let txt1 = ctx['var'];
|
let txt1 = ctx['var'];
|
||||||
return block1([txt1]);
|
return block1([txt1]);
|
||||||
}
|
}
|
||||||
@@ -134,9 +159,9 @@ exports[`t-esc t-esc is escaped 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-esc t-esc work with spread operator 1`] = `
|
exports[`t-esc t-esc work with spread operator 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
||||||
|
|
||||||
@@ -148,11 +173,11 @@ exports[`t-esc t-esc work with spread operator 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-esc t-esc=0 is escaped 1`] = `
|
exports[`t-esc t-esc=0 is escaped 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { isBoundary, zero, getTemplate } = helpers;
|
let { isBoundary, zero } = helpers;
|
||||||
const callTemplate_1 = getTemplate(\`sub\`);
|
const callTemplate_1 = app.getTemplate(\`sub\`);
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
let block2 = createBlock(\`<p>escaped</p>\`);
|
let block2 = createBlock(\`<p>escaped</p>\`);
|
||||||
@@ -160,18 +185,18 @@ exports[`t-esc t-esc=0 is escaped 1`] = `
|
|||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
ctx = Object.create(ctx);
|
ctx = Object.create(ctx);
|
||||||
ctx[isBoundary] = 1;
|
ctx[isBoundary] = 1;
|
||||||
let b2 = block2();
|
const b2 = block2();
|
||||||
ctx[zero] = b2;
|
ctx[zero] = b2;
|
||||||
let b3 = callTemplate_1.call(this, ctx, node, key + \`__1\`);
|
const b3 = callTemplate_1.call(this, ctx, node, key + \`__1\`);
|
||||||
return block1([], [b3]);
|
return block1([], [b3]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-esc t-esc=0 is escaped 2`] = `
|
exports[`t-esc t-esc=0 is escaped 2`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { zero } = helpers;
|
let { zero } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
||||||
@@ -183,10 +208,21 @@ exports[`t-esc t-esc=0 is escaped 2`] = `
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-esc variable 1`] = `
|
exports[`t-esc top level t-esc with undefined 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
return text(ctx['var']);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`t-esc variable 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
let block1 = createBlock(\`<span><block-text-0/></span>\`);
|
||||||
|
|
||||||
|
|||||||
@@ -1,31 +1,31 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`t-foreach does not pollute the rendering context 1`] = `
|
exports[`t-foreach does not pollute the rendering context 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { prepareList, withKey } = helpers;
|
let { prepareList, withKey } = 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);
|
||||||
const [k_block2, v_block2, l_block2, c_block2] = prepareList([1]);
|
const [k_block2, v_block2, l_block2, c_block2] = prepareList([1]);;
|
||||||
for (let i1 = 0; i1 < l_block2; i1++) {
|
for (let i1 = 0; i1 < l_block2; i1++) {
|
||||||
ctx[\`item\`] = v_block2[i1];
|
ctx[\`item\`] = v_block2[i1];
|
||||||
let key1 = ctx['item'];
|
const key1 = ctx['item'];
|
||||||
c_block2[i1] = withKey(text(ctx['item']), key1);
|
c_block2[i1] = withKey(text(ctx['item']), key1);
|
||||||
}
|
}
|
||||||
let b2 = list(c_block2);
|
const b2 = list(c_block2);
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-foreach iterate on items (on a element node) 1`] = `
|
exports[`t-foreach iterate on items (on a element node) 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { prepareList, withKey } = helpers;
|
let { prepareList, withKey } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
@@ -33,98 +33,98 @@ exports[`t-foreach iterate on items (on a element node) 1`] = `
|
|||||||
|
|
||||||
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([1,2]);
|
const [k_block2, v_block2, l_block2, c_block2] = prepareList([1,2]);;
|
||||||
for (let i1 = 0; i1 < l_block2; i1++) {
|
for (let i1 = 0; i1 < l_block2; i1++) {
|
||||||
ctx[\`item\`] = v_block2[i1];
|
ctx[\`item\`] = v_block2[i1];
|
||||||
let key1 = ctx['item'];
|
const key1 = ctx['item'];
|
||||||
let txt1 = ctx['item'];
|
let txt1 = ctx['item'];
|
||||||
c_block2[i1] = withKey(block3([txt1]), key1);
|
c_block2[i1] = withKey(block3([txt1]), key1);
|
||||||
}
|
}
|
||||||
let b2 = list(c_block2);
|
const b2 = list(c_block2);
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-foreach iterate on items 1`] = `
|
exports[`t-foreach iterate on items 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { prepareList, withKey } = helpers;
|
let { prepareList, withKey } = 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);
|
||||||
const [k_block2, v_block2, l_block2, c_block2] = prepareList([3,2,1]);
|
const [k_block2, v_block2, l_block2, c_block2] = prepareList([3,2,1]);;
|
||||||
for (let i1 = 0; i1 < l_block2; i1++) {
|
for (let i1 = 0; i1 < l_block2; i1++) {
|
||||||
ctx[\`item\`] = v_block2[i1];
|
ctx[\`item\`] = v_block2[i1];
|
||||||
ctx[\`item_index\`] = i1;
|
ctx[\`item_index\`] = i1;
|
||||||
ctx[\`item_value\`] = k_block2[i1];
|
ctx[\`item_value\`] = k_block2[i1];
|
||||||
let key1 = ctx['item'];
|
const key1 = ctx['item'];
|
||||||
let b4 = text(\` [\`);
|
const b4 = text(\` [\`);
|
||||||
let b5 = text(ctx['item_index']);
|
const b5 = text(ctx['item_index']);
|
||||||
let b6 = text(\`: \`);
|
const b6 = text(\`: \`);
|
||||||
let b7 = text(ctx['item']);
|
const b7 = text(ctx['item']);
|
||||||
let b8 = text(\` \`);
|
const b8 = text(\` \`);
|
||||||
let b9 = text(ctx['item_value']);
|
const b9 = text(ctx['item_value']);
|
||||||
let b10 = text(\`] \`);
|
const b10 = text(\`] \`);
|
||||||
c_block2[i1] = withKey(multi([b4, b5, b6, b7, b8, b9, b10]), key1);
|
c_block2[i1] = withKey(multi([b4, b5, b6, b7, b8, b9, b10]), key1);
|
||||||
}
|
}
|
||||||
let b2 = list(c_block2);
|
const b2 = list(c_block2);
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-foreach iterate, dict param 1`] = `
|
exports[`t-foreach iterate, dict param 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { prepareList, withKey } = helpers;
|
let { prepareList, withKey } = 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);
|
||||||
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['value']);
|
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['value']);;
|
||||||
for (let i1 = 0; i1 < l_block2; i1++) {
|
for (let i1 = 0; i1 < l_block2; i1++) {
|
||||||
ctx[\`item\`] = v_block2[i1];
|
ctx[\`item\`] = v_block2[i1];
|
||||||
ctx[\`item_index\`] = i1;
|
ctx[\`item_index\`] = i1;
|
||||||
ctx[\`item_value\`] = k_block2[i1];
|
ctx[\`item_value\`] = k_block2[i1];
|
||||||
let key1 = ctx['item_index'];
|
const key1 = ctx['item_index'];
|
||||||
let b4 = text(\` [\`);
|
const b4 = text(\` [\`);
|
||||||
let b5 = text(ctx['item_index']);
|
const b5 = text(ctx['item_index']);
|
||||||
let b6 = text(\`: \`);
|
const b6 = text(\`: \`);
|
||||||
let b7 = text(ctx['item']);
|
const b7 = text(ctx['item']);
|
||||||
let b8 = text(\` \`);
|
const b8 = text(\` \`);
|
||||||
let b9 = text(ctx['item_value']);
|
const b9 = text(ctx['item_value']);
|
||||||
let b10 = text(\`] \`);
|
const b10 = text(\`] \`);
|
||||||
c_block2[i1] = withKey(multi([b4, b5, b6, b7, b8, b9, b10]), key1);
|
c_block2[i1] = withKey(multi([b4, b5, b6, b7, b8, b9, b10]), key1);
|
||||||
}
|
}
|
||||||
let b2 = list(c_block2);
|
const b2 = list(c_block2);
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-foreach iterate, position 1`] = `
|
exports[`t-foreach iterate, position 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { prepareList, withKey } = helpers;
|
let { prepareList, withKey } = 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);
|
||||||
const [k_block2, v_block2, l_block2, c_block2] = prepareList(Array(5));
|
const [k_block2, v_block2, l_block2, c_block2] = prepareList(Array(5));;
|
||||||
for (let i1 = 0; i1 < l_block2; i1++) {
|
for (let i1 = 0; i1 < l_block2; i1++) {
|
||||||
ctx[\`elem\`] = v_block2[i1];
|
ctx[\`elem\`] = v_block2[i1];
|
||||||
ctx[\`elem_first\`] = i1 === 0;
|
ctx[\`elem_first\`] = i1 === 0;
|
||||||
ctx[\`elem_last\`] = i1 === v_block2.length - 1;
|
ctx[\`elem_last\`] = i1 === v_block2.length - 1;
|
||||||
ctx[\`elem_index\`] = i1;
|
ctx[\`elem_index\`] = i1;
|
||||||
let key1 = ctx['elem'];
|
const key1 = ctx['elem'];
|
||||||
let b4,b5,b6,b7,b8,b9;
|
let b4,b5,b6,b7,b8,b9;
|
||||||
b4 = text(\` -\`);
|
b4 = text(\` -\`);
|
||||||
if (ctx['elem_first']) {
|
if (ctx['elem_first']) {
|
||||||
@@ -138,46 +138,46 @@ exports[`t-foreach iterate, position 1`] = `
|
|||||||
b9 = text(\`) \`);
|
b9 = text(\`) \`);
|
||||||
c_block2[i1] = withKey(multi([b4, b5, b6, b7, b8, b9]), key1);
|
c_block2[i1] = withKey(multi([b4, b5, b6, b7, b8, b9]), key1);
|
||||||
}
|
}
|
||||||
let b2 = list(c_block2);
|
const b2 = list(c_block2);
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-foreach simple iteration (in a node) 1`] = `
|
exports[`t-foreach simple iteration (in a node) 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { prepareList, withKey } = helpers;
|
let { prepareList, withKey } = 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);
|
||||||
const [k_block2, v_block2, l_block2, c_block2] = prepareList([3,2,1]);
|
const [k_block2, v_block2, l_block2, c_block2] = prepareList([3,2,1]);;
|
||||||
for (let i1 = 0; i1 < l_block2; i1++) {
|
for (let i1 = 0; i1 < l_block2; i1++) {
|
||||||
ctx[\`item\`] = v_block2[i1];
|
ctx[\`item\`] = v_block2[i1];
|
||||||
let key1 = ctx['item'];
|
const key1 = ctx['item'];
|
||||||
c_block2[i1] = withKey(text(ctx['item']), key1);
|
c_block2[i1] = withKey(text(ctx['item']), key1);
|
||||||
}
|
}
|
||||||
let b2 = list(c_block2);
|
const b2 = list(c_block2);
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-foreach simple iteration 1`] = `
|
exports[`t-foreach simple iteration 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { prepareList, withKey } = helpers;
|
let { prepareList, withKey } = 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([3,2,1]);
|
const [k_block1, v_block1, l_block1, c_block1] = prepareList([3,2,1]);;
|
||||||
for (let i1 = 0; i1 < l_block1; i1++) {
|
for (let i1 = 0; i1 < l_block1; i1++) {
|
||||||
ctx[\`item\`] = v_block1[i1];
|
ctx[\`item\`] = v_block1[i1];
|
||||||
let key1 = ctx['item'];
|
const key1 = ctx['item'];
|
||||||
c_block1[i1] = withKey(text(ctx['item']), key1);
|
c_block1[i1] = withKey(text(ctx['item']), key1);
|
||||||
}
|
}
|
||||||
return list(c_block1);
|
return list(c_block1);
|
||||||
@@ -186,9 +186,9 @@ exports[`t-foreach simple iteration 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-foreach simple iteration with two nodes inside 1`] = `
|
exports[`t-foreach simple iteration with two nodes inside 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { prepareList, withKey } = helpers;
|
let { prepareList, withKey } = helpers;
|
||||||
|
|
||||||
let block3 = createBlock(\`<span>a<block-text-0/></span>\`);
|
let block3 = createBlock(\`<span>a<block-text-0/></span>\`);
|
||||||
@@ -196,14 +196,14 @@ exports[`t-foreach simple iteration with two nodes inside 1`] = `
|
|||||||
|
|
||||||
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([3,2,1]);
|
const [k_block1, v_block1, l_block1, c_block1] = prepareList([3,2,1]);;
|
||||||
for (let i1 = 0; i1 < l_block1; i1++) {
|
for (let i1 = 0; i1 < l_block1; i1++) {
|
||||||
ctx[\`item\`] = v_block1[i1];
|
ctx[\`item\`] = v_block1[i1];
|
||||||
let key1 = ctx['item'];
|
const key1 = ctx['item'];
|
||||||
let txt1 = ctx['item'];
|
let txt1 = ctx['item'];
|
||||||
let b3 = block3([txt1]);
|
const b3 = block3([txt1]);
|
||||||
let txt2 = ctx['item'];
|
let txt2 = ctx['item'];
|
||||||
let b4 = block4([txt2]);
|
const b4 = block4([txt2]);
|
||||||
c_block1[i1] = withKey(multi([b3, b4]), key1);
|
c_block1[i1] = withKey(multi([b3, b4]), key1);
|
||||||
}
|
}
|
||||||
return list(c_block1);
|
return list(c_block1);
|
||||||
@@ -212,11 +212,11 @@ exports[`t-foreach simple iteration with two nodes inside 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-foreach t-call with body in t-foreach in t-foreach 1`] = `
|
exports[`t-foreach t-call with body in t-foreach in t-foreach 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { prepareList, isBoundary, withDefault, setContextValue, getTemplate, withKey } = helpers;
|
let { prepareList, isBoundary, withDefault, setContextValue, withKey } = helpers;
|
||||||
const callTemplate_1 = getTemplate(\`sub\`);
|
const callTemplate_1 = app.getTemplate(\`sub\`);
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><span>[<block-text-0/>][<block-text-1/>][<block-text-2/>]</span></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/><span>[<block-text-0/>][<block-text-1/>][<block-text-2/>]</span></div>\`);
|
||||||
let block6 = createBlock(\`<span><block-text-0/></span>\`);
|
let block6 = createBlock(\`<span><block-text-0/></span>\`);
|
||||||
@@ -225,23 +225,23 @@ exports[`t-foreach t-call with body in t-foreach in t-foreach 1`] = `
|
|||||||
ctx = Object.create(ctx);
|
ctx = Object.create(ctx);
|
||||||
ctx[isBoundary] = 1
|
ctx[isBoundary] = 1
|
||||||
ctx = Object.create(ctx);
|
ctx = Object.create(ctx);
|
||||||
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['numbers']);
|
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['numbers']);;
|
||||||
for (let i1 = 0; i1 < l_block2; i1++) {
|
for (let i1 = 0; i1 < l_block2; i1++) {
|
||||||
ctx[\`a\`] = v_block2[i1];
|
ctx[\`a\`] = v_block2[i1];
|
||||||
ctx[\`a_first\`] = i1 === 0;
|
ctx[\`a_first\`] = i1 === 0;
|
||||||
ctx[\`a_last\`] = i1 === v_block2.length - 1;
|
ctx[\`a_last\`] = i1 === v_block2.length - 1;
|
||||||
ctx[\`a_index\`] = i1;
|
ctx[\`a_index\`] = i1;
|
||||||
ctx[\`a_value\`] = k_block2[i1];
|
ctx[\`a_value\`] = k_block2[i1];
|
||||||
let key1 = ctx['a'];
|
const key1 = ctx['a'];
|
||||||
ctx = Object.create(ctx);
|
ctx = Object.create(ctx);
|
||||||
const [k_block4, v_block4, l_block4, c_block4] = prepareList(ctx['letters']);
|
const [k_block4, v_block4, l_block4, c_block4] = prepareList(ctx['letters']);;
|
||||||
for (let i2 = 0; i2 < l_block4; i2++) {
|
for (let i2 = 0; i2 < l_block4; i2++) {
|
||||||
ctx[\`b\`] = v_block4[i2];
|
ctx[\`b\`] = v_block4[i2];
|
||||||
ctx[\`b_first\`] = i2 === 0;
|
ctx[\`b_first\`] = i2 === 0;
|
||||||
ctx[\`b_last\`] = i2 === v_block4.length - 1;
|
ctx[\`b_last\`] = i2 === v_block4.length - 1;
|
||||||
ctx[\`b_index\`] = i2;
|
ctx[\`b_index\`] = i2;
|
||||||
ctx[\`b_value\`] = k_block4[i2];
|
ctx[\`b_value\`] = k_block4[i2];
|
||||||
let key2 = ctx['b'];
|
const key2 = ctx['b'];
|
||||||
ctx = Object.create(ctx);
|
ctx = Object.create(ctx);
|
||||||
ctx[isBoundary] = 1;
|
ctx[isBoundary] = 1;
|
||||||
setContextValue(ctx, \\"c\\", 'x'+'_'+ctx['a']+'_'+ctx['b']);
|
setContextValue(ctx, \\"c\\", 'x'+'_'+ctx['a']+'_'+ctx['b']);
|
||||||
@@ -249,13 +249,13 @@ exports[`t-foreach t-call with body in t-foreach in t-foreach 1`] = `
|
|||||||
ctx = ctx.__proto__;
|
ctx = ctx.__proto__;
|
||||||
}
|
}
|
||||||
ctx = ctx.__proto__;
|
ctx = ctx.__proto__;
|
||||||
let b4 = list(c_block4);
|
const b4 = list(c_block4);
|
||||||
let txt1 = ctx['c'];
|
let txt1 = ctx['c'];
|
||||||
let b6 = block6([txt1]);
|
const b6 = block6([txt1]);
|
||||||
c_block2[i1] = withKey(multi([b4, b6]), key1);
|
c_block2[i1] = withKey(multi([b4, b6]), key1);
|
||||||
}
|
}
|
||||||
ctx = ctx.__proto__;
|
ctx = ctx.__proto__;
|
||||||
let b2 = list(c_block2);
|
const b2 = list(c_block2);
|
||||||
let txt2 = ctx['a'];
|
let txt2 = ctx['a'];
|
||||||
let txt3 = ctx['b'];
|
let txt3 = ctx['b'];
|
||||||
let txt4 = ctx['c'];
|
let txt4 = ctx['c'];
|
||||||
@@ -265,62 +265,62 @@ exports[`t-foreach t-call with body in t-foreach in t-foreach 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-foreach t-call with body in t-foreach in t-foreach 2`] = `
|
exports[`t-foreach t-call with body in t-foreach in t-foreach 2`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let b2 = text(\` [\`);
|
const b2 = text(\` [\`);
|
||||||
let b3 = text(ctx['a']);
|
const b3 = text(ctx['a']);
|
||||||
let b4 = text(\`] [\`);
|
const b4 = text(\`] [\`);
|
||||||
let b5 = text(ctx['b']);
|
const b5 = text(ctx['b']);
|
||||||
let b6 = text(\`] [\`);
|
const b6 = text(\`] [\`);
|
||||||
let b7 = text(ctx['c']);
|
const b7 = text(ctx['c']);
|
||||||
let b8 = text(\`] \`);
|
const b8 = text(\`] \`);
|
||||||
return multi([b2, b3, b4, b5, b6, b7, b8]);
|
return multi([b2, b3, b4, b5, b6, b7, b8]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-foreach t-call without body in t-foreach in t-foreach 1`] = `
|
exports[`t-foreach t-call without body in t-foreach in t-foreach 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { prepareList, getTemplate, withKey } = helpers;
|
let { prepareList, withKey } = helpers;
|
||||||
const callTemplate_1 = getTemplate(\`sub\`);
|
const callTemplate_1 = app.getTemplate(\`sub\`);
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><span>[<block-text-0/>][<block-text-1/>][<block-text-2/>]</span></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/><span>[<block-text-0/>][<block-text-1/>][<block-text-2/>]</span></div>\`);
|
||||||
let block6 = createBlock(\`<span><block-text-0/></span>\`);
|
let block6 = createBlock(\`<span><block-text-0/></span>\`);
|
||||||
|
|
||||||
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(ctx['numbers']);
|
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['numbers']);;
|
||||||
for (let i1 = 0; i1 < l_block2; i1++) {
|
for (let i1 = 0; i1 < l_block2; i1++) {
|
||||||
ctx[\`a\`] = v_block2[i1];
|
ctx[\`a\`] = v_block2[i1];
|
||||||
ctx[\`a_first\`] = i1 === 0;
|
ctx[\`a_first\`] = i1 === 0;
|
||||||
ctx[\`a_last\`] = i1 === v_block2.length - 1;
|
ctx[\`a_last\`] = i1 === v_block2.length - 1;
|
||||||
ctx[\`a_index\`] = i1;
|
ctx[\`a_index\`] = i1;
|
||||||
ctx[\`a_value\`] = k_block2[i1];
|
ctx[\`a_value\`] = k_block2[i1];
|
||||||
let key1 = ctx['a'];
|
const key1 = ctx['a'];
|
||||||
ctx = Object.create(ctx);
|
ctx = Object.create(ctx);
|
||||||
const [k_block4, v_block4, l_block4, c_block4] = prepareList(ctx['letters']);
|
const [k_block4, v_block4, l_block4, c_block4] = prepareList(ctx['letters']);;
|
||||||
for (let i2 = 0; i2 < l_block4; i2++) {
|
for (let i2 = 0; i2 < l_block4; i2++) {
|
||||||
ctx[\`b\`] = v_block4[i2];
|
ctx[\`b\`] = v_block4[i2];
|
||||||
ctx[\`b_first\`] = i2 === 0;
|
ctx[\`b_first\`] = i2 === 0;
|
||||||
ctx[\`b_last\`] = i2 === v_block4.length - 1;
|
ctx[\`b_last\`] = i2 === v_block4.length - 1;
|
||||||
ctx[\`b_index\`] = i2;
|
ctx[\`b_index\`] = i2;
|
||||||
ctx[\`b_value\`] = k_block4[i2];
|
ctx[\`b_value\`] = k_block4[i2];
|
||||||
let key2 = ctx['b'];
|
const key2 = ctx['b'];
|
||||||
c_block4[i2] = withKey(callTemplate_1.call(this, ctx, node, key + \`__1__\${key1}__\${key2}\`), key2);
|
c_block4[i2] = withKey(callTemplate_1.call(this, ctx, node, key + \`__1__\${key1}__\${key2}\`), key2);
|
||||||
}
|
}
|
||||||
ctx = ctx.__proto__;
|
ctx = ctx.__proto__;
|
||||||
let b4 = list(c_block4);
|
const b4 = list(c_block4);
|
||||||
let txt1 = ctx['c'];
|
let txt1 = ctx['c'];
|
||||||
let b6 = block6([txt1]);
|
const b6 = block6([txt1]);
|
||||||
c_block2[i1] = withKey(multi([b4, b6]), key1);
|
c_block2[i1] = withKey(multi([b4, b6]), key1);
|
||||||
}
|
}
|
||||||
ctx = ctx.__proto__;
|
ctx = ctx.__proto__;
|
||||||
let b2 = list(c_block2);
|
const b2 = list(c_block2);
|
||||||
let txt2 = ctx['a'];
|
let txt2 = ctx['a'];
|
||||||
let txt3 = ctx['b'];
|
let txt3 = ctx['b'];
|
||||||
let txt4 = ctx['c'];
|
let txt4 = ctx['c'];
|
||||||
@@ -330,75 +330,75 @@ exports[`t-foreach t-call without body in t-foreach in t-foreach 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-foreach t-call without body in t-foreach in t-foreach 2`] = `
|
exports[`t-foreach t-call without body in t-foreach in t-foreach 2`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { isBoundary, withDefault, setContextValue } = helpers;
|
let { isBoundary, withDefault, setContextValue } = helpers;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
ctx = Object.create(ctx);
|
ctx = Object.create(ctx);
|
||||||
ctx[isBoundary] = 1
|
ctx[isBoundary] = 1
|
||||||
setContextValue(ctx, \\"c\\", 'x'+'_'+ctx['a']+'_'+ctx['b']);
|
setContextValue(ctx, \\"c\\", 'x'+'_'+ctx['a']+'_'+ctx['b']);
|
||||||
let b2 = text(\` [\`);
|
const b2 = text(\` [\`);
|
||||||
let b3 = text(ctx['a']);
|
const b3 = text(ctx['a']);
|
||||||
let b4 = text(\`] [\`);
|
const b4 = text(\`] [\`);
|
||||||
let b5 = text(ctx['b']);
|
const b5 = text(ctx['b']);
|
||||||
let b6 = text(\`] [\`);
|
const b6 = text(\`] [\`);
|
||||||
let b7 = text(ctx['c']);
|
const b7 = text(ctx['c']);
|
||||||
let b8 = text(\`] \`);
|
const b8 = text(\`] \`);
|
||||||
return multi([b2, b3, b4, b5, b6, b7, b8]);
|
return multi([b2, b3, b4, b5, b6, b7, b8]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-foreach t-foreach in t-foreach 1`] = `
|
exports[`t-foreach t-foreach in t-foreach 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { prepareList, withKey } = helpers;
|
let { prepareList, withKey } = 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);
|
||||||
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['numbers']);
|
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['numbers']);;
|
||||||
for (let i1 = 0; i1 < l_block2; i1++) {
|
for (let i1 = 0; i1 < l_block2; i1++) {
|
||||||
ctx[\`number\`] = v_block2[i1];
|
ctx[\`number\`] = v_block2[i1];
|
||||||
let key1 = ctx['number'];
|
const key1 = ctx['number'];
|
||||||
ctx = Object.create(ctx);
|
ctx = Object.create(ctx);
|
||||||
const [k_block3, v_block3, l_block3, c_block3] = prepareList(ctx['letters']);
|
const [k_block3, v_block3, l_block3, c_block3] = prepareList(ctx['letters']);;
|
||||||
for (let i2 = 0; i2 < l_block3; i2++) {
|
for (let i2 = 0; i2 < l_block3; i2++) {
|
||||||
ctx[\`letter\`] = v_block3[i2];
|
ctx[\`letter\`] = v_block3[i2];
|
||||||
let key2 = ctx['letter'];
|
const key2 = ctx['letter'];
|
||||||
let b5 = text(\` [\`);
|
const b5 = text(\` [\`);
|
||||||
let b6 = text(ctx['number']);
|
const b6 = text(ctx['number']);
|
||||||
let b7 = text(ctx['letter']);
|
const b7 = text(ctx['letter']);
|
||||||
let b8 = text(\`] \`);
|
const b8 = text(\`] \`);
|
||||||
c_block3[i2] = withKey(multi([b5, b6, b7, b8]), key2);
|
c_block3[i2] = withKey(multi([b5, b6, b7, b8]), key2);
|
||||||
}
|
}
|
||||||
ctx = ctx.__proto__;
|
ctx = ctx.__proto__;
|
||||||
c_block2[i1] = withKey(list(c_block3), key1);
|
c_block2[i1] = withKey(list(c_block3), key1);
|
||||||
}
|
}
|
||||||
let b2 = list(c_block2);
|
const b2 = list(c_block2);
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-foreach t-foreach with t-if inside (no external node) 1`] = `
|
exports[`t-foreach t-foreach with t-if inside (no external node) 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { prepareList, withKey } = helpers;
|
let { prepareList, withKey } = helpers;
|
||||||
|
|
||||||
let block3 = createBlock(\`<span><block-text-0/></span>\`);
|
let block3 = createBlock(\`<span><block-text-0/></span>\`);
|
||||||
|
|
||||||
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['elems']);
|
const [k_block1, v_block1, l_block1, c_block1] = prepareList(ctx['elems']);;
|
||||||
for (let i1 = 0; i1 < l_block1; i1++) {
|
for (let i1 = 0; i1 < l_block1; i1++) {
|
||||||
ctx[\`elem\`] = v_block1[i1];
|
ctx[\`elem\`] = v_block1[i1];
|
||||||
let key1 = ctx['elem'].id;
|
const key1 = ctx['elem'].id;
|
||||||
let b3;
|
let b3;
|
||||||
if (ctx['elem'].id<3) {
|
if (ctx['elem'].id<3) {
|
||||||
let txt1 = ctx['elem'].text;
|
let txt1 = ctx['elem'].text;
|
||||||
@@ -412,9 +412,9 @@ exports[`t-foreach t-foreach with t-if inside (no external node) 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-foreach t-foreach with t-if inside 1`] = `
|
exports[`t-foreach t-foreach with t-if inside 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { prepareList, withKey } = helpers;
|
let { prepareList, withKey } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
@@ -422,10 +422,10 @@ exports[`t-foreach t-foreach with t-if inside 1`] = `
|
|||||||
|
|
||||||
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(ctx['elems']);
|
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['elems']);;
|
||||||
for (let i1 = 0; i1 < l_block2; i1++) {
|
for (let i1 = 0; i1 < l_block2; i1++) {
|
||||||
ctx[\`elem\`] = v_block2[i1];
|
ctx[\`elem\`] = v_block2[i1];
|
||||||
let key1 = ctx['elem'].id;
|
const key1 = ctx['elem'].id;
|
||||||
let b4;
|
let b4;
|
||||||
if (ctx['elem'].id<3) {
|
if (ctx['elem'].id<3) {
|
||||||
let txt1 = ctx['elem'].text;
|
let txt1 = ctx['elem'].text;
|
||||||
@@ -433,16 +433,16 @@ exports[`t-foreach t-foreach with t-if inside 1`] = `
|
|||||||
}
|
}
|
||||||
c_block2[i1] = withKey(multi([b4]), key1);
|
c_block2[i1] = withKey(multi([b4]), key1);
|
||||||
}
|
}
|
||||||
let b2 = list(c_block2);
|
const b2 = list(c_block2);
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-foreach t-key on t-foreach 1`] = `
|
exports[`t-foreach t-key on t-foreach 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { prepareList, withKey } = helpers;
|
let { prepareList, withKey } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
@@ -450,22 +450,22 @@ exports[`t-foreach t-key on t-foreach 1`] = `
|
|||||||
|
|
||||||
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(ctx['things']);
|
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['things']);;
|
||||||
for (let i1 = 0; i1 < l_block2; i1++) {
|
for (let i1 = 0; i1 < l_block2; i1++) {
|
||||||
ctx[\`thing\`] = v_block2[i1];
|
ctx[\`thing\`] = v_block2[i1];
|
||||||
let key1 = ctx['thing'];
|
const key1 = ctx['thing'];
|
||||||
c_block2[i1] = withKey(block3(), key1);
|
c_block2[i1] = withKey(block3(), key1);
|
||||||
}
|
}
|
||||||
let b2 = list(c_block2);
|
const b2 = list(c_block2);
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-foreach throws error if invalid loop expression 1`] = `
|
exports[`t-foreach throws error if invalid loop expression 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { prepareList, withKey } = helpers;
|
let { prepareList, withKey } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
@@ -473,24 +473,24 @@ exports[`t-foreach throws error if invalid loop expression 1`] = `
|
|||||||
|
|
||||||
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(ctx['abc']);
|
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['abc']);;
|
||||||
for (let i1 = 0; i1 < l_block2; i1++) {
|
for (let i1 = 0; i1 < l_block2; i1++) {
|
||||||
ctx[\`item\`] = v_block2[i1];
|
ctx[\`item\`] = v_block2[i1];
|
||||||
ctx[\`item_index\`] = i1;
|
ctx[\`item_index\`] = i1;
|
||||||
let key1 = ctx['item'];
|
const key1 = ctx['item'];
|
||||||
const tKey_1 = ctx['item_index'];
|
const tKey_1 = ctx['item_index'];
|
||||||
c_block2[i1] = withKey(block3(), tKey_1 + key1);
|
c_block2[i1] = withKey(block3(), tKey_1 + key1);
|
||||||
}
|
}
|
||||||
let b2 = list(c_block2);
|
const b2 = list(c_block2);
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-foreach with t-memo 1`] = `
|
exports[`t-foreach with t-memo 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { prepareList, withKey } = helpers;
|
let { prepareList, withKey } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
@@ -500,12 +500,12 @@ exports[`t-foreach with t-memo 1`] = `
|
|||||||
let cache = ctx.cache || {};
|
let cache = ctx.cache || {};
|
||||||
let nextCache = ctx.cache = {};
|
let nextCache = ctx.cache = {};
|
||||||
ctx = Object.create(ctx);
|
ctx = Object.create(ctx);
|
||||||
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['items']);
|
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['items']);;
|
||||||
for (let i1 = 0; i1 < l_block2; i1++) {
|
for (let i1 = 0; i1 < l_block2; i1++) {
|
||||||
ctx[\`item\`] = v_block2[i1];
|
ctx[\`item\`] = v_block2[i1];
|
||||||
let key1 = ctx['item'].id;
|
const key1 = ctx['item'].id;
|
||||||
let memo1 = [ctx['item'].x]
|
const memo1 = [ctx['item'].x];
|
||||||
let vnode1 = cache[key1];
|
const vnode1 = cache[key1];;
|
||||||
if (vnode1) {
|
if (vnode1) {
|
||||||
if (shallowEqual(vnode1.memo, memo1)) {
|
if (shallowEqual(vnode1.memo, memo1)) {
|
||||||
c_block2[i1] = vnode1;
|
c_block2[i1] = vnode1;
|
||||||
@@ -518,7 +518,7 @@ exports[`t-foreach with t-memo 1`] = `
|
|||||||
c_block2[i1] = withKey(block3([txt1, txt2]), key1);
|
c_block2[i1] = withKey(block3([txt1, txt2]), key1);
|
||||||
nextCache[key1] = Object.assign(c_block2[i1], {memo: memo1});
|
nextCache[key1] = Object.assign(c_block2[i1], {memo: memo1});
|
||||||
}
|
}
|
||||||
let b2 = list(c_block2);
|
const b2 = list(c_block2);
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`t-if a t-if next to a div 1`] = `
|
exports[`t-if a t-if next to a div 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block2 = createBlock(\`<div>foo</div>\`);
|
let block2 = createBlock(\`<div>foo</div>\`);
|
||||||
|
|
||||||
@@ -19,9 +19,9 @@ exports[`t-if a t-if next to a div 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-if a t-if with two inner nodes 1`] = `
|
exports[`t-if a t-if with two inner nodes 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block3 = createBlock(\`<span>yip</span>\`);
|
let block3 = createBlock(\`<span>yip</span>\`);
|
||||||
let block4 = createBlock(\`<div>yip</div>\`);
|
let block4 = createBlock(\`<div>yip</div>\`);
|
||||||
@@ -29,8 +29,8 @@ exports[`t-if a t-if with two inner nodes 1`] = `
|
|||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let b2;
|
let b2;
|
||||||
if (ctx['condition']) {
|
if (ctx['condition']) {
|
||||||
let b3 = block3();
|
const b3 = block3();
|
||||||
let b4 = block4();
|
const b4 = block4();
|
||||||
b2 = multi([b3, b4]);
|
b2 = multi([b3, b4]);
|
||||||
}
|
}
|
||||||
return multi([b2]);
|
return multi([b2]);
|
||||||
@@ -39,9 +39,9 @@ exports[`t-if a t-if with two inner nodes 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-if boolean value condition elif (no outside node) 1`] = `
|
exports[`t-if boolean value condition elif (no outside node) 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let b2,b3,b4,b5;
|
let b2,b3,b4,b5;
|
||||||
@@ -60,9 +60,9 @@ exports[`t-if boolean value condition elif (no outside node) 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-if boolean value condition elif 1`] = `
|
exports[`t-if boolean value condition elif 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><block-child-1/><block-child-2/><block-child-3/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/><block-child-1/><block-child-2/><block-child-3/></div>\`);
|
||||||
|
|
||||||
@@ -83,9 +83,9 @@ exports[`t-if boolean value condition elif 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-if boolean value condition else 1`] = `
|
exports[`t-if boolean value condition else 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><span>begin</span><block-child-0/><block-child-1/><span>end</span></div>\`);
|
let block1 = createBlock(\`<div><span>begin</span><block-child-0/><block-child-1/><span>end</span></div>\`);
|
||||||
|
|
||||||
@@ -102,9 +102,9 @@ exports[`t-if boolean value condition else 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-if boolean value condition false else 1`] = `
|
exports[`t-if boolean value condition false else 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><span>begin</span><block-child-0/><block-child-1/><span>end</span></div>\`);
|
let block1 = createBlock(\`<div><span>begin</span><block-child-0/><block-child-1/><span>end</span></div>\`);
|
||||||
|
|
||||||
@@ -121,9 +121,9 @@ exports[`t-if boolean value condition false else 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-if boolean value condition missing 1`] = `
|
exports[`t-if boolean value condition missing 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
||||||
|
|
||||||
@@ -138,9 +138,9 @@ exports[`t-if boolean value condition missing 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-if can use some boolean operators in expressions 1`] = `
|
exports[`t-if can use some boolean operators in expressions 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><block-child-1/><block-child-2/><block-child-3/><block-child-4/><block-child-5/><block-child-6/><block-child-7/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/><block-child-1/><block-child-2/><block-child-3/><block-child-4/><block-child-5/><block-child-6/><block-child-7/></div>\`);
|
||||||
|
|
||||||
@@ -176,9 +176,9 @@ exports[`t-if can use some boolean operators in expressions 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-if div containing a t-if with two inner nodes 1`] = `
|
exports[`t-if div containing a t-if with two inner nodes 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
let block3 = createBlock(\`<span>yip</span>\`);
|
let block3 = createBlock(\`<span>yip</span>\`);
|
||||||
@@ -187,8 +187,8 @@ exports[`t-if div containing a t-if with two inner nodes 1`] = `
|
|||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let b2;
|
let b2;
|
||||||
if (ctx['condition']) {
|
if (ctx['condition']) {
|
||||||
let b3 = block3();
|
const b3 = block3();
|
||||||
let b4 = block4();
|
const b4 = block4();
|
||||||
b2 = multi([b3, b4]);
|
b2 = multi([b3, b4]);
|
||||||
}
|
}
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
@@ -197,9 +197,9 @@ exports[`t-if div containing a t-if with two inner nodes 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-if dynamic content after t-if with two children nodes 1`] = `
|
exports[`t-if dynamic content after t-if with two children nodes 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><block-text-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/><block-text-0/></div>\`);
|
||||||
let block3 = createBlock(\`<p>1</p>\`);
|
let block3 = createBlock(\`<p>1</p>\`);
|
||||||
@@ -208,8 +208,8 @@ exports[`t-if dynamic content after t-if with two children nodes 1`] = `
|
|||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let b2;
|
let b2;
|
||||||
if (ctx['condition']) {
|
if (ctx['condition']) {
|
||||||
let b3 = block3();
|
const b3 = block3();
|
||||||
let b4 = block4();
|
const b4 = block4();
|
||||||
b2 = multi([b3, b4]);
|
b2 = multi([b3, b4]);
|
||||||
}
|
}
|
||||||
let txt1 = ctx['text'];
|
let txt1 = ctx['text'];
|
||||||
@@ -219,9 +219,9 @@ exports[`t-if dynamic content after t-if with two children nodes 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-if just a t-if 1`] = `
|
exports[`t-if just a t-if 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let b2;
|
let b2;
|
||||||
@@ -234,9 +234,9 @@ exports[`t-if just a t-if 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-if simple t-if/t-else 1`] = `
|
exports[`t-if simple t-if/t-else 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let b2,b3;
|
let b2,b3;
|
||||||
@@ -251,9 +251,9 @@ exports[`t-if simple t-if/t-else 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-if simple t-if/t-else in a div 1`] = `
|
exports[`t-if simple t-if/t-else in a div 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
|
||||||
|
|
||||||
@@ -270,9 +270,9 @@ exports[`t-if simple t-if/t-else in a div 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-if t-esc with t-elif 1`] = `
|
exports[`t-if t-esc with t-elif 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
|
||||||
|
|
||||||
@@ -289,9 +289,9 @@ exports[`t-if t-esc with t-elif 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-if t-esc with t-if 1`] = `
|
exports[`t-if t-esc with t-if 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
|
||||||
@@ -306,9 +306,9 @@ exports[`t-if t-esc with t-if 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-if t-if and t-else with two nodes 1`] = `
|
exports[`t-if t-if and t-else with two nodes 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block4 = createBlock(\`<span>a</span>\`);
|
let block4 = createBlock(\`<span>a</span>\`);
|
||||||
let block5 = createBlock(\`<span>b</span>\`);
|
let block5 = createBlock(\`<span>b</span>\`);
|
||||||
@@ -318,8 +318,8 @@ exports[`t-if t-if and t-else with two nodes 1`] = `
|
|||||||
if (ctx['condition']) {
|
if (ctx['condition']) {
|
||||||
b2 = text(\`1\`);
|
b2 = text(\`1\`);
|
||||||
} else {
|
} else {
|
||||||
let b4 = block4();
|
const b4 = block4();
|
||||||
let b5 = block5();
|
const b5 = block5();
|
||||||
b3 = multi([b4, b5]);
|
b3 = multi([b4, b5]);
|
||||||
}
|
}
|
||||||
return multi([b2, b3]);
|
return multi([b2, b3]);
|
||||||
@@ -328,9 +328,9 @@ exports[`t-if t-if and t-else with two nodes 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-if t-if in a div 1`] = `
|
exports[`t-if t-if in a div 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
|
|
||||||
@@ -345,9 +345,9 @@ exports[`t-if t-if in a div 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-if t-if in a t-if 1`] = `
|
exports[`t-if t-if in a t-if 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
let block2 = createBlock(\`<span>1<block-child-0/></span>\`);
|
let block2 = createBlock(\`<span>1<block-child-0/></span>\`);
|
||||||
@@ -367,9 +367,9 @@ exports[`t-if t-if in a t-if 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-if t-if with empty content 1`] = `
|
exports[`t-if t-if with empty content 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let b2,b3;
|
let b2,b3;
|
||||||
@@ -383,9 +383,9 @@ exports[`t-if t-if with empty content 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-if t-if/t-else with more content 1`] = `
|
exports[`t-if t-if/t-else with more content 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let b2,b3;
|
let b2,b3;
|
||||||
@@ -402,9 +402,9 @@ exports[`t-if t-if/t-else with more content 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-if t-set, then t-if 1`] = `
|
exports[`t-if t-set, then t-if 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { isBoundary, withDefault, setContextValue } = helpers;
|
let { isBoundary, withDefault, setContextValue } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
@@ -423,9 +423,9 @@ exports[`t-if t-set, then t-if 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-if t-set, then t-if, part 2 1`] = `
|
exports[`t-if t-set, then t-if, part 2 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { isBoundary, withDefault, setContextValue } = helpers;
|
let { isBoundary, withDefault, setContextValue } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
@@ -446,9 +446,9 @@ exports[`t-if t-set, then t-if, part 2 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-if t-set, then t-if, part 3 1`] = `
|
exports[`t-if t-set, then t-if, part 3 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { isBoundary, withDefault, setContextValue } = helpers;
|
let { isBoundary, withDefault, setContextValue } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
|
||||||
@@ -472,9 +472,9 @@ exports[`t-if t-set, then t-if, part 3 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-if two consecutive t-if 1`] = `
|
exports[`t-if two consecutive t-if 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let b2,b3;
|
let b2,b3;
|
||||||
@@ -490,9 +490,9 @@ exports[`t-if two consecutive t-if 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-if two consecutive t-if in a div 1`] = `
|
exports[`t-if two consecutive t-if in a div 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
|
||||||
|
|
||||||
@@ -510,9 +510,9 @@ exports[`t-if two consecutive t-if in a div 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-if two t-ifs next to each other 1`] = `
|
exports[`t-if two t-ifs next to each other 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
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(\`<span><block-text-0/></span>\`);
|
let block2 = createBlock(\`<span><block-text-0/></span>\`);
|
||||||
@@ -526,8 +526,8 @@ exports[`t-if two t-ifs next to each other 1`] = `
|
|||||||
b2 = block2([txt1]);
|
b2 = block2([txt1]);
|
||||||
}
|
}
|
||||||
if (ctx['condition']) {
|
if (ctx['condition']) {
|
||||||
let b4 = block4();
|
const b4 = block4();
|
||||||
let b5 = block5();
|
const b5 = block5();
|
||||||
b3 = multi([b4, b5]);
|
b3 = multi([b4, b5]);
|
||||||
}
|
}
|
||||||
return block1([], [b2, b3]);
|
return block1([], [b2, b3]);
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`t-key can use t-key directive on a node 1`] = `
|
exports[`t-key can use t-key directive on a node 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
||||||
|
|
||||||
@@ -16,9 +16,9 @@ exports[`t-key can use t-key directive on a node 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-key can use t-key directive on a node 2 1`] = `
|
exports[`t-key can use t-key directive on a node 2 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
||||||
|
|
||||||
@@ -31,9 +31,9 @@ exports[`t-key can use t-key directive on a node 2 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-key can use t-key directive on a node as a function 1`] = `
|
exports[`t-key can use t-key directive on a node as a function 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
||||||
|
|
||||||
@@ -46,9 +46,9 @@ exports[`t-key can use t-key directive on a node as a function 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-key t-key directive in a list 1`] = `
|
exports[`t-key t-key directive in a list 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { prepareList, withKey } = helpers;
|
let { prepareList, withKey } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<ul><block-child-0/></ul>\`);
|
let block1 = createBlock(\`<ul><block-child-0/></ul>\`);
|
||||||
@@ -56,23 +56,23 @@ exports[`t-key t-key directive in a list 1`] = `
|
|||||||
|
|
||||||
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(ctx['beers']);
|
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['beers']);;
|
||||||
for (let i1 = 0; i1 < l_block2; i1++) {
|
for (let i1 = 0; i1 < l_block2; i1++) {
|
||||||
ctx[\`beer\`] = v_block2[i1];
|
ctx[\`beer\`] = v_block2[i1];
|
||||||
let key1 = ctx['beer'].id;
|
const key1 = ctx['beer'].id;
|
||||||
let txt1 = ctx['beer'].name;
|
let txt1 = ctx['beer'].name;
|
||||||
c_block2[i1] = withKey(block3([txt1]), key1);
|
c_block2[i1] = withKey(block3([txt1]), key1);
|
||||||
}
|
}
|
||||||
let b2 = list(c_block2);
|
const b2 = list(c_block2);
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-key t-key on sub dom node pushes a child block in its parent 1`] = `
|
exports[`t-key t-key on sub dom node pushes a child block in its parent 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
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(\`<span/>\`);
|
let block2 = createBlock(\`<span/>\`);
|
||||||
@@ -91,9 +91,9 @@ exports[`t-key t-key on sub dom node pushes a child block in its parent 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-key t-key on sub dom node pushes a child block in its parent 2`] = `
|
exports[`t-key t-key on sub dom node pushes a child block in its parent 2`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><h1/></div>\`);
|
let block1 = createBlock(\`<div><h1/></div>\`);
|
||||||
|
|
||||||
|
|||||||
@@ -1,24 +1,24 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`t-out literal 1`] = `
|
exports[`t-out literal 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { safeOutput } = helpers;
|
let { safeOutput } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let b2 = safeOutput('ok');
|
const b2 = safeOutput('ok');
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-out literal, no outside html element 1`] = `
|
exports[`t-out literal, no outside html element 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { safeOutput } = helpers;
|
let { safeOutput } = helpers;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
@@ -28,11 +28,11 @@ exports[`t-out literal, no outside html element 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-out multiple calls to t-out 1`] = `
|
exports[`t-out multiple calls to t-out 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { isBoundary, zero, getTemplate } = helpers;
|
let { isBoundary, zero } = helpers;
|
||||||
const callTemplate_1 = getTemplate(\`sub\`);
|
const callTemplate_1 = app.getTemplate(\`sub\`);
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
let block2 = createBlock(\`<span>coucou</span>\`);
|
let block2 = createBlock(\`<span>coucou</span>\`);
|
||||||
@@ -40,51 +40,66 @@ exports[`t-out multiple calls to t-out 1`] = `
|
|||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
ctx = Object.create(ctx);
|
ctx = Object.create(ctx);
|
||||||
ctx[isBoundary] = 1;
|
ctx[isBoundary] = 1;
|
||||||
let b2 = block2();
|
const b2 = block2();
|
||||||
ctx[zero] = b2;
|
ctx[zero] = b2;
|
||||||
let b3 = callTemplate_1.call(this, ctx, node, key + \`__1\`);
|
const b3 = callTemplate_1.call(this, ctx, node, key + \`__1\`);
|
||||||
return block1([], [b3]);
|
return block1([], [b3]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-out multiple calls to t-out 2`] = `
|
exports[`t-out multiple calls to t-out 2`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { zero } = helpers;
|
let { zero } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><div>Greeter</div><block-child-1/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/><div>Greeter</div><block-child-1/></div>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let b2 = ctx[zero];
|
const b2 = ctx[zero];
|
||||||
let b3 = ctx[zero];
|
const b3 = ctx[zero];
|
||||||
return block1([], [b2, b3]);
|
return block1([], [b2, b3]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-out not escaping 1`] = `
|
exports[`t-out not escaping 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { safeOutput } = helpers;
|
let { safeOutput } = 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 = \\"\\") {
|
||||||
let b2 = safeOutput(ctx['var']);
|
const b2 = safeOutput(ctx['var']);
|
||||||
|
return block1([], [b2]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`t-out number literal 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { safeOutput } = helpers;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
const b2 = safeOutput(1);
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-out t-out 0 1`] = `
|
exports[`t-out t-out 0 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { isBoundary, zero, getTemplate } = helpers;
|
let { isBoundary, zero } = helpers;
|
||||||
const callTemplate_1 = getTemplate(\`_basic-callee\`);
|
const callTemplate_1 = app.getTemplate(\`_basic-callee\`);
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
let block2 = createBlock(\`<div>zero</div>\`);
|
let block2 = createBlock(\`<div>zero</div>\`);
|
||||||
@@ -92,48 +107,48 @@ exports[`t-out t-out 0 1`] = `
|
|||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
ctx = Object.create(ctx);
|
ctx = Object.create(ctx);
|
||||||
ctx[isBoundary] = 1;
|
ctx[isBoundary] = 1;
|
||||||
let b2 = block2();
|
const b2 = block2();
|
||||||
ctx[zero] = b2;
|
ctx[zero] = b2;
|
||||||
let b3 = callTemplate_1.call(this, ctx, node, key + \`__1\`);
|
const b3 = callTemplate_1.call(this, ctx, node, key + \`__1\`);
|
||||||
return block1([], [b3]);
|
return block1([], [b3]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-out t-out 0 2`] = `
|
exports[`t-out t-out 0 2`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { zero } = helpers;
|
let { zero } = 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 = \\"\\") {
|
||||||
let b2 = ctx[zero];
|
const b2 = ctx[zero];
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-out t-out and another sibling node 1`] = `
|
exports[`t-out t-out and another sibling node 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { safeOutput } = helpers;
|
let { safeOutput } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><span>hello</span><block-child-0/></span>\`);
|
let block1 = createBlock(\`<span><span>hello</span><block-child-0/></span>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let b2 = safeOutput(ctx['var']);
|
const b2 = safeOutput(ctx['var']);
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-out t-out bdom 1`] = `
|
exports[`t-out t-out bdom 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { isBoundary, withDefault, LazyValue, safeOutput } = helpers;
|
let { isBoundary, withDefault, LazyValue, safeOutput } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><span><block-child-0/></span></div>\`);
|
let block1 = createBlock(\`<div><span><block-child-0/></span></div>\`);
|
||||||
@@ -146,140 +161,140 @@ exports[`t-out t-out bdom 1`] = `
|
|||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
ctx = Object.create(ctx);
|
ctx = Object.create(ctx);
|
||||||
ctx[isBoundary] = 1
|
ctx[isBoundary] = 1
|
||||||
ctx[\`var\`] = new LazyValue(value1, ctx, node);
|
ctx[\`var\`] = new LazyValue(value1, ctx, this, node, key);
|
||||||
let b3 = safeOutput(ctx['var']);
|
const b3 = safeOutput(ctx['var']);
|
||||||
return block1([], [b3]);
|
return block1([], [b3]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-out t-out block 1`] = `
|
exports[`t-out t-out block 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { safeOutput } = helpers;
|
let { safeOutput } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let b2 = safeOutput(ctx['bdom']);
|
const b2 = safeOutput(ctx['bdom']);
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-out t-out escaped 1`] = `
|
exports[`t-out t-out escaped 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { safeOutput } = helpers;
|
let { safeOutput } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let b2 = safeOutput(ctx['var']);
|
const b2 = safeOutput(ctx['var']);
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-out t-out markedup 1`] = `
|
exports[`t-out t-out markedup 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { safeOutput } = helpers;
|
let { safeOutput } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let b2 = safeOutput(ctx['var']);
|
const b2 = safeOutput(ctx['var']);
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-out t-out on a node with a body, as a default 1`] = `
|
exports[`t-out t-out on a node with a body, as a default 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { safeOutput, withDefault } = helpers;
|
let { safeOutput } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let b3 = text(\`nope\`);
|
const b3 = text(\`nope\`);
|
||||||
let b2 = withDefault(safeOutput(ctx['var']), b3);
|
const b2 = safeOutput(ctx['var'], b3);
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-out t-out on a node with a dom node in body, as a default 1`] = `
|
exports[`t-out t-out on a node with a dom node in body, as a default 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { safeOutput, withDefault } = helpers;
|
let { safeOutput } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
||||||
let block3 = createBlock(\`<div>nope</div>\`);
|
let block3 = createBlock(\`<div>nope</div>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let b3 = block3();
|
const b3 = block3();
|
||||||
let b2 = withDefault(safeOutput(ctx['var']), b3);
|
const b2 = safeOutput(ctx['var'], b3);
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-out t-out switch escaped 1`] = `
|
exports[`t-out t-out switch escaped 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { safeOutput } = helpers;
|
let { safeOutput } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let b2 = safeOutput(ctx['var']);
|
const b2 = safeOutput(ctx['var']);
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-out t-out switch escaped on markup 1`] = `
|
exports[`t-out t-out switch escaped on markup 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { safeOutput } = helpers;
|
let { safeOutput } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let b2 = safeOutput(ctx['var']);
|
const b2 = safeOutput(ctx['var']);
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-out t-out switch markup 1`] = `
|
exports[`t-out t-out switch markup 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { safeOutput } = helpers;
|
let { safeOutput } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let b2 = safeOutput(ctx['var']);
|
const b2 = safeOutput(ctx['var']);
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-out t-out switch markup on bdom 1`] = `
|
exports[`t-out t-out switch markup on bdom 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { isBoundary, withDefault, LazyValue, safeOutput } = helpers;
|
let { isBoundary, withDefault, LazyValue, safeOutput } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
|
||||||
@@ -295,12 +310,12 @@ exports[`t-out t-out switch markup on bdom 1`] = `
|
|||||||
ctx = Object.create(ctx);
|
ctx = Object.create(ctx);
|
||||||
ctx[isBoundary] = 1
|
ctx[isBoundary] = 1
|
||||||
let b3,b5;
|
let b3,b5;
|
||||||
ctx[\`bdom\`] = new LazyValue(value1, ctx, node);
|
ctx[\`bdom\`] = new LazyValue(value1, ctx, this, node, key);
|
||||||
if (ctx['hasBdom']) {
|
if (ctx['hasBdom']) {
|
||||||
let b4 = safeOutput(ctx['bdom']);
|
const b4 = safeOutput(ctx['bdom']);
|
||||||
b3 = block3([], [b4]);
|
b3 = block3([], [b4]);
|
||||||
} else {
|
} else {
|
||||||
let b6 = safeOutput(ctx['var']);
|
const b6 = safeOutput(ctx['var']);
|
||||||
b5 = block5([], [b6]);
|
b5 = block5([], [b6]);
|
||||||
}
|
}
|
||||||
return block1([], [b3, b5]);
|
return block1([], [b3, b5]);
|
||||||
@@ -309,24 +324,24 @@ exports[`t-out t-out switch markup on bdom 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-out t-out switch markup on escaped 1`] = `
|
exports[`t-out t-out switch markup on escaped 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { safeOutput } = helpers;
|
let { safeOutput } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let b2 = safeOutput(ctx['var']);
|
const b2 = safeOutput(ctx['var']);
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-out t-out with a <t/> in body 1`] = `
|
exports[`t-out t-out with a <t/> in body 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { safeOutput } = helpers;
|
let { safeOutput } = helpers;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
@@ -336,54 +351,93 @@ exports[`t-out t-out with a <t/> in body 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-out t-out with arbitrary object 1`] = `
|
exports[`t-out t-out with arbitrary object 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { safeOutput } = helpers;
|
let { safeOutput } = 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 = \\"\\") {
|
||||||
let b2 = safeOutput(ctx['var']);
|
const b2 = safeOutput(ctx['var']);
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-out t-out with arbitrary object 2 1`] = `
|
exports[`t-out t-out with arbitrary object 2 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { safeOutput } = helpers;
|
let { safeOutput } = 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 = \\"\\") {
|
||||||
let b2 = safeOutput(ctx['var']);
|
const b2 = safeOutput(ctx['var']);
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-out t-out with comment 1`] = `
|
exports[`t-out t-out with comment 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { safeOutput } = helpers;
|
let { safeOutput } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let b2 = safeOutput(ctx['var']);
|
const b2 = safeOutput(ctx['var']);
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-out t-out with just a t-set t-value in body 1`] = `
|
exports[`t-out t-out with just a t-set t-value in body 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { safeOutput } = helpers;
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
return safeOutput(ctx['var']);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`t-out t-out with the 0 number 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { safeOutput } = helpers;
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
return safeOutput(ctx['var']);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`t-out t-out with the 0 number, in a p 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { safeOutput } = helpers;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<p><block-child-0/></p>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
const b2 = safeOutput(ctx['var']);
|
||||||
|
return block1([], [b2]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`t-out top level t-out with undefined 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { safeOutput } = helpers;
|
let { safeOutput } = helpers;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
@@ -393,45 +447,75 @@ exports[`t-out t-out with just a t-set t-value in body 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-out variable 1`] = `
|
exports[`t-out variable 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { safeOutput } = helpers;
|
let { safeOutput } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let b2 = safeOutput(ctx['var']);
|
const b2 = safeOutput(ctx['var']);
|
||||||
|
return block1([], [b2]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`t-out with a String class 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { safeOutput } = helpers;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
const b2 = safeOutput(ctx['var']);
|
||||||
|
return block1([], [b2]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`t-out with an extended String class 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { safeOutput } = helpers;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
const b2 = safeOutput(ctx['var']);
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-raw is deprecated should warn 1`] = `
|
exports[`t-raw is deprecated should warn 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { safeOutput } = helpers;
|
let { safeOutput } = 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 = \\"\\") {
|
||||||
let b2 = safeOutput(ctx['var']);
|
const b2 = safeOutput(ctx['var']);
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-raw is deprecated t-out is actually called in t-raw's place 1`] = `
|
exports[`t-raw is deprecated t-out is actually called in t-raw's place 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { safeOutput } = helpers;
|
let { safeOutput } = 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 = \\"\\") {
|
||||||
let b2 = safeOutput(ctx['var']);
|
const b2 = safeOutput(ctx['var']);
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
|
|||||||
@@ -1,78 +1,98 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`t-ref can get a dynamic ref on a node 1`] = `
|
exports[`t-ref can get a dynamic ref on a node 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { singleRefSetter } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><span block-ref=\\"0\\"/></div>\`);
|
let block1 = createBlock(\`<div><span block-ref=\\"0\\"/></div>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
const refs = ctx.__owl__.refs;
|
const refs = this.__owl__.refs;
|
||||||
const v1 = ctx['id'];
|
const v1 = ctx['id'];
|
||||||
let ref1 = (el) => refs[\`myspan\${v1}\`] = el;
|
let ref1 = singleRefSetter(refs, \`myspan\${v1}\`);
|
||||||
|
return block1([ref1]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`t-ref can get a dynamic ref on a node, alternate syntax 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { singleRefSetter } = helpers;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div><span block-ref=\\"0\\"/></div>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
const refs = this.__owl__.refs;
|
||||||
|
const v1 = ctx['id'];
|
||||||
|
let ref1 = singleRefSetter(refs, \`myspan\${v1}\`);
|
||||||
return block1([ref1]);
|
return block1([ref1]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-ref can get a ref on a node 1`] = `
|
exports[`t-ref can get a ref on a node 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { singleRefSetter } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><span block-ref=\\"0\\"/></div>\`);
|
let block1 = createBlock(\`<div><span block-ref=\\"0\\"/></div>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
const refs = ctx.__owl__.refs;
|
const refs = this.__owl__.refs;
|
||||||
const ref1 = (el) => refs[\`myspan\`] = el;
|
const ref1 = singleRefSetter(refs, \`myspan\`);
|
||||||
return block1([ref1]);
|
return block1([ref1]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-ref ref in a t-call 1`] = `
|
exports[`t-ref ref in a t-call 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { getTemplate } = helpers;
|
const callTemplate_1 = app.getTemplate(\`sub\`);
|
||||||
const callTemplate_1 = getTemplate(\`sub\`);
|
|
||||||
|
|
||||||
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 = \\"\\") {
|
||||||
let b2 = callTemplate_1.call(this, ctx, node, key + \`__1\`);
|
const b2 = callTemplate_1.call(this, ctx, node, key + \`__1\`);
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-ref ref in a t-call 2`] = `
|
exports[`t-ref ref in a t-call 2`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { singleRefSetter } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div>1<span block-ref=\\"0\\"/>2</div>\`);
|
let block1 = createBlock(\`<div>1<span block-ref=\\"0\\"/>2</div>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
const refs = ctx.__owl__.refs;
|
const refs = this.__owl__.refs;
|
||||||
const ref1 = (el) => refs[\`name\`] = el;
|
const ref1 = singleRefSetter(refs, \`name\`);
|
||||||
return block1([ref1]);
|
return block1([ref1]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-ref ref in a t-if 1`] = `
|
exports[`t-ref ref in a t-if 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { singleRefSetter } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
let block2 = createBlock(\`<span block-ref=\\"0\\"/>\`);
|
let block2 = createBlock(\`<span block-ref=\\"0\\"/>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
const refs = ctx.__owl__.refs;
|
const refs = this.__owl__.refs;
|
||||||
const ref1 = (el) => refs[\`name\`] = el;
|
const ref1 = singleRefSetter(refs, \`name\`);
|
||||||
let b2;
|
let b2;
|
||||||
if (ctx['condition']) {
|
if (ctx['condition']) {
|
||||||
b2 = block2([ref1]);
|
b2 = block2([ref1]);
|
||||||
@@ -83,45 +103,46 @@ exports[`t-ref ref in a t-if 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-ref refs in a loop 1`] = `
|
exports[`t-ref refs in a loop 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { prepareList, withKey } = helpers;
|
let { prepareList, singleRefSetter, withKey } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
let block3 = createBlock(\`<div block-ref=\\"0\\"><block-text-1/></div>\`);
|
let block3 = createBlock(\`<div block-ref=\\"0\\"><block-text-1/></div>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
const refs = ctx.__owl__.refs;
|
const refs = this.__owl__.refs;
|
||||||
ctx = Object.create(ctx);
|
ctx = Object.create(ctx);
|
||||||
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['items']);
|
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['items']);;
|
||||||
for (let i1 = 0; i1 < l_block2; i1++) {
|
for (let i1 = 0; i1 < l_block2; i1++) {
|
||||||
ctx[\`item\`] = v_block2[i1];
|
ctx[\`item\`] = v_block2[i1];
|
||||||
let key1 = ctx['item'];
|
const key1 = ctx['item'];
|
||||||
const tKey_1 = ctx['item'];
|
const tKey_1 = ctx['item'];
|
||||||
const v1 = ctx['item'];
|
const v1 = ctx['item'];
|
||||||
let ref1 = (el) => refs[\`\${v1}\`] = el;
|
let ref1 = singleRefSetter(refs, (v1));
|
||||||
let txt1 = ctx['item'];
|
let txt1 = ctx['item'];
|
||||||
c_block2[i1] = withKey(block3([ref1, txt1]), tKey_1 + key1);
|
c_block2[i1] = withKey(block3([ref1, txt1]), tKey_1 + key1);
|
||||||
}
|
}
|
||||||
let b2 = list(c_block2);
|
const b2 = list(c_block2);
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-ref two refs, one in a t-if 1`] = `
|
exports[`t-ref two refs, one in a t-if 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { singleRefSetter } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><p block-ref=\\"0\\"/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/><p block-ref=\\"0\\"/></div>\`);
|
||||||
let block2 = createBlock(\`<span block-ref=\\"0\\"/>\`);
|
let block2 = createBlock(\`<span block-ref=\\"0\\"/>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
const refs = ctx.__owl__.refs;
|
const refs = this.__owl__.refs;
|
||||||
const ref1 = (el) => refs[\`name\`] = el;
|
const ref1 = singleRefSetter(refs, \`name\`);
|
||||||
const ref2 = (el) => refs[\`p\`] = el;
|
const ref2 = singleRefSetter(refs, \`p\`);
|
||||||
let b2;
|
let b2;
|
||||||
if (ctx['condition']) {
|
if (ctx['condition']) {
|
||||||
b2 = block2([ref1]);
|
b2 = block2([ref1]);
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`t-set evaluate value expression 1`] = `
|
exports[`t-set evaluate value expression 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { isBoundary, withDefault, setContextValue } = helpers;
|
let { isBoundary, withDefault, setContextValue } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
||||||
@@ -19,9 +19,9 @@ exports[`t-set evaluate value expression 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-set evaluate value expression, part 2 1`] = `
|
exports[`t-set evaluate value expression, part 2 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { isBoundary, withDefault, setContextValue } = helpers;
|
let { isBoundary, withDefault, setContextValue } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
||||||
@@ -37,9 +37,9 @@ exports[`t-set evaluate value expression, part 2 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-set set from attribute literal (no outside div) 1`] = `
|
exports[`t-set set from attribute literal (no outside div) 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { isBoundary, withDefault, setContextValue } = helpers;
|
let { isBoundary, withDefault, setContextValue } = helpers;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
@@ -52,9 +52,9 @@ exports[`t-set set from attribute literal (no outside div) 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-set set from attribute literal 1`] = `
|
exports[`t-set set from attribute literal 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { isBoundary, withDefault, setContextValue } = helpers;
|
let { isBoundary, withDefault, setContextValue } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
||||||
@@ -70,9 +70,9 @@ exports[`t-set set from attribute literal 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-set set from attribute lookup 1`] = `
|
exports[`t-set set from attribute lookup 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { isBoundary, withDefault, setContextValue } = helpers;
|
let { isBoundary, withDefault, setContextValue } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
||||||
@@ -88,9 +88,9 @@ exports[`t-set set from attribute lookup 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-set set from body literal (with t-if/t-else 1`] = `
|
exports[`t-set set from body literal (with t-if/t-else 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { isBoundary, withDefault, LazyValue } = helpers;
|
let { isBoundary, withDefault, LazyValue } = helpers;
|
||||||
|
|
||||||
function value1(ctx, node, key = \\"\\") {
|
function value1(ctx, node, key = \\"\\") {
|
||||||
@@ -106,16 +106,16 @@ exports[`t-set set from body literal (with t-if/t-else 1`] = `
|
|||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
ctx = Object.create(ctx);
|
ctx = Object.create(ctx);
|
||||||
ctx[isBoundary] = 1
|
ctx[isBoundary] = 1
|
||||||
ctx[\`value\`] = new LazyValue(value1, ctx, node);
|
ctx[\`value\`] = new LazyValue(value1, ctx, this, node, key);
|
||||||
return text(ctx['value']);
|
return text(ctx['value']);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-set set from body literal 1`] = `
|
exports[`t-set set from body literal 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { isBoundary, withDefault, setContextValue } = helpers;
|
let { isBoundary, withDefault, setContextValue } = helpers;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
@@ -128,9 +128,9 @@ exports[`t-set set from body literal 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-set set from body lookup 1`] = `
|
exports[`t-set set from body lookup 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { isBoundary, withDefault, LazyValue } = helpers;
|
let { isBoundary, withDefault, LazyValue } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
||||||
@@ -142,7 +142,7 @@ exports[`t-set set from body lookup 1`] = `
|
|||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
ctx = Object.create(ctx);
|
ctx = Object.create(ctx);
|
||||||
ctx[isBoundary] = 1
|
ctx[isBoundary] = 1
|
||||||
ctx[\`stuff\`] = new LazyValue(value1, ctx, node);
|
ctx[\`stuff\`] = new LazyValue(value1, ctx, this, node, key);
|
||||||
let txt1 = ctx['stuff'];
|
let txt1 = ctx['stuff'];
|
||||||
return block1([txt1]);
|
return block1([txt1]);
|
||||||
}
|
}
|
||||||
@@ -150,9 +150,9 @@ exports[`t-set set from body lookup 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-set set from empty body 1`] = `
|
exports[`t-set set from empty body 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { isBoundary, withDefault, setContextValue } = helpers;
|
let { isBoundary, withDefault, setContextValue } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
||||||
@@ -168,9 +168,9 @@ exports[`t-set set from empty body 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-set t-set and t-if 1`] = `
|
exports[`t-set t-set and t-if 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { isBoundary, withDefault, setContextValue } = helpers;
|
let { isBoundary, withDefault, setContextValue } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
@@ -189,9 +189,9 @@ exports[`t-set t-set and t-if 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-set t-set body is evaluated immediately 1`] = `
|
exports[`t-set t-set body is evaluated immediately 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { isBoundary, withDefault, setContextValue, LazyValue, safeOutput } = helpers;
|
let { isBoundary, withDefault, setContextValue, LazyValue, safeOutput } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
@@ -206,20 +206,20 @@ exports[`t-set t-set body is evaluated immediately 1`] = `
|
|||||||
ctx = Object.create(ctx);
|
ctx = Object.create(ctx);
|
||||||
ctx[isBoundary] = 1
|
ctx[isBoundary] = 1
|
||||||
setContextValue(ctx, \\"v1\\", 'before');
|
setContextValue(ctx, \\"v1\\", 'before');
|
||||||
ctx[\`v2\`] = new LazyValue(value1, ctx, node);
|
ctx[\`v2\`] = new LazyValue(value1, ctx, this, node, key);
|
||||||
setContextValue(ctx, \\"v1\\", 'after');
|
setContextValue(ctx, \\"v1\\", 'after');
|
||||||
let b3 = safeOutput(ctx['v2']);
|
const b3 = safeOutput(ctx['v2']);
|
||||||
return block1([], [b3]);
|
return block1([], [b3]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-set t-set can't alter from within callee 1`] = `
|
exports[`t-set t-set can't alter from within callee 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { isBoundary, withDefault, setContextValue, getTemplate } = helpers;
|
let { isBoundary, withDefault, setContextValue } = helpers;
|
||||||
const callTemplate_1 = getTemplate(\`sub\`);
|
const callTemplate_1 = app.getTemplate(\`sub\`);
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><p><block-text-0/></p><block-child-0/><p><block-text-1/></p></div>\`);
|
let block1 = createBlock(\`<div><p><block-text-0/></p><block-child-0/><p><block-text-1/></p></div>\`);
|
||||||
|
|
||||||
@@ -228,7 +228,7 @@ exports[`t-set t-set can't alter from within callee 1`] = `
|
|||||||
ctx[isBoundary] = 1
|
ctx[isBoundary] = 1
|
||||||
setContextValue(ctx, \\"iter\\", 'source');
|
setContextValue(ctx, \\"iter\\", 'source');
|
||||||
let txt1 = ctx['iter'];
|
let txt1 = ctx['iter'];
|
||||||
let b2 = callTemplate_1.call(this, ctx, node, key + \`__1\`);
|
const b2 = callTemplate_1.call(this, ctx, node, key + \`__1\`);
|
||||||
let txt2 = ctx['iter'];
|
let txt2 = ctx['iter'];
|
||||||
return block1([txt1, txt2], [b2]);
|
return block1([txt1, txt2], [b2]);
|
||||||
}
|
}
|
||||||
@@ -236,9 +236,9 @@ exports[`t-set t-set can't alter from within callee 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-set t-set can't alter from within callee 2`] = `
|
exports[`t-set t-set can't alter from within callee 2`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { isBoundary, withDefault, setContextValue } = helpers;
|
let { isBoundary, withDefault, setContextValue } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/><block-text-1/></div>\`);
|
let block1 = createBlock(\`<div><block-text-0/><block-text-1/></div>\`);
|
||||||
@@ -255,11 +255,11 @@ exports[`t-set t-set can't alter from within callee 2`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-set t-set can't alter in t-call body 1`] = `
|
exports[`t-set t-set can't alter in t-call body 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { isBoundary, withDefault, setContextValue, getTemplate } = helpers;
|
let { isBoundary, withDefault, setContextValue } = helpers;
|
||||||
const callTemplate_1 = getTemplate(\`sub\`);
|
const callTemplate_1 = app.getTemplate(\`sub\`);
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><p><block-text-0/></p><block-child-0/><p><block-text-1/></p></div>\`);
|
let block1 = createBlock(\`<div><p><block-text-0/></p><block-child-0/><p><block-text-1/></p></div>\`);
|
||||||
|
|
||||||
@@ -271,7 +271,7 @@ exports[`t-set t-set can't alter in t-call body 1`] = `
|
|||||||
ctx = Object.create(ctx);
|
ctx = Object.create(ctx);
|
||||||
ctx[isBoundary] = 1;
|
ctx[isBoundary] = 1;
|
||||||
setContextValue(ctx, \\"iter\\", 'inCall');
|
setContextValue(ctx, \\"iter\\", 'inCall');
|
||||||
let b2 = callTemplate_1.call(this, ctx, node, key + \`__1\`);
|
const b2 = callTemplate_1.call(this, ctx, node, key + \`__1\`);
|
||||||
ctx = ctx.__proto__;
|
ctx = ctx.__proto__;
|
||||||
let txt2 = ctx['iter'];
|
let txt2 = ctx['iter'];
|
||||||
return block1([txt1, txt2], [b2]);
|
return block1([txt1, txt2], [b2]);
|
||||||
@@ -280,9 +280,9 @@ exports[`t-set t-set can't alter in t-call body 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-set t-set can't alter in t-call body 2`] = `
|
exports[`t-set t-set can't alter in t-call body 2`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { isBoundary, withDefault, setContextValue } = helpers;
|
let { isBoundary, withDefault, setContextValue } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/><block-text-1/></div>\`);
|
let block1 = createBlock(\`<div><block-text-0/><block-text-1/></div>\`);
|
||||||
@@ -299,9 +299,9 @@ exports[`t-set t-set can't alter in t-call body 2`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-set t-set does not modify render context existing key values 1`] = `
|
exports[`t-set t-set does not modify render context existing key values 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { isBoundary, withDefault, setContextValue } = helpers;
|
let { isBoundary, withDefault, setContextValue } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
||||||
@@ -317,9 +317,9 @@ exports[`t-set t-set does not modify render context existing key values 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-set t-set evaluates an expression only once 1`] = `
|
exports[`t-set t-set evaluates an expression only once 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { isBoundary, withDefault, setContextValue } = helpers;
|
let { isBoundary, withDefault, setContextValue } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/><block-text-1/></div>\`);
|
let block1 = createBlock(\`<div><block-text-0/><block-text-1/></div>\`);
|
||||||
@@ -336,9 +336,9 @@ exports[`t-set t-set evaluates an expression only once 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-set t-set outside modified in t-foreach 1`] = `
|
exports[`t-set t-set outside modified in t-foreach 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { isBoundary, withDefault, setContextValue, prepareList, withKey } = helpers;
|
let { isBoundary, withDefault, setContextValue, prepareList, withKey } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><p>EndLoop: <block-text-0/></p></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/><p>EndLoop: <block-text-0/></p></div>\`);
|
||||||
@@ -349,16 +349,16 @@ exports[`t-set t-set outside modified in t-foreach 1`] = `
|
|||||||
ctx[isBoundary] = 1
|
ctx[isBoundary] = 1
|
||||||
setContextValue(ctx, \\"iter\\", 0);
|
setContextValue(ctx, \\"iter\\", 0);
|
||||||
ctx = Object.create(ctx);
|
ctx = Object.create(ctx);
|
||||||
const [k_block2, v_block2, l_block2, c_block2] = prepareList(['a','b']);
|
const [k_block2, v_block2, l_block2, c_block2] = prepareList(['a','b']);;
|
||||||
for (let i1 = 0; i1 < l_block2; i1++) {
|
for (let i1 = 0; i1 < l_block2; i1++) {
|
||||||
ctx[\`val\`] = v_block2[i1];
|
ctx[\`val\`] = v_block2[i1];
|
||||||
let key1 = ctx['val'];
|
const key1 = ctx['val'];
|
||||||
let txt1 = ctx['iter'];
|
let txt1 = ctx['iter'];
|
||||||
c_block2[i1] = withKey(block3([txt1]), key1);
|
c_block2[i1] = withKey(block3([txt1]), key1);
|
||||||
setContextValue(ctx, \\"iter\\", ctx['iter']+1);
|
setContextValue(ctx, \\"iter\\", ctx['iter']+1);
|
||||||
}
|
}
|
||||||
ctx = ctx.__proto__;
|
ctx = ctx.__proto__;
|
||||||
let b2 = list(c_block2);
|
const b2 = list(c_block2);
|
||||||
let txt2 = ctx['iter'];
|
let txt2 = ctx['iter'];
|
||||||
return block1([txt2], [b2]);
|
return block1([txt2], [b2]);
|
||||||
}
|
}
|
||||||
@@ -366,9 +366,9 @@ exports[`t-set t-set outside modified in t-foreach 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-set t-set outside modified in t-foreach increment-after operator 1`] = `
|
exports[`t-set t-set outside modified in t-foreach increment-after operator 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { isBoundary, withDefault, setContextValue, prepareList, withKey } = helpers;
|
let { isBoundary, withDefault, setContextValue, prepareList, withKey } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><p>EndLoop: <block-text-0/></p></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/><p>EndLoop: <block-text-0/></p></div>\`);
|
||||||
@@ -379,16 +379,16 @@ exports[`t-set t-set outside modified in t-foreach increment-after operator 1`]
|
|||||||
ctx[isBoundary] = 1
|
ctx[isBoundary] = 1
|
||||||
setContextValue(ctx, \\"iter\\", 0);
|
setContextValue(ctx, \\"iter\\", 0);
|
||||||
ctx = Object.create(ctx);
|
ctx = Object.create(ctx);
|
||||||
const [k_block2, v_block2, l_block2, c_block2] = prepareList(['a','b']);
|
const [k_block2, v_block2, l_block2, c_block2] = prepareList(['a','b']);;
|
||||||
for (let i1 = 0; i1 < l_block2; i1++) {
|
for (let i1 = 0; i1 < l_block2; i1++) {
|
||||||
ctx[\`val\`] = v_block2[i1];
|
ctx[\`val\`] = v_block2[i1];
|
||||||
let key1 = ctx['val'];
|
const key1 = ctx['val'];
|
||||||
let txt1 = ctx['iter'];
|
let txt1 = ctx['iter'];
|
||||||
c_block2[i1] = withKey(block3([txt1]), key1);
|
c_block2[i1] = withKey(block3([txt1]), key1);
|
||||||
setContextValue(ctx, \\"iter\\", ctx['iter']++);
|
setContextValue(ctx, \\"iter\\", ctx['iter']++);
|
||||||
}
|
}
|
||||||
ctx = ctx.__proto__;
|
ctx = ctx.__proto__;
|
||||||
let b2 = list(c_block2);
|
const b2 = list(c_block2);
|
||||||
let txt2 = ctx['iter'];
|
let txt2 = ctx['iter'];
|
||||||
return block1([txt2], [b2]);
|
return block1([txt2], [b2]);
|
||||||
}
|
}
|
||||||
@@ -396,9 +396,9 @@ exports[`t-set t-set outside modified in t-foreach increment-after operator 1`]
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-set t-set outside modified in t-foreach increment-before operator 1`] = `
|
exports[`t-set t-set outside modified in t-foreach increment-before operator 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { isBoundary, withDefault, setContextValue, prepareList, withKey } = helpers;
|
let { isBoundary, withDefault, setContextValue, prepareList, withKey } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><p>EndLoop: <block-text-0/></p></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/><p>EndLoop: <block-text-0/></p></div>\`);
|
||||||
@@ -409,16 +409,16 @@ exports[`t-set t-set outside modified in t-foreach increment-before operator 1`]
|
|||||||
ctx[isBoundary] = 1
|
ctx[isBoundary] = 1
|
||||||
setContextValue(ctx, \\"iter\\", 0);
|
setContextValue(ctx, \\"iter\\", 0);
|
||||||
ctx = Object.create(ctx);
|
ctx = Object.create(ctx);
|
||||||
const [k_block2, v_block2, l_block2, c_block2] = prepareList(['a','b']);
|
const [k_block2, v_block2, l_block2, c_block2] = prepareList(['a','b']);;
|
||||||
for (let i1 = 0; i1 < l_block2; i1++) {
|
for (let i1 = 0; i1 < l_block2; i1++) {
|
||||||
ctx[\`val\`] = v_block2[i1];
|
ctx[\`val\`] = v_block2[i1];
|
||||||
let key1 = ctx['val'];
|
const key1 = ctx['val'];
|
||||||
let txt1 = ctx['iter'];
|
let txt1 = ctx['iter'];
|
||||||
c_block2[i1] = withKey(block3([txt1]), key1);
|
c_block2[i1] = withKey(block3([txt1]), key1);
|
||||||
setContextValue(ctx, \\"iter\\", ++ctx['iter']);
|
setContextValue(ctx, \\"iter\\", ++ctx['iter']);
|
||||||
}
|
}
|
||||||
ctx = ctx.__proto__;
|
ctx = ctx.__proto__;
|
||||||
let b2 = list(c_block2);
|
const b2 = list(c_block2);
|
||||||
let txt2 = ctx['iter'];
|
let txt2 = ctx['iter'];
|
||||||
return block1([txt2], [b2]);
|
return block1([txt2], [b2]);
|
||||||
}
|
}
|
||||||
@@ -426,9 +426,9 @@ exports[`t-set t-set outside modified in t-foreach increment-before operator 1`]
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-set t-set should reuse variable if possible 1`] = `
|
exports[`t-set t-set should reuse variable if possible 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { isBoundary, withDefault, setContextValue, prepareList, withKey } = helpers;
|
let { isBoundary, withDefault, setContextValue, prepareList, withKey } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
@@ -439,39 +439,39 @@ exports[`t-set t-set should reuse variable if possible 1`] = `
|
|||||||
ctx[isBoundary] = 1
|
ctx[isBoundary] = 1
|
||||||
setContextValue(ctx, \\"v\\", 1);
|
setContextValue(ctx, \\"v\\", 1);
|
||||||
ctx = Object.create(ctx);
|
ctx = Object.create(ctx);
|
||||||
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['list']);
|
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['list']);;
|
||||||
for (let i1 = 0; i1 < l_block2; i1++) {
|
for (let i1 = 0; i1 < l_block2; i1++) {
|
||||||
ctx[\`elem\`] = v_block2[i1];
|
ctx[\`elem\`] = v_block2[i1];
|
||||||
ctx[\`elem_index\`] = i1;
|
ctx[\`elem_index\`] = i1;
|
||||||
let key1 = ctx['elem_index'];
|
const key1 = ctx['elem_index'];
|
||||||
let txt1 = ctx['v'];
|
let txt1 = ctx['v'];
|
||||||
setContextValue(ctx, \\"v\\", ctx['elem']);
|
setContextValue(ctx, \\"v\\", ctx['elem']);
|
||||||
c_block2[i1] = withKey(block3([txt1]), key1);
|
c_block2[i1] = withKey(block3([txt1]), key1);
|
||||||
}
|
}
|
||||||
let b2 = list(c_block2);
|
const b2 = list(c_block2);
|
||||||
return block1([], [b2]);
|
return block1([], [b2]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-set t-set with content and sub t-esc 1`] = `
|
exports[`t-set t-set with content and sub t-esc 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { isBoundary, withDefault, LazyValue } = helpers;
|
let { isBoundary, withDefault, LazyValue } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
||||||
|
|
||||||
function value1(ctx, node, key = \\"\\") {
|
function value1(ctx, node, key = \\"\\") {
|
||||||
let b3 = text(ctx['beep']);
|
const b3 = text(ctx['beep']);
|
||||||
let b4 = text(\` boop\`);
|
const b4 = text(\` boop\`);
|
||||||
return multi([b3, b4]);
|
return multi([b3, b4]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
ctx = Object.create(ctx);
|
ctx = Object.create(ctx);
|
||||||
ctx[isBoundary] = 1
|
ctx[isBoundary] = 1
|
||||||
ctx[\`setvar\`] = new LazyValue(value1, ctx, node);
|
ctx[\`setvar\`] = new LazyValue(value1, ctx, this, node, key);
|
||||||
let txt1 = ctx['setvar'];
|
let txt1 = ctx['setvar'];
|
||||||
return block1([txt1]);
|
return block1([txt1]);
|
||||||
}
|
}
|
||||||
@@ -479,9 +479,9 @@ exports[`t-set t-set with content and sub t-esc 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-set t-set with t-value (falsy) and body 1`] = `
|
exports[`t-set t-set with t-value (falsy) and body 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { isBoundary, withDefault, setContextValue, LazyValue, safeOutput } = helpers;
|
let { isBoundary, withDefault, setContextValue, LazyValue, safeOutput } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
@@ -497,19 +497,19 @@ exports[`t-set t-set with t-value (falsy) and body 1`] = `
|
|||||||
ctx[isBoundary] = 1
|
ctx[isBoundary] = 1
|
||||||
setContextValue(ctx, \\"v3\\", false);
|
setContextValue(ctx, \\"v3\\", false);
|
||||||
setContextValue(ctx, \\"v1\\", 'before');
|
setContextValue(ctx, \\"v1\\", 'before');
|
||||||
ctx[\`v2\`] = withDefault(ctx['v3'], new LazyValue(value1, ctx, node));
|
ctx[\`v2\`] = withDefault(ctx['v3'], new LazyValue(value1, ctx, this, node, key));
|
||||||
setContextValue(ctx, \\"v1\\", 'after');
|
setContextValue(ctx, \\"v1\\", 'after');
|
||||||
setContextValue(ctx, \\"v3\\", true);
|
setContextValue(ctx, \\"v3\\", true);
|
||||||
let b3 = safeOutput(ctx['v2']);
|
const b3 = safeOutput(ctx['v2']);
|
||||||
return block1([], [b3]);
|
return block1([], [b3]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-set t-set with t-value (truthy) and body 1`] = `
|
exports[`t-set t-set with t-value (truthy) and body 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { isBoundary, withDefault, setContextValue, LazyValue, safeOutput } = helpers;
|
let { isBoundary, withDefault, setContextValue, LazyValue, safeOutput } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||||
@@ -525,22 +525,45 @@ exports[`t-set t-set with t-value (truthy) and body 1`] = `
|
|||||||
ctx[isBoundary] = 1
|
ctx[isBoundary] = 1
|
||||||
setContextValue(ctx, \\"v3\\", 'Truthy');
|
setContextValue(ctx, \\"v3\\", 'Truthy');
|
||||||
setContextValue(ctx, \\"v1\\", 'before');
|
setContextValue(ctx, \\"v1\\", 'before');
|
||||||
ctx[\`v2\`] = withDefault(ctx['v3'], new LazyValue(value1, ctx, node));
|
ctx[\`v2\`] = withDefault(ctx['v3'], new LazyValue(value1, ctx, this, node, key));
|
||||||
setContextValue(ctx, \\"v1\\", 'after');
|
setContextValue(ctx, \\"v1\\", 'after');
|
||||||
setContextValue(ctx, \\"v3\\", false);
|
setContextValue(ctx, \\"v3\\", false);
|
||||||
let b3 = safeOutput(ctx['v2']);
|
const b3 = safeOutput(ctx['v2']);
|
||||||
return block1([], [b3]);
|
return block1([], [b3]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-set t-set, t-if, and mix of expression/body lookup, 1 1`] = `
|
exports[`t-set t-set, multiple t-ifs, and a specific configuration 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { isBoundary, withDefault, setContextValue } = helpers;
|
let { isBoundary, withDefault, setContextValue } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><block-child-0/><block-text-0/></div>\`);
|
let block1 = createBlock(\`<p><div><span>First div</span></div><div><block-child-0/></div></p>\`);
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
ctx = Object.create(ctx);
|
||||||
|
ctx[isBoundary] = 1
|
||||||
|
let b2;
|
||||||
|
if (ctx['flag']) {
|
||||||
|
setContextValue(ctx, \\"bouh\\", 2);
|
||||||
|
}
|
||||||
|
if (!ctx['flag']) {
|
||||||
|
b2 = text(\`Second\`);
|
||||||
|
}
|
||||||
|
return block1([], [b2]);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`t-set t-set, t-if, and mix of expression/body lookup, 1 1`] = `
|
||||||
|
"function anonymous(app, bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
let { isBoundary, withDefault, setContextValue } = helpers;
|
||||||
|
|
||||||
|
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
ctx = Object.create(ctx);
|
ctx = Object.create(ctx);
|
||||||
@@ -557,12 +580,12 @@ exports[`t-set t-set, t-if, and mix of expression/body lookup, 1 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-set t-set, t-if, and mix of expression/body lookup, 2 1`] = `
|
exports[`t-set t-set, t-if, and mix of expression/body lookup, 2 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { isBoundary, withDefault, setContextValue } = helpers;
|
let { isBoundary, withDefault, setContextValue } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/><block-child-0/><block-text-0/></div>\`);
|
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
ctx = Object.create(ctx);
|
ctx = Object.create(ctx);
|
||||||
@@ -579,9 +602,9 @@ exports[`t-set t-set, t-if, and mix of expression/body lookup, 2 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-set t-set, t-if, and mix of expression/body lookup, 3 1`] = `
|
exports[`t-set t-set, t-if, and mix of expression/body lookup, 3 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { isBoundary, withDefault, setContextValue } = helpers;
|
let { isBoundary, withDefault, setContextValue } = helpers;
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
@@ -600,9 +623,9 @@ exports[`t-set t-set, t-if, and mix of expression/body lookup, 3 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-set value priority (with non text body 1`] = `
|
exports[`t-set value priority (with non text body 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { isBoundary, withDefault, LazyValue } = helpers;
|
let { isBoundary, withDefault, LazyValue } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
||||||
@@ -615,7 +638,7 @@ exports[`t-set value priority (with non text body 1`] = `
|
|||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
ctx = Object.create(ctx);
|
ctx = Object.create(ctx);
|
||||||
ctx[isBoundary] = 1
|
ctx[isBoundary] = 1
|
||||||
ctx[\`value\`] = withDefault(1, new LazyValue(value1, ctx, node));
|
ctx[\`value\`] = withDefault(1, new LazyValue(value1, ctx, this, node, key));
|
||||||
let txt1 = ctx['value'];
|
let txt1 = ctx['value'];
|
||||||
return block1([txt1]);
|
return block1([txt1]);
|
||||||
}
|
}
|
||||||
@@ -623,9 +646,9 @@ exports[`t-set value priority (with non text body 1`] = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-set value priority 1`] = `
|
exports[`t-set value priority 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
let { isBoundary, withDefault, setContextValue } = helpers;
|
let { isBoundary, withDefault, setContextValue } = helpers;
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
||||||
|
|||||||
@@ -1,119 +1,119 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`qweb t-tag can fallback if falsy tag 1`] = `
|
exports[`qweb t-tag can fallback if falsy tag 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = tag => createBlock(\`<\${tag || 'fallback'}/>\`);
|
let block1 = tag => createBlock(\`<\${tag || 'fallback'}/>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let tag1 = ctx['tag'];
|
const tag1 = ctx['tag'];
|
||||||
return toggler(tag1, block1(tag1)());
|
return toggler(tag1, block1(tag1)());
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`qweb t-tag can update 1`] = `
|
exports[`qweb t-tag can update 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = tag => createBlock(\`<\${tag || 't'}/>\`);
|
let block1 = tag => createBlock(\`<\${tag || 't'}/>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let tag1 = ctx['tag'];
|
const tag1 = ctx['tag'];
|
||||||
return toggler(tag1, block1(tag1)());
|
return toggler(tag1, block1(tag1)());
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`qweb t-tag simple usecases 1`] = `
|
exports[`qweb t-tag simple usecases 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = tag => createBlock(\`<\${tag || 't'}/>\`);
|
let block1 = tag => createBlock(\`<\${tag || 't'}/>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let tag1 = 'div';
|
const tag1 = 'div';
|
||||||
return toggler(tag1, block1(tag1)());
|
return toggler(tag1, block1(tag1)());
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`qweb t-tag simple usecases 2`] = `
|
exports[`qweb t-tag simple usecases 2`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = tag => createBlock(\`<\${tag || 't'}>text</\${tag || 't'}>\`);
|
let block1 = tag => createBlock(\`<\${tag || 't'}>text</\${tag || 't'}>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let tag1 = ctx['tag'];
|
const tag1 = ctx['tag'];
|
||||||
return toggler(tag1, block1(tag1)());
|
return toggler(tag1, block1(tag1)());
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`qweb t-tag with multiple attributes 1`] = `
|
exports[`qweb t-tag with multiple attributes 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = tag => createBlock(\`<\${tag || 't'} class=\\"blueberry\\" taste=\\"raspberry\\">gooseberry</\${tag || 't'}>\`);
|
let block1 = tag => createBlock(\`<\${tag || 't'} class=\\"blueberry\\" taste=\\"raspberry\\">gooseberry</\${tag || 't'}>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let tag1 = ctx['tag'];
|
const tag1 = ctx['tag'];
|
||||||
return toggler(tag1, block1(tag1)());
|
return toggler(tag1, block1(tag1)());
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`qweb t-tag with multiple child nodes 1`] = `
|
exports[`qweb t-tag with multiple child nodes 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = tag => createBlock(\`<\${tag || 't'}> pear <span>apple</span> strawberry </\${tag || 't'}>\`);
|
let block1 = tag => createBlock(\`<\${tag || 't'}> pear <span>apple</span> strawberry </\${tag || 't'}>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let tag1 = ctx['tag'];
|
const tag1 = ctx['tag'];
|
||||||
return toggler(tag1, block1(tag1)());
|
return toggler(tag1, block1(tag1)());
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`qweb t-tag with multiple t-tag in same template 1`] = `
|
exports[`qweb t-tag with multiple t-tag in same template 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block1 = tag => createBlock(\`<\${tag || 't'}><block-child-0/></\${tag || 't'}>\`);
|
let block1 = tag => createBlock(\`<\${tag || 't'}><block-child-0/></\${tag || 't'}>\`);
|
||||||
let block2 = tag => createBlock(\`<\${tag || 't'}>baz</\${tag || 't'}>\`);
|
let block2 = tag => createBlock(\`<\${tag || 't'}>baz</\${tag || 't'}>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let tag1 = ctx['outer'];
|
const tag1 = ctx['outer'];
|
||||||
let tag2 = ctx['inner'];
|
const tag2 = ctx['inner'];
|
||||||
let b2 = toggler(tag2, block2(tag2)());
|
const b2 = toggler(tag2, block2(tag2)());
|
||||||
return toggler(tag1, block1(tag1)([], [b2]));
|
return toggler(tag1, block1(tag1)([], [b2]));
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`qweb t-tag with multiple t-tag in same template, part 2 1`] = `
|
exports[`qweb t-tag with multiple t-tag in same template, part 2 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(app, bdom, helpers
|
||||||
) {
|
) {
|
||||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
||||||
|
|
||||||
let block2 = tag => createBlock(\`<\${tag || 't'}>bar</\${tag || 't'}>\`);
|
let block2 = tag => createBlock(\`<\${tag || 't'}>bar</\${tag || 't'}>\`);
|
||||||
let block3 = tag => createBlock(\`<\${tag || 't'}>baz</\${tag || 't'}>\`);
|
let block3 = tag => createBlock(\`<\${tag || 't'}>baz</\${tag || 't'}>\`);
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
return function template(ctx, node, key = \\"\\") {
|
||||||
let tag1 = ctx['brother'];
|
const tag1 = ctx['brother'];
|
||||||
let b2 = toggler(tag1, block2(tag1)());
|
const b2 = toggler(tag1, block2(tag1)());
|
||||||
let tag2 = ctx['brother'];
|
const tag2 = ctx['brother'];
|
||||||
let b3 = toggler(tag2, block3(tag2)());
|
const b3 = toggler(tag2, block3(tag2)());
|
||||||
return multi([b2, b3]);
|
return multi([b2, b3]);
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user