-
Notifications
You must be signed in to change notification settings - Fork 318
fixed decorators to return a property descriptor to work with babel d… #206
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
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here (e.g. What to do if you already signed the CLAIndividual signers
Corporate signers
|
I signed it! |
CLAs look good, thanks! |
Can't add decorators to our classes right now using Bable7. Does this fix that issue? |
export const property = (options?: PropertyDeclaration) => (proto: Object, | ||
name: string) => { | ||
(proto.constructor as typeof UpdatingElement).createProperty(name, options); | ||
export const property = (options?: PropertyDeclaration): FixedPropertyDecorator => (proto: Object, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to satisfy typescript (temporarily) and be consistent with how other decorators are written, this should probably return any
.
get() { return this[key]; }, | ||
set(value) { | ||
|
||
let defaultInitializer: null | (() => any) = descriptor ? descriptor!.initializer || null : null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This whole handling of the default value seems just a little messy but i can see why...
The default value really needs to be in the constructor but babel annoyingly doesn't put it there...
@43081j I found away to support all, stage-0 babel, stage-0 typescript and stage-2 babel decorators while experimenting in my own decorator project: https://github.com/mzeiher/ce-decorators/blob/master/src/stage2decorators.ts, https://github.com/mzeiher/ce-decorators/blob/master/src/prop.ts, should in include such a thing in the PR to be future proof? |
I'll have a read soon. One thing to keep in mind is that the legacy decorators babel produces are neither stage 0 nor stage 2, they are an incorrectly patched stage-0 by the looks of it: They make use of |
hehe that's the fun when using experimental features :) the same is done for stage-2 decorators, this way multiple decorators are possible which manipulates the property every decorator delegates to get/set to the previous get/set for method decorators it's just the get/set case is used but the delegate goes to the value of the previous PropertyDescriptor which holds the original function or a overidden one from another decorator (value = function(...parameter) { original.value.apply(this, [...parameter] } the delegation logic must be implemented from every decorator which patches a member or member-function so the one implementing the decorator must take care of that (if someone mixes the decorators created by you and for example own logging decorators), I'll add an example and a test for it... edit: |
cosing... implemented by the lit-element team |
…ecorators
Reference Issue
Fixes #205