Commit 7c64aec4 authored by Jörg Richter's avatar Jörg Richter

Model: add `equals()` to DMXObject

See dmx-platform/dmx-platform#317
parent 3719df29
Pipeline #8385 passed with stage
in 2 seconds
This diff is collapsed.
......@@ -6,7 +6,7 @@ import typeCache from './type-cache'
import permCache from './permission-cache'
import utils from './utils'
console.log('[DMX] Client API 2019/11/01')
console.log('[DMX] Client API 2019/11/02')
export default {
......
......@@ -102,6 +102,37 @@ class DMXObject {
return this
}
/**
* Returns true if this object equals the given object.
*
* In case of composite objects this method can only be used if all child topics are present (according to type
* definition) in both objects. Child topics can have empty values. Consider calling fillChildren() on both objects
* before calling this method.
*/
equals (object) {
return this.id === object.id &&
this.uri === object.uri &&
this.typeUri === object.typeUri &&
this.value === object.value &&
this.childrenEquals(object.children)
}
childrenEquals (children) {
return !this.type.compDefs.some(compDef => {
const compDefUri = compDef.compDefUri
const child = this.children[compDefUri]
const _child = children[compDefUri]
if (compDef.isOne()) {
return !child.equals(_child)
} else if (child.length !== _child.length) {
return true
} else {
let i = 0
return child.some(child => !child.equals(_child[i++]))
}
})
}
clone () {
return utils.clone(this)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment