@@ -18,32 +18,47 @@ export function isSameArray(a: any[], b: any[]) {
1818 return true ;
1919}
2020
21+ // source: https://stackoverflow.com/questions/4816099/chrome-sendrequest-error-typeerror-converting-circular-structure-to-json
22+ function stringifyCensor ( censor : any ) {
23+ let i = 0 ;
24+ return function ( key : string , value : any ) {
25+ if ( i !== 0 && typeof censor === 'object' && typeof value == 'object' && censor == value ) {
26+ return '[Circular]' ;
27+ }
28+ if ( i >= 29 ) {
29+ // seems to be a harded maximum of 30 serialized objects?
30+ return '[Unknown]' ;
31+ }
32+ ++ i ; // so we know we aren't using the original object anymore
33+ return value ;
34+ } ;
35+ }
36+
2137export function isSameObject ( a : any , b : any ) {
22- return JSON . stringify ( a ) === JSON . stringify ( b ) ;
38+ return JSON . stringify ( a , stringifyCensor ( a ) ) === JSON . stringify ( b , stringifyCensor ( b ) ) ;
2339}
2440
2541export function reactFormatter ( JSX : any ) {
26- return function customFormatter ( cell : any , formatterParams : any , onRendered : ( callback : ( ) => void ) => void ) {
27- //cell - the cell component
28- //formatterParams - parameters set for the column
29- //onRendered - function to call when the formatter has been rendered
30-
42+ return function customFormatter ( cell : any , formatterParams : any , onRendered : ( callback : ( ) => void ) => void ) {
43+ // cell - the cell component
44+ // formatterParams - parameters set for the column
45+ // onRendered - function to call when the formatter has been rendered
3146 const renderFn = ( ) => {
3247 const cellEl = cell . getElement ( ) ;
3348 if ( cellEl ) {
34- const formatterCell = cellEl . querySelector ( '.formatterCell' )
49+ const formatterCell = cellEl . querySelector ( '.formatterCell' ) ;
3550 if ( formatterCell ) {
3651 const CompWithMoreProps = React . cloneElement ( JSX , { cell } ) ;
3752 render ( CompWithMoreProps , cellEl . querySelector ( '.formatterCell' ) ) ;
3853 }
3954 }
40- }
55+ } ;
4156
4257 onRendered ( renderFn ) ; // initial render only.
4358
4459 setTimeout ( ( ) => {
4560 renderFn ( ) ; // render every time cell value changed.
46- } , 0 )
61+ } , 0 ) ;
4762 return '<div class="formatterCell"></div>' ;
48- }
49- }
63+ } ;
64+ }
0 commit comments