question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make Components implement an Interface instead of extending VueComponent

See original GitHub issue

With 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:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
slavapcommented, Apr 5, 2018

@adrienbaron vue() is better than asVue()

0reactions
slavapcommented, Apr 5, 2018

@adrienbaron Go ahead, I’m quite overloaded today 😦

Read more comments on GitHub >

github_iconTop Results From Across the Web

Extending Vue.js Components
The easiest way to make a component multi-use, and thus avoid extending it, is to provide a prop which drives conditional logic in...
Read more >
Recipes to Wrap, Extend or Proxy a Vue Component - Medium
This article details some ways to create a component that extends another. We'll look at attributes, props, listeners, and slots, along with ...
Read more >
Extended interface doesn't seem to implement parent members
There are some very suspicious type assertions here: _componentGroup: this.componentGroup as IComponentGroup, _focussedComponent: this.
Read more >
Extend Vue Components in TypeScript | egghead.io
This lesson shows how you can extend and reuse logic in Vue components using TypeScript inheritance. It will take you through extending a...
Read more >
Using Vue component as options for interface extension #11927
Hi team, the extensions docs for an interface options property suggests you can use either an options object or a dedicated Vue component...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found