@@ -142,12 +142,11 @@ class Cache {
142142 }
143143
144144 fetchSimple ( key , setter ) {
145- if ( this . store [ key ] ) {
146- return this . store [ key ] ;
147- } else {
145+ if ( ! ( key in this . store ) ) {
148146 this . store [ key ] = setter ( ) ;
149- return this . store [ key ] ;
150147 }
148+
149+ return this . store [ key ] ;
151150 }
152151
153152 fetchComplex ( [ name , ...path ] , setter ) {
@@ -157,6 +156,7 @@ class Cache {
157156 for ( let i = 0 ; i < path . length - 1 ; i ++ ) {
158157 if ( typeof this . get ( current , path [ i ] ) === 'undefined' ) {
159158 const nextKey = path [ i + 1 ] ;
159+
160160 this . put ( current , path [ i ] ,
161161 typeof nextKey === 'number' ||
162162 typeof nextKey === 'string' ||
@@ -167,11 +167,12 @@ class Cache {
167167 current = this . get ( current , path [ i ] ) ;
168168 }
169169 const key = path [ path . length - 1 ] , cached = this . get ( current , key ) ;
170+
170171 return cached || this . put ( current , key , setter ( ) ) ;
171172 }
172173
173174 get ( store , key ) {
174- if ( store . constructor === WeakMap ) {
175+ if ( store instanceof WeakMap ) {
175176 return store . get ( key ) ;
176177 } else {
177178 return store [ key ] ;
@@ -184,6 +185,7 @@ class Cache {
184185 } else {
185186 store [ key ] = value ;
186187 }
188+
187189 return value ;
188190 }
189191}
0 commit comments