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