Quantcast
Channel: ReScript Forum - Latest posts
Viewing all articles
Browse latest Browse all 2592

Leverage ES decorators

$
0
0

It seems like a pretty tricky problem to explain something that looks similar but is different. Understanding the syntax with a JS background is just as dangerous as understanding the syntax with an OCaml background.

After all, we can’t inherit all the features of another language to support a JS framework, the choice of language is a framework-side decision. Instead, we can provide proper extension points to interop.

For example, we have PPX that can do code generation, it’s possible to make user-level integrations more similar. For example, Lit’s @customElement decorator actually:

const customElement = (tagName) => (classOrTarget, context) => {
  if (context !== undefined) {
    context.addInitializer(() => {
      customElements.define(tagName, classOrTarget));
    });
  } else {
    customElements.define(tagName, classOrTarget);
  }
};

So it can generate the same function, or even generate more efficient pre-optimized code if you want.

I know it doesn’t sound simple, but it’s all we have so far.


Viewing all articles
Browse latest Browse all 2592

Trending Articles