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

How do I tap into connected / disconnected lifecycle methods ? #218

Closed
mykulyak opened this issue Nov 19, 2023 · 2 comments
Closed

How do I tap into connected / disconnected lifecycle methods ? #218

mykulyak opened this issue Nov 19, 2023 · 2 comments
Labels
properties Applies to the property definition

Comments

@mykulyak
Copy link

Hi,

I am writing an element wrapping Monaco editor (+ doing extra stuff related to my app).
To set up the editor I need somehow to hook into 'connectedCallback'. However, I don't see a possibility to do this.

Can you guide me ? Here's the "more or less" what I'm trying to achieve.

@mykulyak mykulyak changed the title Lifecycle methods ? How do I tap into connected / disconnected lifecycle methods ? Nov 19, 2023
@smalluban
Copy link
Contributor

smalluban commented Nov 20, 2023

Every property supports connect() callback, which is triggered within the connectedCallback of the Custom Elements API.

You can try to do something like this:

{
  tag: 'my-monaco-editor',
  editor: {
    value: undefined,
    connect: (host, key) => {
      host[key] = host[key] || monaco.editor.create(host.render().querySelector('div'), {
	value: ['function x() {', '\tconsole.log("Hello world!");', '}'].join('\n'),
	language: 'javascript'
      });
    },
  },
  render: () => html`<div></div>`,
};

@smalluban smalluban added the properties Applies to the property definition label Nov 27, 2023
@smalluban
Copy link
Contributor

I am not sure if I can help more in that subject. There is also an explanation of the concept in the docs here: https://hybrids.js.org/#/component-model/structure?id=connect

Feel free to re-open if you need more help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
properties Applies to the property definition
Development

No branches or pull requests

2 participants