Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] parser: add support for user-space directives #1651

Merged
merged 2 commits into from
Nov 25, 2024

Conversation

jpp-odoo
Copy link
Contributor

@jpp-odoo jpp-odoo commented Nov 7, 2024

This commit adds the support for user-space directives. To use the user-space directive, an Object of functions needs to be configured on the owl APP:

 new App(..., {
    userDirectives: {
     my-user-directive: function (el, value) {
            el.setAttribute("t-on-click", value);
            return el;
       }
   }
  });

The functions will be called when a user directive with the name of the function is found. The original element will be replaced with the one returned by the function.
This :

<div t-user-my-user-directive="click" />

will be replace by :

<div t-on-click="value"/>

issue : #1650

@jpp-odoo jpp-odoo force-pushed the master-add_user_directives-jpp branch 3 times, most recently from e0e4d78 to f2eab03 Compare November 7, 2024 14:13
@sdegueldre
Copy link
Contributor

If the user directives are defined on the app, doesn't that mean the entire feature is unavailable when precompiling?

@jpp-odoo jpp-odoo force-pushed the master-add_user_directives-jpp branch from f2eab03 to 53807d8 Compare November 12, 2024 14:21
@ged-odoo ged-odoo marked this pull request as ready for review November 12, 2024 15:38
tests/app/app.test.ts Outdated Show resolved Hide resolved
@jpp-odoo jpp-odoo force-pushed the master-add_user_directives-jpp branch from 6a19f9e to 545cb32 Compare November 13, 2024 10:42
@jpp-odoo jpp-odoo force-pushed the master-add_user_directives-jpp branch 2 times, most recently from 9a824a6 to 7c17b7f Compare November 21, 2024 13:17
src/compiler/parser.ts Outdated Show resolved Hide resolved
src/compiler/parser.ts Outdated Show resolved Hide resolved
src/compiler/parser.ts Outdated Show resolved Hide resolved
@jpp-odoo jpp-odoo force-pushed the master-add_user_directives-jpp branch 3 times, most recently from 987429c to 3c34085 Compare November 21, 2024 14:32
This commit adds the support for custom directives. To use the
custom directive, an Object of functions needs to be configured on
the owl APP:
```js
 new App(..., {
    customDirectives: {
     test_directive: function (el, value) {
            el.setAttribute("t-on-click", value);
            return el;
       }
   }
  });
```
The functions will be called when a custom directive with the name of the
function is found. The original element will be replaced with the one
returned by the function.
This :
```xml
<div t-custom-test_directive="click" />
```
will be replace by :
```xml
<div t-on-click="value"/>
```

issue : #1650
@jpp-odoo jpp-odoo force-pushed the master-add_user_directives-jpp branch from 3c34085 to a96815f Compare November 21, 2024 14:39
This commit, add a new configuration on the App: globalValues.
It's a global object of elements available at compilations.

For instance:
```js
    const app = new App(SomeComponent, {
      globalValues: {
        plop: (string: any) => {
          steps.push(string);
        },
      },
    });
```

The plop function will be available at the compilation, so it can be
used on the templates :
```xml
<div t-on-click="() => __globals__.plop('click')" class="my-div"/>
```
@jpp-odoo jpp-odoo force-pushed the master-add_user_directives-jpp branch from a96815f to a903ccd Compare November 25, 2024 08:55
@ged-odoo ged-odoo merged commit 6b24864 into master Nov 25, 2024
2 checks passed
@ged-odoo ged-odoo deleted the master-add_user_directives-jpp branch November 25, 2024 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants