@@ -48,6 +48,24 @@ export default class Preview extends PreviewCollection {
48
48
private afterChildrenRenderDeferred : DeferredInterface = deferred ( ) ;
49
49
private buildSlickDebounce = _ . debounce ( this . buildSlick . bind ( this ) , 10 ) ;
50
50
51
+ /**
52
+ * Define keys which when changed should not trigger the slider to be rebuilt
53
+ *
54
+ * @type {string[] }
55
+ */
56
+ private ignoredKeysForBuild : string [ ] = [
57
+ "display" ,
58
+ "margins_and_padding" ,
59
+ "border" ,
60
+ "border_color" ,
61
+ "border_radius" ,
62
+ "border_width" ,
63
+ "css_classes" ,
64
+ "name" ,
65
+ "text_align" ,
66
+ ] ;
67
+ private previousData : DataObject ;
68
+
51
69
/**
52
70
* @param {ContentTypeCollectionInterface } parent
53
71
* @param {ContentTypeConfigInterface } config
@@ -73,7 +91,13 @@ export default class Preview extends PreviewCollection {
73
91
this . element = element as HTMLElement ;
74
92
75
93
this . childSubscribe = this . parent . children . subscribe ( this . buildSlickDebounce ) ;
76
- this . parent . dataStore . subscribe ( this . buildSlickDebounce ) ;
94
+ this . previousData = this . parent . dataStore . get ( ) as DataObject ;
95
+ this . parent . dataStore . subscribe ( ( data : DataObject ) => {
96
+ if ( this . hasDataChanged ( this . previousData , data ) ) {
97
+ this . buildSlickDebounce ( ) ;
98
+ }
99
+ this . previousData = data ;
100
+ } ) ;
77
101
78
102
this . buildSlick ( ) ;
79
103
@@ -346,6 +370,19 @@ export default class Preview extends PreviewCollection {
346
370
} ) ;
347
371
}
348
372
373
+ /**
374
+ * Determine if the data has changed, whilst ignoring certain keys which don't require a rebuild
375
+ *
376
+ * @param {DataObject } previousData
377
+ * @param {DataObject } newData
378
+ * @returns {boolean }
379
+ */
380
+ private hasDataChanged ( previousData : DataObject , newData : DataObject ) {
381
+ previousData = _ . omit ( previousData , this . ignoredKeysForBuild ) ;
382
+ newData = _ . omit ( newData , this . ignoredKeysForBuild ) ;
383
+ return ! _ . isEqual ( previousData , newData ) ;
384
+ }
385
+
349
386
/**
350
387
* Build our instance of slick
351
388
*/
0 commit comments