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

Add ability to reflect prop changes back to attributes #43

Open
patricknelson opened this issue Dec 13, 2023 · 0 comments
Open

Add ability to reflect prop changes back to attributes #43

patricknelson opened this issue Dec 13, 2023 · 0 comments
Labels
enhancement New feature or request
Milestone

Comments

@patricknelson
Copy link
Owner

patricknelson commented Dec 13, 2023

Describe the problem

Currently it's not possible to reflect prop changes in the custom element attributes.

Describe the proposed solution

Due limitations caused by the fact that svelte-retag isn't able to hook into Svelte compiler options (at least not for now), the developer must first manually enable accessors in their component like so:

<svelte:options accessors />

svelte-retag would then add a new props option (if not already present, see #13) and include a reflect option, e.g.

svelteRetag({
  component: HelloWorld,
  tagname: 'hello-world',
  props: {
    greetPerson: { reflect: true },
  }
});

Once configured, modifications to greetPerson from within the component would be reflected in the greetperson custom element attribute.

Implementation Details

  • The attribute MutationObserver should be aware of reflected changes to prevent infinite loops.

  • See if possible to automate setting of accessors option if already hooking into compiler process

  • To watch for updates, one would have to utilize the after_updates array available on the component instance, e.g.

    tag.componentInstance.$$.after_update.push(() => {
    	tag.setAttribute('greetperson', tag.componentInstance.greetPerson);
    });

Alternatives considered

None.

Importance

nice to have

@patricknelson patricknelson added the enhancement New feature or request label Dec 13, 2023
@patricknelson patricknelson changed the title Add ability to reflect props changes back to attributes Add ability to reflect prop changes back to attributes Dec 13, 2023
@patricknelson patricknelson added this to the v2 milestone May 8, 2024
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