diff options
Diffstat (limited to 'web/src/js/utils.js')
-rw-r--r-- | web/src/js/utils.js | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/web/src/js/utils.js b/web/src/js/utils.js index d3b99bd0..cc17c565 100644 --- a/web/src/js/utils.js +++ b/web/src/js/utils.js @@ -1,7 +1,9 @@ -import _ from "lodash"; +import _ from 'lodash' +import React from 'react' +import shallowEqual from 'shallowequal' window._ = _; -window.React = require("react"); +window.React = React; export var Key = { UP: 38, @@ -106,15 +108,27 @@ fetchApi.put = (url, json, options) => fetchApi( } ) - export function getDiff(obj1, obj2) { let result = {...obj2}; for(let key in obj1) { if(_.isEqual(obj2[key], obj1[key])) - result[key] = undefined; + result[key] = undefined else if(!(Array.isArray(obj2[key]) && Array.isArray(obj1[key])) && typeof obj2[key] == 'object' && typeof obj1[key] == 'object') - result[key] = getDiff(obj1[key], obj2[key]); + result[key] = getDiff(obj1[key], obj2[key]) + } + return result +} + +export const pure = renderFn => class extends React.Component { + static displayName = renderFn.name + + shouldComponentUpdate(nextProps) { + console.log(!shallowEqual(this.props, nextProps)) + return !shallowEqual(this.props, nextProps) + } + + render() { + return renderFn(this.props) } - return result; } |