-
Notifications
You must be signed in to change notification settings - Fork 788
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
Feature Request: Custom Attribute Parsing #1691
Comments
I couldn't agree more, especially for JSON attributes. |
Definitely agree with this. In the meantime, I've adopted this not overly ideal pattern:
What I would like to see from the Stencil team for parsing complex types would be something like this:
Where
This would allow flexibility across the board for a whole range of options. However, looking at the stencil code, the Happy to work on the PR if necessary to get this in. |
This comes up a lot, and although it's an unpopular opinion, I'll reiterate what I said here:
Essentially, this feature will encourage a bad practice that results in slow components, particularly those handling large data sets and frequently changing attributes. |
Does it? I'm not familiar with the internals of stencil but what I'd expect is that this happens on the attributeChangedCallback level. Properties are always of the concrete type and could have simple setters, only changing the attribute itself would cause parsing. It would be an anti-pattern to pass dynamic data through an attribute versus a property but this is primarily for static usage outside of the stencil VDOM. |
To add my 2 cents, it would be really convenient if you could set attribute converters/serializers if you want to be able to specify almost-primitive values like dates, such as <my-calendar selected="2021-05-05"></my-calendar> Currently, Note that in HTML it's actually not uncommon to have more complex attribute syntax than just string or number. Just think of In case of |
are |
@johnjenkins In my case, that could work. At least it would be a lot better than the whole mess I described above, including checks for not updating unchanged values. (And it's better than 'unknown class node' 😄). One thing I don't know how to handle properly would be uglies like |
This is an interesting idea! I'm going to label this for us to review later. |
Thanks for the issue! This issue is being closed due to inactivity. If this is still an issue with the latest version of Stencil, please create a new issue and ensure the template is fully filled out. Thank you for using Stencil! |
Hey ionitron-bot, we didn't mean to close this. Bad bot! |
Relates to: #2533 |
Resolving #1359 would remove the need for this |
Stencil version:
I'm submitting a:
[ ] bug report
[x ] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://stencil-worldwide.herokuapp.com/ or https://forum.ionicframework.com/
Current behavior:
Stencil only seems to provide string and boolean values via attributes.
The current work around seems to be setting an intermediate property and using watch to set another property which is not ideal. https://medium.com/@gilfink/using-complex-objects-arrays-as-props-in-stencil-components-f2d54b093e85
Expected behavior:
A prop should have a custom conversion function that determines how attributes convert into property value, and also how properties reflect into attributes.
Steps to reproduce:
Example: I would like a component that takes an ISO Date String as an attribute but the property should be the actual date object. Maybe something similar to:
Example: I would like to use a JSON string and convert it into a complex object.
Example: I would like to take a comma delimited list and convert it into an array.
Other information:
Related issue: #1155
The related issue raises performance concerns with built-in object conversion but is that still a problem if the conversion is user provided?
If not considered, is the current work around the best-case for this pattern? Are there other alternatives?
The text was updated successfully, but these errors were encountered: