-
Notifications
You must be signed in to change notification settings - Fork 434
check reflectionIsSupported in decorator runtime #350
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
In that case, why is it a problem for you that vue-class-component does not handle meta data? If you want vue-class-component to handle it, you can simply add import statement for |
Yeah, you're almost absolutely right!
The case I'm talking about is when u need to decorate a single component, in one place, temporary (for some developments staff, tests, logs), to check something, and you dont have (and dont need) reflect-metadata lib. OR, we can process reflect dynamically, as I've proposed in this PR. |
You can import the polyfill as webpack (or any bundler) entry script or adding import statement in the very beginning in your entry script. You don't need to import it by every appearance of vue-class-component import. And I see it is a common way to load polyfill in my experience. |
I'm talking about the case, where I don't need this polyfill in production and I don't want to edit my webpack config just because of reflect metadata. I need this metadata polyfill only when my own decorator is used, and it is used like:
With your proposition it looks like that:
Or we can make dynamic configuration with tree-shaking etc., which is obviously an overhead for a simple stuff I'm talking about. My decorator bring this dep with himself, but it SHOULDN'T be imported in entry point or moved to separate entrypoint, as long as it dependencies, like reflect metadata (to keep it simple). |
What do you mean by In any cases, if you want to tree-shake If you really want to split your chunks even with // ./class-component.js
import 'reflect-metadata'
import Component from 'vue-class-component'
export default Component import Vue from 'vue'
import Component from '@/class-component'
@Component
export default MyComp extends Vue {
} |
As an example: I have a tool, which does nothing except a dozens of logs. It is very specific and rarely-needed. It is used in following way:
// /components/.../DeepComponent.vue
import Vue from 'vue';
import Component from 'vue-class-component';
@Component
export default class DeepComponent extends Vue {
}
a) Expected: // /components/.../DeepComponent.vue
import Vue from 'vue';
import Component from 'vue-class-component';
import MyDecorator from 'my-lib';
@MyDecorator
@Component
export default class DeepComponent extends Vue {
} b) Actual: npm install reflect-metadata Then, import it on a top-level module // /components/App.vue
import 'reflect-metadata';
@Component
export default class App extends Vue {
} And only after, use it as expected. Also, lib should have notification, something like
|
Ah I finally get what you mean. Thank you for clarifying it!
No it shouldn't, as it is totally optional. |
Thanks again! 💚 |
Thanks! |
In this commit,
reflectionIsSupported
has been refactored from(Reflect && Reflect.defineMetadata) !== undefined
totypeof Reflect !== undefined && Reflect.defineMetadata
.But also, from decorator runtime (function) check to one-time check on
import
(var). Which caused a small issue:I've faced a situation, where one of my dependencies brings
reflect-metadata
as it's own dependency, and being imported aftervue-class-component
package.When decorating is applied, metadata already treated as unsupported and metadata is lost.
The only way to solve this is to import
reflect-metadata
before our mainApp
module (in other words, before decorated are applied).But in my case, I don't need
reflect-metadata
, except for this dependency. Even more, this dependency is used only during development and not imported in production.This PR can solve this issue.