-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
44 lines (41 loc) · 1.03 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
function mixWith(ctor, trait) {
Object.getOwnPropertyNames(trait.prototype)
.filter((m) => !(m in ctor.prototype))
.forEach(copy);
return ctor;
function copy(prop) {
Object.defineProperty(ctor.prototype, prop, Object.getOwnPropertyDescriptor(trait.prototype, prop));
}
}
class MixinBuilderImpl {
constructor(ctor) {
this.ctor = ctor;
}
get() {
return this.ctor;
}
get prototype() {
return this.ctor.prototype;
}
with(x) {
const trait = x instanceof MixinBuilderImpl ? x.get() : x;
const ctor = mixWith(this.ctor, trait);
const builder = new MixinBuilderImpl(ctor);
return builder;
}
}
function newMixin() {
function m(ctor) {
return new MixinBuilderImpl(ctor);
}
function mWith(ctor) {
return m(class {
}).with(ctor);
}
m.with = mWith;
return m;
}
const mixin = newMixin();
exports.mixin = mixin;