Skip to content

Commit 87b9df0

Browse files
committed
fix: Util: isSameObject
1 parent 13f6ac2 commit 87b9df0

File tree

4 files changed

+48
-17
lines changed

4 files changed

+48
-17
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
## [0.14.8] - 2021-02-25
1+
## [0.15.0] - 2021-02-25
22
- feat: when "options" prop changed, rebuild and rerender the table.
3+
- fix: Util: stringifyCensor to compare "options" props.
34
- fix: take "layout" from prop - thanks @ViralLka
45
- switched from yarn to npm as yarn build doesn't work anymore.
56
- updated peerDependencies for React 17 - thanks @ApacheEx

lib/Utils.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,30 @@ function isSameArray(a, b) {
2020
return true;
2121
}
2222
exports.isSameArray = isSameArray;
23+
// source: https://stackoverflow.com/questions/4816099/chrome-sendrequest-error-typeerror-converting-circular-structure-to-json
24+
function stringifyCensor(censor) {
25+
var i = 0;
26+
return function (key, value) {
27+
if (i !== 0 && typeof censor === 'object' && typeof value == 'object' && censor == value) {
28+
return '[Circular]';
29+
}
30+
if (i >= 29) {
31+
// seems to be a harded maximum of 30 serialized objects?
32+
return '[Unknown]';
33+
}
34+
++i; // so we know we aren't using the original object anymore
35+
return value;
36+
};
37+
}
2338
function isSameObject(a, b) {
24-
return JSON.stringify(a) === JSON.stringify(b);
39+
return JSON.stringify(a, stringifyCensor(a)) === JSON.stringify(b, stringifyCensor(b));
2540
}
2641
exports.isSameObject = isSameObject;
2742
function reactFormatter(JSX) {
2843
return function customFormatter(cell, formatterParams, onRendered) {
29-
//cell - the cell component
30-
//formatterParams - parameters set for the column
31-
//onRendered - function to call when the formatter has been rendered
44+
// cell - the cell component
45+
// formatterParams - parameters set for the column
46+
// onRendered - function to call when the formatter has been rendered
3247
var renderFn = function () {
3348
var cellEl = cell.getElement();
3449
if (cellEl) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-tabulator",
3-
"version": "0.14.8",
3+
"version": "0.15.0",
44
"description": "React Tabulator is based on tabulator - a JS table library with many advanced features.",
55
"main": "lib/index.js",
66
"types": "lib/index.d.ts",

src/Utils.tsx

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
2137
export 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

2541
export 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

Comments
 (0)