@@ -8,14 +8,6 @@ import { DrawerRef } from './drawer-ref';
8
8
import { DrawerOptions , DrawerSize } from './types' ;
9
9
10
10
const DRAWER_OVERLAY_CLASS = 'aui-drawer-overlay' ;
11
- const DEFAULT_OPTIONS : DrawerOptions = {
12
- size : DrawerSize . Medium ,
13
- offsetY : '0' ,
14
- showClose : true ,
15
- hideOnClickOutside : false ,
16
- divider : true ,
17
- disposeWhenHide : true ,
18
- } ;
19
11
20
12
@Injectable ( )
21
13
export class DrawerService <
@@ -31,6 +23,15 @@ export class DrawerService<
31
23
DrawerInternalComponent < T , C >
32
24
> ;
33
25
26
+ private readonly DEFAULT_OPTIONS : DrawerOptions < T , C > = {
27
+ size : DrawerSize . Medium ,
28
+ offsetY : '0' ,
29
+ showClose : true ,
30
+ hideOnClickOutside : false ,
31
+ divider : true ,
32
+ disposeWhenHide : true ,
33
+ } ;
34
+
34
35
constructor ( private readonly overlay : Overlay ) { }
35
36
36
37
open ( options : DrawerOptions < T , C > ) {
@@ -46,10 +47,7 @@ export class DrawerService<
46
47
}
47
48
48
49
updateOptions ( options : DrawerOptions < T , C > ) : void {
49
- this . options = {
50
- ...( DEFAULT_OPTIONS as DrawerOptions < T , C > ) ,
51
- ...options ,
52
- } ;
50
+ this . options = merge < DrawerOptions < T , C > > ( this . DEFAULT_OPTIONS , options ) ;
53
51
}
54
52
55
53
private createOverlay ( ) {
@@ -135,3 +133,18 @@ export class DrawerService<
135
133
this . dispose ( ) ;
136
134
}
137
135
}
136
+
137
+ function merge < T extends object > ( target : T , source : T ) {
138
+ return Object . keys ( source ) . reduce (
139
+ ( acc , _key ) => {
140
+ const key = _key as keyof T ;
141
+ if ( source [ key ] !== undefined ) {
142
+ acc [ key ] = source [ key ] ;
143
+ }
144
+ return acc ;
145
+ } ,
146
+ {
147
+ ...target ,
148
+ } ,
149
+ ) ;
150
+ }
0 commit comments