@@ -263,8 +263,11 @@ function (_React$Component) {
263263 // animate the chart to show the changes
264264
265265 this . chartObj . render ( ) ;
266+ return ;
266267 }
267- } else if ( ! this . isSameChartData ( currData , oldData ) ) {
268+ }
269+
270+ if ( ! this . isSameChartData ( currData , oldData ) ) {
268271 if ( ! _utils_utils__WEBPACK_IMPORTED_MODULE_3__ [ "isUndefined" ] ( currData ) ) {
269272 this . chartObj . setChartData ( currData , // When dataFormat is not given, but data is changed,
270273 // then use 'json' as default dataFormat
@@ -275,11 +278,35 @@ function (_React$Component) {
275278 } , {
276279 key : "isSameChartData" ,
277280 value : function isSameChartData ( currData , oldData ) {
278- if ( _utils_utils__WEBPACK_IMPORTED_MODULE_3__ [ "isObject" ] ( currData ) && _utils_utils__WEBPACK_IMPORTED_MODULE_3__ [ "isObject" ] ( oldData ) ) {
279- return _utils_utils__WEBPACK_IMPORTED_MODULE_3__ [ "isSameObjectContent" ] ( currData , oldData ) ;
280- }
281+ /* TODO
282+ 1. Current has DataStore and Old doesn't
283+ 2. Old has and Current doesn't
284+ 3. Both has, check ref is equal, return false only if not equal
285+ 4. Clone oldData for diff
286+ 5. Clone currentData for diff
287+ 6. return string check.
288+ */
289+ // 1. Current has DataStore and Old doesn't
290+ if ( _utils_utils__WEBPACK_IMPORTED_MODULE_3__ [ "checkIfDataTableExists" ] ( currData ) && ! _utils_utils__WEBPACK_IMPORTED_MODULE_3__ [ "checkIfDataTableExists" ] ( oldData ) ) {
291+ return false ;
292+ } // 2. Old has and Current doesn't
293+
294+
295+ if ( ! _utils_utils__WEBPACK_IMPORTED_MODULE_3__ [ "checkIfDataTableExists" ] ( currData ) && _utils_utils__WEBPACK_IMPORTED_MODULE_3__ [ "checkIfDataTableExists" ] ( oldData ) ) {
296+ return false ;
297+ } // 3. Both has, check ref is equal, return false only if not equal
298+
299+
300+ if ( _utils_utils__WEBPACK_IMPORTED_MODULE_3__ [ "checkIfDataTableExists" ] ( currData ) && _utils_utils__WEBPACK_IMPORTED_MODULE_3__ [ "checkIfDataTableExists" ] ( oldData ) && currData . data !== oldData . data ) {
301+ return false ;
302+ } // 4. Clone oldData for diff
281303
282- return currData === oldData ;
304+
305+ var oldDataStringified = JSON . stringify ( _utils_utils__WEBPACK_IMPORTED_MODULE_3__ [ "cloneDataSource" ] ( oldData , 'diff' ) ) ; // 5. Clone currentData for diff
306+
307+ var currentDataStringified = JSON . stringify ( _utils_utils__WEBPACK_IMPORTED_MODULE_3__ [ "cloneDataSource" ] ( currData , 'diff' ) ) ; // 6. return string check.
308+
309+ return oldDataStringified === currentDataStringified ;
283310 }
284311 } , {
285312 key : "checkAndUpdateEvents" ,
@@ -414,8 +441,10 @@ function (_React$Component) {
414441 } , { } ) ;
415442 Object . assign ( inlineOptions , chartConfig ) ;
416443
417- if ( _utils_utils__WEBPACK_IMPORTED_MODULE_3__ [ "isObject" ] ( inlineOptions . dataSource ) ) {
444+ if ( _utils_utils__WEBPACK_IMPORTED_MODULE_3__ [ "isObject" ] ( inlineOptions . dataSource ) && ! _utils_utils__WEBPACK_IMPORTED_MODULE_3__ [ "checkIfDataTableExists" ] ( inlineOptions . dataSource ) ) {
418445 inlineOptions . dataSource = _utils_utils__WEBPACK_IMPORTED_MODULE_3__ [ "deepCopyOf" ] ( inlineOptions . dataSource ) ;
446+ } else if ( _utils_utils__WEBPACK_IMPORTED_MODULE_3__ [ "isObject" ] ( inlineOptions . dataSource ) && _utils_utils__WEBPACK_IMPORTED_MODULE_3__ [ "checkIfDataTableExists" ] ( inlineOptions . dataSource ) ) {
447+ inlineOptions . dataSource = _utils_utils__WEBPACK_IMPORTED_MODULE_3__ [ "cloneDataSource" ] ( inlineOptions . dataSource , 'clone' ) ;
419448 }
420449
421450 if ( _utils_utils__WEBPACK_IMPORTED_MODULE_3__ [ "isObject" ] ( inlineOptions . link ) ) {
@@ -571,8 +600,11 @@ __webpack_require__.r(__webpack_exports__);
571600/* harmony export (binding) */ __webpack_require__ . d ( __webpack_exports__ , "isSameObjectContent" , function ( ) { return isSameObjectContent ; } ) ;
572601/* harmony export (binding) */ __webpack_require__ . d ( __webpack_exports__ , "isUndefined" , function ( ) { return isUndefined ; } ) ;
573602/* harmony export (binding) */ __webpack_require__ . d ( __webpack_exports__ , "deepCopyOf" , function ( ) { return deepCopyOf ; } ) ;
603+ /* harmony export (binding) */ __webpack_require__ . d ( __webpack_exports__ , "checkIfDataTableExists" , function ( ) { return checkIfDataTableExists ; } ) ;
604+ /* harmony export (binding) */ __webpack_require__ . d ( __webpack_exports__ , "cloneDataSource" , function ( ) { return cloneDataSource ; } ) ;
574605function _typeof ( obj ) { if ( typeof Symbol === "function" && typeof Symbol . iterator === "symbol" ) { _typeof = function _typeof ( obj ) { return typeof obj ; } ; } else { _typeof = function _typeof ( obj ) { return obj && typeof Symbol === "function" && obj . constructor === Symbol && obj !== Symbol . prototype ? "symbol" : typeof obj ; } ; } return _typeof ( obj ) ; }
575606
607+ /* eslint-disable guard-for-in */
576608function isObject ( value ) {
577609 return value !== null && _typeof ( value ) === 'object' ;
578610}
@@ -608,6 +640,64 @@ function isUndefined(value) {
608640function deepCopyOf ( obj ) {
609641 return JSON . parse ( JSON . stringify ( obj ) ) ;
610642}
643+ function checkIfDataTableExists ( dataSource ) {
644+ // eslint-disable-next-line no-underscore-dangle
645+ if ( dataSource && dataSource . data && dataSource . data . _dataStore ) {
646+ return true ;
647+ }
648+
649+ return false ;
650+ }
651+ function cloneDataSource ( obj ) {
652+ var purpose = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : 'clone' ;
653+
654+ var type = _typeof ( obj ) ;
655+
656+ if ( type === 'string' || type === 'number' || type === 'function' || type === 'boolean' ) {
657+ return obj ;
658+ }
659+
660+ if ( obj === null || obj === undefined ) {
661+ return obj ;
662+ }
663+
664+ if ( Array . isArray ( obj ) ) {
665+ var arr = [ ] ;
666+
667+ for ( var i = 0 ; i < obj . length ; i ++ ) {
668+ arr . push ( this . cloneDataSource ( obj [ i ] ) ) ;
669+ }
670+
671+ return arr ;
672+ }
673+
674+ if ( _typeof ( obj ) === 'object' ) {
675+ var clonedObj = { } ; // eslint-disable-next-line guard-for-in
676+ // eslint-disable-next-line no-restricted-syntax
677+
678+ for ( var prop in obj ) {
679+ // Edge case handling for DataTable
680+ if ( prop === 'data' ) {
681+ // eslint-disable-next-line no-underscore-dangle
682+ if ( obj [ prop ] . _dataStore && purpose === 'clone' ) {
683+ clonedObj [ prop ] = obj [ prop ] ; // eslint-disable-next-line no-underscore-dangle
684+ } else if ( obj [ prop ] . _dataStore && purpose === 'diff' ) {
685+ clonedObj [ prop ] = '-' ;
686+ } else {
687+ clonedObj [ prop ] = this . cloneDataSource ( obj [ prop ] ) ;
688+ }
689+
690+ continue ;
691+ }
692+
693+ clonedObj [ prop ] = this . cloneDataSource ( obj [ prop ] ) ;
694+ }
695+
696+ return clonedObj ;
697+ }
698+
699+ return undefined ;
700+ }
611701
612702/***/ } ) ,
613703/* 8 */
0 commit comments