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.

support for class-factory mixins

See original GitHub issue

The following plain JS doesn’t work:

function Foo(Base) {
  return class Foo extends Base {
    foo() { console.log('foo') }
  }
}

class Bar {
  bar() { console.log('bar') }
}

class Baz extends Foo(Bar) {
  baz() { console.log('baz') }
}

const b = new Baz
b.foo()
b.bar()
b.baz()

try link

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:5
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
trusktrcommented, Jun 6, 2020

As another example of the current complexity, here’s my Mixin implementation (which itself isn’t that long) and the unit tests (but the README has better more practical examples). But it gets complicated at the usage sites, for example.

It is riddled with issues. For example, in that last example, if I change the lines

const _Base = Constructor(Base)
const Parent = Observable.mixin(TreeNode.mixin(_Base))

to

const Parent = Observable.mixin(TreeNode.mixin(Constructor(Base)))

it completely breaks (for no intuitive reason). The Constructor(Base) constructor expression must be assigned to a new variable first, for it to work.

It’s little things like that, plus all the other issues like having to follow the patterns with the mapped typed that you see in that example, that make it all too complicated compared to plain JS.

1reaction
web-padawancommented, Jul 15, 2020

I’m also interested in class mixins, and the developer experience with TypeScript has been quite painful in this regard.

Here is one more issue which wasn’t mentioned above: microsoft/TypeScript#17744. See my comment there for an overview of techniques that I tried, including the workaround for using protected methods.

Generally, this might be beneficial for web components libraries, such as Lion, Vaadin, Spectrum and others. We have to use class mixins when creating custom elements classes that extend HTMLElement.

Read more comments on GitHub >

github_iconTop Results From Across the Web

feature request: support for mixins composed from other ...
I'm porting JavaScript code to TypeScript, and the JavaScript makes great use of mixins (including composing new mixins from other mixins), but ...
Read more >
Class::MixinFactory - Class Factory with Selection of Mixins ...
Factories support methods that control which classes they will use. The base class will be inherited from by all mixed classes. $factory -> ......
Read more >
Typescript Mixin with Class Factory - Stack Overflow
I have a Class factory that has been derived from creating a class using typescript with specific fields, but I'd like to do...
Read more >
Multiple inheritance (not class-factory mixins). Will it ever be a ...
I don't like class-factory mixins, because they require wrapping classes in functions. Therefore, one can not import a 3rd-party class and compose it....
Read more >
Factory(3pm) — libclass-mixinfactory-perl — Debian unstable
Class::MixinFactory::Factory - Class Factory with Selection of Mixins ... A mixin factory generates new classes at run-time which inherit ...
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