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

Allow access to specific variables/functions #40

Open
vinyll opened this issue Mar 4, 2023 · 1 comment
Open

Allow access to specific variables/functions #40

vinyll opened this issue Mar 4, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@vinyll
Copy link
Member

vinyll commented Mar 4, 2023

A real world usecase requires to access the document, as for collecting data from a form (ex: document.querySelector('a')).

Right now document can't be accessed outside of the component class and we must still extend the Lego class to use it.
We may want to consider to make the document variable accessible.

Same issue with the component itself.
I do have a case where the component itself, as a dom element, has to modify its classList from within the component.
Using the Lego class it's as easy as this.classList but in the new version this is undefined.
We may want to consider to make the component available to the script like with a reference to it such as self, node, component or another name.

This will lead to a reserved words list that must be listed in the doc.
Currently the only reserved words are state and render.
We could either extend the list, or only add a reference to the component and call methods or properties from there.

We need to decide:

  • wether we make a list of reserved keywords or a sole access to one variable that represents the component
  • decide of these names
@vinyll vinyll added the enhancement New feature or request label Mar 4, 2023
@vinyll
Copy link
Member Author

vinyll commented Mar 7, 2023

A solution was implemented:

<script>
  const state = {name: 'bob'}

  // `constructed` is called when the component is fully ready (state and attributes are loaded, dom is rendered)
  // `this` refers to the component itself and gives access to the whole context.
  function constructed() {
    console.info(`The component ${this.nodeName} is now ready`)
  }
</script>

It would result with the following reserved words:

  • 2 for internal purpose: h, Component
  • 3 for the user: state, constructed and render

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant