diff options
author | hmhealey <harrisonmhealey@gmail.com> | 2016-02-08 13:35:38 -0500 |
---|---|---|
committer | hmhealey <harrisonmhealey@gmail.com> | 2016-02-08 13:35:38 -0500 |
commit | fa069e4e1f4fc730fd29ab9699240480d84c84d3 (patch) | |
tree | 16b2a10af595b6e3ba8b8d408121d6b386d83ffc /web/react | |
parent | 96cb7345dafbf07027acb9dc05fc7d0808a4ac38 (diff) | |
download | chat-fa069e4e1f4fc730fd29ab9699240480d84c84d3.tar.gz chat-fa069e4e1f4fc730fd29ab9699240480d84c84d3.tar.bz2 chat-fa069e4e1f4fc730fd29ab9699240480d84c84d3.zip |
Added support for ES6 Maps to Utils.areObjectsEqual
Diffstat (limited to 'web/react')
-rw-r--r-- | web/react/utils/utils.jsx | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/web/react/utils/utils.jsx b/web/react/utils/utils.jsx index 4beec8d64..376053792 100644 --- a/web/react/utils/utils.jsx +++ b/web/react/utils/utils.jsx @@ -392,6 +392,10 @@ export function areObjectsEqual(x, y) { return x.toString() === y.toString(); } + if (x instanceof Map && y instanceof Map) { + return areMapsEqual(x, y); + } + // At last checking prototypes as good a we can if (!(x instanceof Object && y instanceof Object)) { return false; @@ -456,6 +460,24 @@ export function areObjectsEqual(x, y) { return true; } +export function areMapsEqual(a, b) { + if (a.size !== b.size) { + return false; + } + + for (const [key, value] of a) { + if (!b.has(key)) { + return false; + } + + if (!areObjectsEqual(value, b.get(key))) { + return false; + } + } + + return true; +} + export function replaceHtmlEntities(text) { var tagsToReplace = { '&': '&', |