@@ -4,9 +4,10 @@ import {
4
4
Envelope ,
5
5
FlasherResponseOptions ,
6
6
QueueableInterface ,
7
- ResponseContext ,
7
+ ResponseContext , FlasherOptions ,
8
8
} from './interfaces' ;
9
9
import TemplateFactory from './template' ;
10
+ import { parseFunction } from './functions' ;
10
11
11
12
export default class Flasher {
12
13
private static instance : Flasher ;
@@ -26,6 +27,7 @@ export default class Flasher {
26
27
}
27
28
28
29
public render ( response : FlasherResponse ) : void {
30
+ response = this . parseResponse ( response ) ;
29
31
this . addStyles ( response . styles , ( ) => {
30
32
this . addScripts ( response . scripts , ( ) => {
31
33
this . renderOptions ( response . options ) ;
@@ -127,4 +129,24 @@ export default class Flasher {
127
129
return typeof object . addEnvelope === 'function'
128
130
&& typeof object . renderQueue === 'function' ;
129
131
}
132
+
133
+ private parseResponse ( response : FlasherResponse ) : FlasherResponse {
134
+ Object . entries ( response . options ) . forEach ( ( [ handler , options ] ) => {
135
+ response . options [ handler ] = this . parseOptions ( options ) ;
136
+ } ) ;
137
+
138
+ response . envelopes . forEach ( envelope => {
139
+ envelope . notification . options = this . parseOptions ( envelope . notification . options ) ;
140
+ } ) ;
141
+
142
+ return response ;
143
+ }
144
+
145
+ private parseOptions ( options : FlasherOptions ) : FlasherOptions {
146
+ Object . entries ( options ) . forEach ( ( [ key , value ] ) => {
147
+ options [ key ] = parseFunction ( value ) ;
148
+ } ) ;
149
+
150
+ return options ;
151
+ }
130
152
}
0 commit comments