luwes / swiss

🇨🇭Functional custom elements

Home Page:https://swiss.netlify.app/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature Request: more options when defining properties/attributes (type coercion, etc)

jpray opened this issue · comments

This is a really cool library. I do miss one major thing from LitElement which is the robust set of options it has for defining properties/attributes.

https://lit-element.polymer-project.org/guide/properties

The ones I use most are coercing certain attributes to number and boolean properties, mapping dashed attributes to camelCase properties, and defining how properties are reflected back to attributes.

Anything on the roadmap to support such features? Thanks...

thanks @jpray!

this might get added but I'm not sure if it will get directly added in the Swiss library or as an enhancer in a separate package.

Swiss does automatically add property getters/setters for observedAttributes which can be seen here: https://github.com/luwes/swiss/blob/master/packages/swiss/src/enhancers/props-to-attrs.js

Also a lot of view libraries like Preact and Lithtml can be used with just the properties of an element instead of the attributes I noticed.

So as long as you're not doing server side rendering the set value would retain its type.

Which use case do you have where the attribute is set and the property with type is needed?

Having it as a separate enhancer/package would be awesome. I was thinking of the use case of creating a library of components that you want to be able to be consumed and used within any (or no) framework, including vanilla HTML.

v2 supports this 🎉