-
Notifications
You must be signed in to change notification settings - Fork 790
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
feat(@Mixin): new decorator #2921
Conversation
…mods. Test transpiler - can cope with multiple files.
'omit' and 'pick' can now be used to filter real class members from the host component.
…. Added e2e & karma tests.
Allows for custom elements build to modify how CustomEvents, addEventListener and removeEventListeners are called.
…mods. Test transpiler - can cope with multiple files.
'omit' and 'pick' can now be used to filter real class members from the host component.
…. Added e2e & karma tests.
… into feat-mixin-decorator # Conflicts: # CHANGELOG.md # package-lock.json # package.json
To anyone interested, I built out a temporary package of all my recent PRs (and may add some other user's PRs in future too) - just until Stencil becomes more active. This includes: You can test it out with little disruption by just swapping out any reference to
becomes
I will keep this package in-sync with @stencil/core master up until the relevant PRs get accepted or rejected. |
Thank you @johnjenkins for your hard work, you legend! Your PRs are all highly useful features! |
feat(souremaps): bring in mixin source into sourceMaps
This PR is truly impressive and I really don't want to be a party pooper but here comes the but As cool as this PR might be I don't believe Mixins are the way to go. Stencil would only be repeating a very costly mistake the react community tried and already failed at. The article goes in detail on why Mixins might cause headaches on large codebases and those cases are pretty applicable to a Stencil codebase. |
hey @UnGaucho! Thanks for the thoughts and feedback, really appreciated.
A mixin cannot call anything on a component. The cascade is one way. At the end of the day the generated JS is not dynamic from mixin to component - it is simply as if the mixin is part of the component.
Once again, not a problem. Because we define in typescript what class is extending from which Mixin class (and even which Mixin members from where), intellisense takes care of the rest. I click on the 'method' that isn't defined in my class and it takes me to the Mixin file / line where it is defined.
As mentioned in the readme above, I have disallowed mixin recursion / nesting for this reason.
Not in this PR they don't. Typescript won't let them :) Typescript will complain that there are name-clashes, then it is up to the developer to choose (as described ^ via Omit and Pick) which members from which classes they actually want. In this PR, not only does this make the typescript error go away, but (via static analysis) that is actually what will happen.
I cannot speculate how or what people will do with the PR, but I have tried to limit what they can do with the purposeful blocking of mixin recursion / nesting which (I believe) should help with this no end. |
Powerful enough without being a footgun. You convinced me to give it a try :)
|
I really want to see real TypeScript mixin support. |
…l source maps) run prettier
# Conflicts: # .prettierignore # package-lock.json # package.json # scripts/license.ts # scripts/release-tasks.ts # scripts/release.ts # scripts/utils/release-utils.ts # src/compiler/transpile/transpile-module.ts # src/runtime/test/fixtures/cmp-b.tsx # src/sys/node/node-sys.ts # test/browser-compile/src/utils/css-template-plugin.ts # test/karma/stencil.config.ts # test/karma/test-app/slot-fallback/karma.spec.ts # test/karma/test-app/util.ts
Hi Any update on this PR? I could really use this now! 😅 |
What is the status of this? |
@johnjenkins You think this PR will go in anytime soon? |
@perronef5-ukg no idea bud - sorry. |
Hi folks! Thanks for your interest in this PR. We’ve got it on our internal backlog to investigate the feature’s feasibility, but we haven’t made any decisions on it yet. We'd love it if you could react to the PR summary with a '👍' to give us a signal that we should reprioritize. |
# Conflicts: # package-lock.json # package.json # src/compiler/build/compiler-ctx.ts # src/compiler/transformers/transform-utils.ts # src/compiler/transpile/run-program.ts # src/compiler/transpile/transpiled-module.ts # src/declarations/stencil-private.ts # test/karma/package.json
@a-giuliano Any update on this PR? |
Thanks for checking in on this, @Perronef5. While I don't have any major updates, I can say this feature will be on our roadmap for our first quarter of 2022 (that's February - April for us). I know the community is really excited about this feature, so we really appreciate your patience! |
excited about this change tho. any news on this guys? |
Waiting from long time for this feature, any update on release? |
let's go! it's overdue |
Still April, still hoping for this one. ❤️ |
Hi everyone! Thank you all for your interest in this PR. I know in my last update I mentioned that this feature will be on our roadmap for our first quarter of 2022. Unfortunately, we haven't yet made any decisions on this PR. We recognize that a number of community members are interested in this PR, and we sincerely appreciate your patience. |
After trying to extend / mixin Stencil components I've end up here. Really looks like the solution close, do you chaps have an estimate on when / if this feature will be merged? |
After investing much more time in the whole stencil 'stack', I have come to feel that this PR is probably not the best way forward for stencil. I use my fork of stencil every day which includes the
I personally would like to see reactive controllers to be implemented within stencil. Once again, would not solve shared properties but would solve many other pain points. I thank all those who gave kind words of encouragement and apologise for any disappointment caused. |
Much of Stencil's secret sauce comes from 'static analysis'; using the ts compiler to pull out meta from components.
With this meta, stencil can do lots of cool stuff. Make an ultra light, lazy loading layer. Make framework specific wrappers, and allow devs to make their own wrappers!
But a reliance on static analysis does come at a cost. How could the compiler derive static meta data from components that could endlessly
extend
for example? For this reason, extending components is not allowed in Stencil.Because I'm a stupid sadist, I decided to see if I could find a solution: A new
@Mixin
decorator.With
@Mixin
I leaned further onto static analysis in quite a naive way. Class members (and supporting statements) are simply merged together with the host, kinda like a cascade.Usage
Notes:
@Mixin
order is important! - mixin members are merged like a cascade with the host. So any name clashes (variables / methods) between Base1, Base2 and the Host will be overwritten in that order.Omit
andPick
e.g.export interface MyInput extends Omit<Base1, 'offendingMethod'>, Base2 {}
Omit
orPick
to do just that - cherry pick incoming members.@Mixin
nesting / recursion and trying to do so will throw an error. e.g.^ Error. This could be open for debate.
@Component
meta is mixed in. Inluding scope, shadow, styleUrl/s and assetDirs.When writing tests I focused on 3 main use cases:
And that's about it. I've written quite a lot of tests for this new behaviour and all seems to be working well, but there are bound to be things I've missed.
I would urge anyone who is remotely interested in this, please try it out and give feedback. This is quite a big change and it will need more eyes on it to have a chance at being accepted.
If this gets some traction, I will loop back over this when source maps are merged < I think they would be helpful*
*I have now made the necessary changes: mixins will work as expected with source maps
Fixes: #2844
Fixes: #2559
Fixes: #1127
Fixes: #1060
Fixes: #172
Pull request checklist
Please check if your PR fulfills the following requirements:
npm run build
) was run locallyPull request type
Please check the type of change your PR introduces:
What is the current behavior?
There is no easy way to extend from other classes.
What is the new behavior?
As described above.
Does this introduce a breaking change?
Manual Testing
npm build
andnpm link
from the root of the repo directory (on this branch)npm init stencil
@Mixin
decorated components, with multiple diffrent type of mixin classes.@Mixin
components to reload 👍