3 ms·
i really wish it didn’t rely on decorators so heavily.
by teg4n_ 3y ago
i really wish it didn’t rely on decorators so heavily.
- spankalee 3y agoWhy? We support a non-decorator API (the static properties block), but I don't think it's particularly ergonomic compared to decorators which allow us to declarative modify standard class fields. Decorators work better with type systems, which don't have to be taught about our bespoke property declaration convention, and they're coming natively to JS so they won't require compilers.
- teg4n_ 3y agoAdding decorators to JS is a mistake but thats just my opinion. I don’t like them because they make it more difficult for me to understand what is actually happening when you run the code that is decorated. I have to go and read the decorator source and then it’s some metaprogramming nonsense instead of something more straightforward. It’s very possible i’m just a curmudgeon but I still find it off putting and is one of the reasons i haven’t really experimented with lit more than vaguely paying attention to it.
- spankalee 3y agoMetaprogramming can be applied in ways that makes code hard to reason about, but that doesn't mean all metaprogramming is that way. Decorators, especially the newly standardized decorators, provide a structured for of metadata where the possible actions are limited. Decorators can basically only replace the decorated class member with another member of the same kind: replace an accessor, or a method. This should make things easier to reason about. The Lit @property() decorator for instance wraps the decorated setter with one that calls `this.requestUpdate()` - that's it. The alternative is writing all the boilerplat by hand, which most users don't want to do (but is possible) or the adhoc metaprogramming systems that are fairly popular now, and I think those are much harder to reason about.
- teg4n_ 3y agoI mean couldn’t lit have just exposed a method like this.setReactiveProperty that calls this.requestUpdate and sets the property? The need for decorators seems because the api was designed to use decorators not because they are particularly necessary for this sort of thing
- spankalee 3y agoThat wouldn't be interoperable. Lots of frameworks already have the ability to set properties on elements declaratively in templates. By using setters we work with their data binding system without hanging to teach them about Lit-specific APIs.
- teg4n_ 3y agook, that makes sense. thanks for the explanation