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. |
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
|
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.