File tree 1 file changed +10
-16
lines changed
1 file changed +10
-16
lines changed Original file line number Diff line number Diff line change 1
1
export class Base {
2
2
constructor ( options = { } ) {
3
3
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 ) => {
8
5
Object . assign ( this , plugin ( this , options ) ) ;
9
6
} ) ;
10
7
}
11
- static plugin ( plugin1 , ... additionalPlugins ) {
12
- var _a ;
8
+
9
+ static plugin ( ... newPlugins ) {
13
10
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 (
18
13
newPlugins . filter ( ( plugin ) => ! currentPlugins . includes ( plugin ) )
19
- ) ) ,
20
- _a ) ;
21
- return BaseWithPlugins ;
14
+ ) ;
15
+ } ;
22
16
}
23
17
static defaults ( defaults ) {
24
- const BaseWitDefaults = class extends this {
18
+ return class extends this {
25
19
constructor ( ...args ) {
26
20
super ( Object . assign ( { } , defaults , args [ 0 ] || { } ) ) ;
27
21
}
28
22
} ;
29
- return BaseWitDefaults ;
30
23
}
24
+
25
+ static plugins = [ ] ;
31
26
}
32
- Base . plugins = [ ] ;
You can’t perform that action at this time.
0 commit comments