Last change
on this file since 8d391a1 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
900 bytes
|
Line | |
---|
1 | 'use strict';
|
---|
2 |
|
---|
3 | class Mixin {
|
---|
4 | constructor(host) {
|
---|
5 | const originalMethods = {};
|
---|
6 | const overriddenMethods = this._getOverriddenMethods(this, originalMethods);
|
---|
7 |
|
---|
8 | for (const key of Object.keys(overriddenMethods)) {
|
---|
9 | if (typeof overriddenMethods[key] === 'function') {
|
---|
10 | originalMethods[key] = host[key];
|
---|
11 | host[key] = overriddenMethods[key];
|
---|
12 | }
|
---|
13 | }
|
---|
14 | }
|
---|
15 |
|
---|
16 | _getOverriddenMethods() {
|
---|
17 | throw new Error('Not implemented');
|
---|
18 | }
|
---|
19 | }
|
---|
20 |
|
---|
21 | Mixin.install = function(host, Ctor, opts) {
|
---|
22 | if (!host.__mixins) {
|
---|
23 | host.__mixins = [];
|
---|
24 | }
|
---|
25 |
|
---|
26 | for (let i = 0; i < host.__mixins.length; i++) {
|
---|
27 | if (host.__mixins[i].constructor === Ctor) {
|
---|
28 | return host.__mixins[i];
|
---|
29 | }
|
---|
30 | }
|
---|
31 |
|
---|
32 | const mixin = new Ctor(host, opts);
|
---|
33 |
|
---|
34 | host.__mixins.push(mixin);
|
---|
35 |
|
---|
36 | return mixin;
|
---|
37 | };
|
---|
38 |
|
---|
39 | module.exports = Mixin;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.