From 0891c4bd343d633fb0f51a120b4da67b1468f9f2 Mon Sep 17 00:00:00 2001 From: Hugo Agbonon Date: Thu, 24 Mar 2016 16:36:21 +0100 Subject: [PATCH] Prevent a crash when working with symbols --- demo/src/js/DemoApp.jsx | 6 +++++- demo/src/js/reducers.js | 4 +++- src/ActionPreview.jsx | 2 ++ src/JSONDiff.jsx | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/demo/src/js/DemoApp.jsx b/demo/src/js/DemoApp.jsx index 6865fcb..842ea5e 100644 --- a/demo/src/js/DemoApp.jsx +++ b/demo/src/js/DemoApp.jsx @@ -109,6 +109,9 @@ class DemoApp extends React.Component { +
@@ -155,6 +158,7 @@ export default connect( type: 'HUGE_PAYLOAD', payload: Array.from({ length: 10000 }).map((_, i) => i) }), - addFunction: () => ({ type: 'ADD_FUNCTION' }) + addFunction: () => ({ type: 'ADD_FUNCTION' }), + addSymbol: () => ({ type: 'ADD_SYMBOL' }) } )(DemoApp); diff --git a/demo/src/js/reducers.js b/demo/src/js/reducers.js index e930896..5330200 100644 --- a/demo/src/js/reducers.js +++ b/demo/src/js/reducers.js @@ -90,5 +90,7 @@ export default combineReducers({ str => str + '!' ) : state, addFunction: (state=null, action) => action.type === 'ADD_FUNCTION' ? - { f: FUNC } : state + { f: FUNC } : state, + addSymbol: (state=null, action) => action.type === 'ADD_SYMBOL' ? + { s: Symbol('symbol') } : state }); diff --git a/src/ActionPreview.jsx b/src/ActionPreview.jsx index 2a61691..ff1aca8 100644 --- a/src/ActionPreview.jsx +++ b/src/ActionPreview.jsx @@ -30,6 +30,8 @@ function getItemString(createTheme, type, data) { return 'fn'; } else if (typeof val === 'string') { return `"${val.substr(0, 10) + (val.length > 10 ? '…' : '')}"` + } else if (typeof val === 'symbol') { + return 'symbol' } else { return val; } diff --git a/src/JSONDiff.jsx b/src/JSONDiff.jsx index f4ff3a6..80dc57e 100644 --- a/src/JSONDiff.jsx +++ b/src/JSONDiff.jsx @@ -1,7 +1,7 @@ import React from 'react'; import JSONTree from '@alexkuz/react-json-tree'; import themeable from './themeable'; -import stringify from 'javascript-stringify'; +import { stringify } from 'jsan'; function stringifyAndShrink(val) { const str = stringify(val);