Skip to content

Suggestion with Web components? #110

Description

@mistyharsh

Thank you for the great library. It has been a great experience so far.

I am trying to wrap bucklescript-tea component into web components. The initial skeleton looks like this:

import { main } from './Demo.bs.js';

// Library function to register a custom element
export function define(name, mainFn) {

    const componentClass = class extends HTMLElement {

        constructor() {
            super();
            // Attach a shadow root to the element.
            let shadowRoot = this.attachShadow({ mode: 'open' });

            mainFn(shadowRoot);
        }
    };
    customElements.define(name, componentClass);
}



// Application code
define('hello-world', main);

I was wondering if you have any suggestions for observing props in a typesafe manner. Currently, I am thinking of manually accepting the list of prop string to be observed and adding setter for each prop. Something like this:

define('hello-world', main, ['prop1', 'prop2']);

The plan is to either raise a custom event or call pushMessage directly from the prop setter. I am not sure if this is the right approach. Any suggestions on how I can do interoperability with JavaScript; specifically in the context of custom elements?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions