22 * Lazy Loading Utility for WeChat Mini Program
33 * Handles component, image, and data lazy loading
44 */
5+ import Debug from '../debug/debug' ;
56
67class LazyLoader {
78 constructor ( ) {
@@ -43,7 +44,7 @@ class LazyLoader {
4344 markComponentLoaded ( componentName ) {
4445 this . loadedComponents . add ( componentName ) ;
4546 if ( this . debugMode ) {
46- console . log ( `[LazyLoader] Component loaded: ${ componentName } ` ) ;
47+ Debug . log ( `[LazyLoader] Component loaded: ${ componentName } ` ) ;
4748 }
4849 }
4950
@@ -60,13 +61,13 @@ class LazyLoader {
6061 query . selectAll ( selector ) . boundingClientRect ( ( rects ) => {
6162 if ( ! rects || rects . length === 0 ) {
6263 if ( this . debugMode ) {
63- console . log ( `[LazyLoader] No elements found for selector "${ selector } ". Skipping image lazy loading.` ) ;
64+ Debug . log ( `[LazyLoader] No elements found for selector "${ selector } ". Skipping image lazy loading.` ) ;
6465 }
6566 return ;
6667 }
6768
6869 if ( this . debugMode ) {
69- console . log ( `[LazyLoader] Found ${ rects . length } elements for lazy loading with selector "${ selector } "` ) ;
70+ Debug . log ( `[LazyLoader] Found ${ rects . length } elements for lazy loading with selector "${ selector } "` ) ;
7071 }
7172
7273 // Create intersection observer for images only if elements exist
@@ -118,7 +119,7 @@ class LazyLoader {
118119 }
119120 } ,
120121 fail : ( err ) => {
121- console . error ( '[LazyLoader] Image lazy load failed:' , err ) ;
122+ Debug . error ( '[LazyLoader] Image lazy load failed:' , err ) ;
122123 // Set fallback or error state
123124 const updateKey = `images.${ imageId } ` ;
124125 context . setData ( {
@@ -150,7 +151,7 @@ class LazyLoader {
150151 this . setCache ( cacheKey , data ) ;
151152 return data ;
152153 } catch ( error ) {
153- console . error ( '[LazyLoader] Data lazy load failed:' , error ) ;
154+ Debug . error ( '[LazyLoader] Data lazy load failed:' , error ) ;
154155 throw error ;
155156 }
156157 }
@@ -166,7 +167,7 @@ class LazyLoader {
166167 }
167168 } catch ( e ) {
168169 if ( this . debugMode ) {
169- console . error ( '[LazyLoader] Cache read error:' , e ) ;
170+ Debug . error ( '[LazyLoader] Cache read error:' , e ) ;
170171 }
171172 }
172173 return null ;
@@ -180,7 +181,7 @@ class LazyLoader {
180181 } ) ;
181182 } catch ( e ) {
182183 if ( this . debugMode ) {
183- console . error ( '[LazyLoader] Cache write error:' , e ) ;
184+ Debug . error ( '[LazyLoader] Cache write error:' , e ) ;
184185 }
185186 }
186187 }
@@ -211,7 +212,7 @@ class LazyLoader {
211212 this . initImageLazyLoad ( selector , context ) ;
212213 } else {
213214 if ( this . debugMode ) {
214- console . log ( `[LazyLoader] No elements found for "${ selector } ". Image lazy loading skipped.` ) ;
215+ Debug . log ( `[LazyLoader] No elements found for "${ selector } ". Image lazy loading skipped.` ) ;
215216 }
216217 }
217218 }
@@ -223,7 +224,7 @@ class LazyLoader {
223224 setDebugMode ( enabled ) {
224225 this . debugMode = enabled ;
225226 if ( enabled ) {
226- console . log ( '[LazyLoader] Debug mode enabled' ) ;
227+ Debug . log ( '[LazyLoader] Debug mode enabled' ) ;
227228 }
228229 }
229230
0 commit comments