@@ -6,6 +6,7 @@ import {getAnalyticsOptions} from "../utils/analytics";
66
77export class HtmlImageLayer {
88 private imgElement : any ;
9+ private destroyed = false ;
910 htmlPluginState : HtmlPluginState ;
1011 constructor ( element : HTMLImageElement | null , userCloudinaryImage : CloudinaryImage , plugins ?: Plugins , baseAnalyticsOptions ?: BaseAnalyticsOptions ) {
1112 this . imgElement = element ;
@@ -14,6 +15,9 @@ export class HtmlImageLayer{
1415
1516 render ( element , pluginCloudinaryImage , plugins , this . htmlPluginState , baseAnalyticsOptions )
1617 . then ( ( pluginResponse ) => { // when resolved updates the src
18+ if ( this . destroyed ) {
19+ return ;
20+ }
1721 this . htmlPluginState . pluginEventSubscription . forEach ( fn => { fn ( ) } ) ;
1822 const analyticsOptions = getAnalyticsOptions ( baseAnalyticsOptions , pluginResponse ) ;
1923 this . imgElement . setAttribute ( 'src' , pluginCloudinaryImage . toURL ( analyticsOptions ) ) ;
@@ -30,8 +34,14 @@ export class HtmlImageLayer{
3034 const pluginCloudinaryImage = cloneDeep ( userCloudinaryImage ) ;
3135 render ( this . imgElement , pluginCloudinaryImage , plugins , this . htmlPluginState )
3236 . then ( ( pluginResponse ) => {
37+ if ( this . destroyed ) {
38+ return ;
39+ }
3340 const featuredAnalyticsOptions = getAnalyticsOptions ( baseAnalyticsOptions , pluginResponse ) ;
3441 this . imgElement . setAttribute ( 'src' , pluginCloudinaryImage . toURL ( featuredAnalyticsOptions ) ) ;
3542 } ) ;
3643 }
44+ destroy ( ) {
45+ this . destroyed = true ;
46+ }
3747}
0 commit comments