Skip to content

Commit 2e48e16

Browse files
authored
fix: simplify source code (#52)
1 parent e13eb93 commit 2e48e16

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

index.js

+10-16
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,26 @@
11
export class Base {
22
constructor(options = {}) {
33
this.options = options;
4-
// apply plugins
5-
// https://stackoverflow.com/a/16345172
6-
const classConstructor = this.constructor;
7-
classConstructor.plugins.forEach((plugin) => {
4+
this.constructor.plugins.forEach((plugin) => {
85
Object.assign(this, plugin(this, options));
96
});
107
}
11-
static plugin(plugin1, ...additionalPlugins) {
12-
var _a;
8+
9+
static plugin(...newPlugins) {
1310
const currentPlugins = this.plugins;
14-
let newPlugins = [plugin1, ...additionalPlugins];
15-
const BaseWithPlugins =
16-
((_a = class extends this {}),
17-
(_a.plugins = currentPlugins.concat(
11+
return class extends this {
12+
static plugins = currentPlugins.concat(
1813
newPlugins.filter((plugin) => !currentPlugins.includes(plugin))
19-
)),
20-
_a);
21-
return BaseWithPlugins;
14+
);
15+
};
2216
}
2317
static defaults(defaults) {
24-
const BaseWitDefaults = class extends this {
18+
return class extends this {
2519
constructor(...args) {
2620
super(Object.assign({}, defaults, args[0] || {}));
2721
}
2822
};
29-
return BaseWitDefaults;
3023
}
24+
25+
static plugins = [];
3126
}
32-
Base.plugins = [];

0 commit comments

Comments
 (0)