@@ -85,44 +85,40 @@ const DEFAULT_CONFIGURATIONS = {
85
85
}
86
86
} ;
87
87
88
- const PROXY_GET = function ( obj , key ) {
89
- if ( ! key ) {
90
- return null ;
91
- }
92
-
93
- for ( const k of key . split ( "." ) ) {
94
- obj = obj [ k ] ;
95
- if ( ! obj ) {
96
- break ;
88
+ const PROXY_HANDLER = {
89
+ get : function ( obj , key ) {
90
+ if ( ! key ) {
91
+ return null ;
97
92
}
98
- }
99
93
100
- return obj ;
101
- } ;
94
+ for ( const k of key . split ( "." ) ) {
95
+ obj = obj [ k ] ;
96
+ if ( ! obj ) {
97
+ break ;
98
+ }
99
+ }
102
100
103
- const PROXT_SET = function ( obj , key , val ) {
104
- if ( ! key ) {
105
- return false ;
106
- }
101
+ return obj ;
102
+ } ,
103
+ set : function ( obj , key , val ) {
104
+ if ( ! key ) {
105
+ return false ;
106
+ }
107
107
108
- const keys = key . split ( "." ) ;
109
- const lastKey = keys [ keys . length - 1 ] ;
108
+ const keys = key . split ( "." ) ;
109
+ const lastKey = keys [ keys . length - 1 ] ;
110
110
111
- for ( let i = 0 ; i < keys . length - 1 ; i ++ ) {
112
- if ( ! obj [ keys [ i ] ] ) {
113
- obj [ keys [ i ] ] = { } ;
111
+ for ( let i = 0 ; i < keys . length - 1 ; i ++ ) {
112
+ if ( ! obj [ keys [ i ] ] ) {
113
+ obj [ keys [ i ] ] = { } ;
114
+ }
115
+ obj = obj [ keys [ i ] ] ;
114
116
}
115
- obj = obj [ keys [ i ] ] ;
116
- }
117
-
118
- obj [ lastKey ] = val ;
119
117
120
- return true ;
121
- } ;
118
+ obj [ lastKey ] = val ;
122
119
123
- const PROXY_HANDLER = {
124
- get : PROXY_GET ,
125
- set : PROXT_SET
120
+ return true ;
121
+ }
126
122
} ;
127
123
128
124
const LEGAL_VALUES = new Proxy ( {
@@ -134,26 +130,27 @@ const LEGAL_VALUES = new Proxy({
134
130
}
135
131
} , PROXY_HANDLER ) ;
136
132
133
+ var CONFIGURATION = null ;
134
+ var LOADED_CONFIGURATION = null ;
135
+
137
136
const configuration = {
138
- CONFIGURATION : null ,
139
- LOADED_CONFIGURATION : null ,
140
137
load ( ) {
141
138
configuration . getConfig ( ) ;
142
139
} ,
143
140
getConfig ( ) {
144
- if ( ! configuration . CONFIGURATION ) {
145
- configuration . CONFIGURATION = new Proxy ( JSON . parse ( JSON . stringify ( DEFAULT_CONFIGURATIONS . default ) ) , {
146
- get : PROXY_GET ,
141
+ if ( ! CONFIGURATION ) {
142
+ CONFIGURATION = new Proxy ( JSON . parse ( JSON . stringify ( DEFAULT_CONFIGURATION ) ) , {
143
+ get : PROXY_HANDLER . get ,
147
144
set : function ( obj , key , val ) {
148
145
if ( LEGAL_VALUES [ key ] && ! LEGAL_VALUES [ key ] . includes ( val ) ) {
149
146
return true ;
150
147
}
151
148
152
- if ( PROXY_GET ( obj , key ) === val ) {
149
+ if ( PROXY_HANDLER . get ( obj , key ) === val ) {
153
150
return true ;
154
151
}
155
152
156
- PROXT_SET ( obj , key , val ) ;
153
+ PROXY_HANDLER . set ( obj , key , val ) ;
157
154
158
155
if ( key === "style" ) {
159
156
obj . styleOptions = DEFAULT_CONFIGURATIONS [ val ] . styleOptions ;
@@ -164,21 +161,21 @@ const configuration = {
164
161
return true ;
165
162
}
166
163
} ) ;
167
- configuration . merge ( configuration . CONFIGURATION , configuration . getLoadedConfig ( ) ) ;
164
+ configuration . merge ( CONFIGURATION , configuration . getLoadedConfig ( ) ) ;
168
165
}
169
- return configuration . CONFIGURATION ;
166
+ return CONFIGURATION ;
170
167
} ,
171
168
getLoadedConfig ( ) {
172
- if ( ! configuration . LOADED_CONFIGURATION ) {
173
- configuration . LOADED_CONFIGURATION = new Proxy ( { } , PROXY_HANDLER ) ;
174
- for ( const key of configuration . getKeys ( DEFAULT_CONFIGURATIONS . default ) ) {
169
+ if ( ! LOADED_CONFIGURATION ) {
170
+ LOADED_CONFIGURATION = new Proxy ( { } , PROXY_HANDLER ) ;
171
+ for ( const key of configuration . getKeys ( DEFAULT_CONFIGURATION ) ) {
175
172
const val = query . get ( `${ ls . PREFIX } ${ key } ` ) || ls . get ( key ) ;
176
173
if ( val ) {
177
- configuration . LOADED_CONFIGURATION [ key ] = val ;
174
+ LOADED_CONFIGURATION [ key ] = val ;
178
175
}
179
176
}
180
177
}
181
- return configuration . LOADED_CONFIGURATION ;
178
+ return LOADED_CONFIGURATION ;
182
179
} ,
183
180
get ( key ) {
184
181
const config = configuration . getConfig ( ) ;
0 commit comments