Open larkintuckerllc opened 5 years ago
@larkintuckerllc this is a great question. Due to the uncertainty of the standardization of decorators, we have decided to restrict the decorators allowed by our LWC compiler until we are certain about the future of decorators. At the moment, I don't see a way to manipulate the build step to have your own decorators.
Coincidentally, I just bumped into an interesting JavaScript pattern that potentially provides a pattern for cross-cutting concerns with LWC. The beauty of the pattern is that once you see it, it is super simple and obvious. http://justinfagnani.com/2015/12/21/real-mixins-with-javascript-classes/
Looking at using this pattern with some real-world examples, e.g., redux and apollo client
yes @larkintuckerllc that works fine with LWC, in fact we have some folks using it, but, we do not recommend it if you are planning to share your component thru salesforce platform. Until we can land the syntax in Javascript (we are working with google folks on that), we have no way to do a full static analysis of the component, and therefore, part of the referencial integrity aspect of the platform cannot be preserved for those components.
FYI... Through an effort to incorporate Apollo Client, ended up learning about an officially supported pattern for cross-cutting concerns in LWC; just not well documented. Here is an article on the topic:
I am trying to figure out how to implement cross-cutting concerns in LWC and thought to use decorators; LWC is class-based and this one such way of doing this.
But, when I went implement my own decorator, I get the following error message.
"Invalid decorator usage. Supported decorators (api, wire, track) should be imported from "lwc"
I either would like to see a good example of implementing a cross-cutting concern, like HOC, RenderProps, or Hooks in React. Again, I thought decorators were the answer; so enabling them more generally might be the answer?