widget: optimize prop comparison function

This commit is contained in:
jean-emmanuel 2018-08-26 11:41:46 +02:00
parent 17ceff4293
commit 4577914d4e
2 changed files with 19 additions and 2 deletions

View file

@ -19,6 +19,23 @@ module.exports = {
return copy
},
deepEqual: function(a, b) {
// about 2,75 x faster than JSON.stringify(a) === JSON.stringify(b)
var ta = typeof a,
tb = typeof b
if (ta !== tb) {
return false
} else if (ta === 'object') {
return JSON.stringify(a) === JSON.stringify(b)
} else {
return a === b
}
}
}

View file

@ -7,7 +7,7 @@ var EventEmitter = require('../../events/event-emitter'),
{iconify} = require('../../ui/utils'),
resize = require('../../events/resize'),
OscReceiver = require('./osc-receiver'),
{deepCopy} = require('../../utils'),
{deepCopy, deepEqual} = require('../../utils'),
updateWidget = ()=>{}
@ -418,7 +418,7 @@ class Widget extends EventEmitter {
let propValue = this.resolveProp(propName, undefined, false),
oldPropValue = this.getProp(propName)
if (JSON.stringify(oldPropValue) !== JSON.stringify(propValue)) {
if (!deepEqual(oldPropValue, propValue)) {
if (!this.constructor.dynamicProps.includes(propName)) {