Skip to content
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

Mixins included multiple times #62

Open
wkeese opened this issue Jun 12, 2021 · 0 comments
Open

Mixins included multiple times #62

wkeese opened this issue Jun 12, 2021 · 0 comments

Comments

@wkeese
Copy link

wkeese commented Jun 12, 2021

Even if an inheritance chain includes a mixin multiple times, mix() should only include it once. It should also follow C3MRO as documented in https://en.wikipedia.org/wiki/C3_linearization.

However, opposite to #61, in some of my tests, a mixin is getting included multiple times. For example, MixinA in the following example is included twice:

import { mix } from "mics/src/index";

// Base class
class SimpleGreeting {
	foo () {
		console.log("SimpleGreeting foo()");
		this.textContent = "Hello world!";
	}
}

// Root mixin A.
const MixinA = mix(SimpleGreeting, Base => class extends Base {
	foo () {
		super.foo();
		console.log("Mixin A foo()");
	}
});

// Mixin B extends root mixin A.
const MixinB = mix(SimpleGreeting, MixinA, Base => class extends Base {
	foo () {
		super.foo();
		console.log("Mixin B foo()");
	}
});

// Mixin C also extends root mixin A.
const MixinC = mix(SimpleGreeting, MixinA, Base => class extends Base {
	foo () {
		super.foo();
		console.log("Mixin C foo()");
	}
});

// ExtendedGreeting extends SimpleGreeting, mixing in B and C
const ExtendedGreeting = mix(SimpleGreeting, MixinB, MixinC, Base => class extends Base {
	foo () {
		super.foo();
		console.log("ExtendedGreeting foo()");
	}
});

// "new" doesn't work here, despite documentation saying that it does
const eg = ExtendedGreeting();

// Prints "Mixin A foo()" twice.
eg.foo();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant