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

Property setters/getters for interop #2

Open
robdodson opened this issue Oct 24, 2016 · 0 comments
Open

Property setters/getters for interop #2

robdodson opened this issue Oct 24, 2016 · 0 comments

Comments

@robdodson
Copy link

For Custom Elements to work well in other frameworks like Angular and React (or even just in a regular old vanilla HTML page) it's useful if they follow the conventions of native tags. This means, attributes and properties to send data in, and events to get data out/listen for changes. The set() and get() APIs make this a bit difficult because it means the consumer of the components has to know to call those methods. In other words, the implementation is leaking to the outside world.

Instead of explicit set() api (which I'm assuming triggers rendering), you might have the element author define an object that specifies the properties of their element and install setters for those properties. The setters could then call render anytime they update. The one catch is if a user is mutating data instead of passing in a new value (like pushing to an array or modifying an object subproperty). In that case, the setters would not be called and you'd miss out on rendering. To work around this, I think a good best practice for Custom Elements might be to encourage folks to always pass complex data by copy, instead of by reference.

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

No branches or pull requests

1 participant