Make Components implement an Interface instead of extending VueComponent
See original GitHub issueWith J2CL when extending a class with the @JsType
annotation, then the child class must have a constructor annotated with @JsConstructor
.
Currently, Components are extending VueComponent
(which is a native @JsType
), so they would need a @JsConstructor
to compile in J2CL.
To avoid needing to create this constructor in each Component, I propose to introduce an interface that Components implement instead of extending VueComponent
.
This interface would look like this:
public interface IsVueComponent {
default VueComponent asVue() {
return Js.cast(this);
}
}
This would make all Vue.js Components methods (like $emit
) or properties (like $el
) accessible in Components this way instead of directly on this
:
asVue().$emit("my-event");
This also open up the possibility of adding more idiomatic methods as default
in this interface to access attributes/elements on the Component.
Even if this is a pretty big breaking change, the migration from Beta 7 should be fairly easy as it would just require replacing all extends VueComponent
with implements IsVueComponent
.
Feedback on the name of this interface (IsVueComponent
) and this idea is welcome!
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
@adrienbaron vue() is better than asVue()
@adrienbaron Go ahead, I’m quite overloaded today 😦