Skip to content

Mixins and the applyMixins function? #3505

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

Closed
blendsdk opened this issue Jun 13, 2015 · 4 comments
Closed

Mixins and the applyMixins function? #3505

blendsdk opened this issue Jun 13, 2015 · 4 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@blendsdk
Copy link

Hi,

Since the compiler can distinguish between a class being used as an interface, what is the reason the compiler does not automatically emit "applyMixins" at the end of the compilation cycle? It there a particular reason for this?

Regards,
Gevik.

@danquirk
Copy link
Member

Are you asking why the current behavior is this?

class Foo { 
   doStuff() { return 'hi'; }
}
class Bar implements Foo { // error here, but should automatically mixin doStuff?
}

@mhegazy mhegazy added the Question An issue which isn't directly actionable in code label Jun 18, 2015
@benliddicott
Copy link

I think the question is, why can't we do this:

class Foo { 
   doStuff() { return 'hi'; }
}
 class Yung { 
   doStuff2() { return 'hi'; }
}
// FAILS
class Bar extends Foo, Yung { // error here, but should automatically mixin doStuff?
}

Currently we do:

// SUCCEEDS

class Bar extends Foo implements Yung {
constructor(){super();}
}
applyMixins(Bar, [Yung]);

I think @blendsdk is asking why you can't extend two classes, and the compiler emit the applyMixins call automatically, to implicitly turn the FAILS example into the SUCCEEDS example.

@danquirk
Copy link
Member

Because the type system is structural the extends and implements clauses are generally best thought of as statements of intent and a desire to have the compiler validate you have done what you intended.

At this point changing the behavior of these statements would be an enormous breaking change so it's not something we'd do without new syntax of some sort.

@benliddicott
Copy link

@danquirk thanks for the note. I get changing the behaviour of implements would be a breaking change. But allowing multiple extends with different semantics for the second onwards, would not, since these are currently syntax errors. (Actually I am not advocating this, I am advocating #3854 as a different route to the same goal. I just picked this issue up while looking for related issues. I am just trying to clarify what I take to be the OP's point.)

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

4 participants