-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.js
31 lines (26 loc) · 735 Bytes
/
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
export class Base {
constructor(options = {}) {
this.options = options;
this.constructor.plugins.forEach((plugin) => {
Object.assign(this, plugin(this, options));
});
}
static plugin(...newPlugins) {
const currentPlugins = this.plugins;
return class extends this {
static plugins = currentPlugins.concat(
newPlugins.filter((plugin) => !currentPlugins.includes(plugin))
);
};
}
static defaults(defaults) {
return class extends this {
constructor(...args) {
super(Object.assign({}, defaults, args[0] || {}));
}
static defaultOptions = { ...defaults, ...this.defaultOptions };
};
}
static defaultOptions = {};
static plugins = [];
}