widget: optimize prop comparison function
This commit is contained in:
parent
0f9e694cb1
commit
769b332436
2 changed files with 19 additions and 2 deletions
|
|
@ -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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue