@@ -176,8 +176,66 @@ var ComponentBase = /** @class */ (function (_super) {
176176 this . isProtectedOnChange = prevDetection ;
177177 }
178178 } ;
179- ComponentBase . prototype . compareObjects = function ( oldProps , newProps ) {
180- return JSON . stringify ( oldProps ) === JSON . stringify ( newProps ) ;
179+ ComponentBase . prototype . compareValues = function ( value1 , value2 ) {
180+ var typeVal = typeof value1 ;
181+ var typeVal2 = typeof value2 ;
182+ if ( typeVal === typeVal2 ) {
183+ if ( value1 . constructor !== value2 . constructor ) {
184+ return false ;
185+ }
186+ if ( value1 === value2 ) {
187+ return true ;
188+ }
189+ if ( value1 instanceof Date ||
190+ value1 instanceof RegExp ||
191+ value1 instanceof String ||
192+ value1 instanceof Number ||
193+ typeVal === 'function' ) {
194+ return value1 . tostring === value2 . tostring ;
195+ }
196+ if ( sf . base . isObject ( value1 ) || Array . isArray ( value1 ) ) {
197+ var tempVal = value1 ;
198+ var tempVal2 = value2 ;
199+ if ( sf . base . isObject ( tempVal ) ) {
200+ tempVal = [ value1 ] ;
201+ tempVal2 = [ value2 ] ;
202+ }
203+ return this . compareObjects ( tempVal , tempVal2 ) . status ;
204+ }
205+ }
206+ return false ;
207+ } ;
208+ ComponentBase . prototype . compareObjects = function ( oldProps , newProps , propName ) {
209+ var status ;
210+ var lenSimilarity = ( oldProps . length === newProps . length ) ;
211+ var diffArray = [ ] ;
212+ if ( lenSimilarity ) {
213+ for ( var i = 0 , len = newProps . length ; i < len ; i ++ ) {
214+ var curObj = { } ;
215+ var oldProp = oldProps [ i ] ;
216+ var newProp = newProps [ i ] ;
217+ var keys = Object . keys ( newProp ) ;
218+ for ( var _i = 0 , keys_2 = keys ; _i < keys_2 . length ; _i ++ ) {
219+ var key = keys_2 [ _i ] ;
220+ var oldValue = oldProp [ key ] ;
221+ var newValue = newProp [ key ] ;
222+ if ( ! oldProp . hasOwnProperty ( key ) || ! this . compareValues ( newValue , oldValue ) ) {
223+ if ( ! propName ) {
224+ return { status : false } ;
225+ }
226+ status = false ;
227+ curObj [ key ] = newValue ;
228+ }
229+ }
230+ if ( Object . keys ( curObj ) . length ) {
231+ diffArray . push ( { index : i , value : curObj , key : propName } ) ;
232+ }
233+ }
234+ }
235+ else {
236+ status = false ;
237+ }
238+ return { status : status , changedProperties : diffArray } ;
181239 } ;
182240 ComponentBase . prototype . refreshChild = function ( silent , props ) {
183241 if ( this . checkInjectedModules ) {
@@ -192,8 +250,9 @@ var ComponentBase = /** @class */ (function (_super) {
192250 this . injectedModules = prevModule ;
193251 }
194252 if ( this . directivekeys ) {
253+ var changedProps = [ ] ;
195254 var directiveValue = this . validateChildren ( { } , this . directivekeys , ( props || this . props ) ) ;
196- if ( directiveValue ) {
255+ if ( directiveValue && Object . keys ( directiveValue ) . length ) {
197256 if ( ! silent && this . skipRefresh ) {
198257 for ( var _a = 0 , _b = this . skipRefresh ; _a < _b . length ; _a ++ ) {
199258 var fields = _b [ _a ] ;
@@ -204,10 +263,17 @@ var ComponentBase = /** @class */ (function (_super) {
204263 var dKeys = Object . keys ( this . prevProperties ) ;
205264 for ( var i = 0 ; i < dKeys . length ; i ++ ) {
206265 var key = dKeys [ i ] ;
207- if ( this . compareObjects ( this . prevProperties [ key ] , directiveValue [ key ] ) ) {
266+ if ( ! directiveValue . hasOwnProperty ( key ) ) {
267+ continue ;
268+ }
269+ var compareOutput = this . compareObjects ( this . prevProperties [ key ] , directiveValue [ key ] , key ) ;
270+ if ( compareOutput . status ) {
208271 delete directiveValue [ key ] ;
209272 }
210273 else {
274+ if ( compareOutput . changedProperties . length ) {
275+ changedProps = changedProps . concat ( compareOutput . changedProperties ) ;
276+ }
211277 var obj = { } ;
212278 obj [ key ] = directiveValue [ key ] ;
213279 this . prevProperties = sf . base . extend ( this . prevProperties , obj ) ;
@@ -217,7 +283,21 @@ var ComponentBase = /** @class */ (function (_super) {
217283 else {
218284 this . prevProperties = sf . base . extend ( { } , directiveValue , { } , true ) ;
219285 }
220- this . setProperties ( directiveValue , silent ) ;
286+ if ( changedProps . length ) {
287+ for ( var _c = 0 , changedProps_1 = changedProps ; _c < changedProps_1 . length ; _c ++ ) {
288+ var changes = changedProps_1 [ _c ] ;
289+ var propInstance = sf . base . getValue ( changes . key + '.' + changes . index , this ) ;
290+ if ( propInstance && propInstance . setProperties ) {
291+ propInstance . setProperties ( changes . value ) ;
292+ }
293+ else {
294+ sf . base . extend ( propInstance , changes . value ) ;
295+ }
296+ }
297+ }
298+ else {
299+ this . setProperties ( directiveValue , silent ) ;
300+ }
221301 }
222302 }
223303 } ;
0 commit comments