@logic-pad/core
Version:
27 lines (26 loc) • 931 B
JavaScript
import { configEquals } from './config.js';
export default class Configurable {
get configs() {
return null;
}
/**
* Check if this instruction is equal to another instruction by comparing their IDs and configs.
*
* @param other The other instruction to compare to.
* @returns Whether the two instructions are equal.
*/
equals(other) {
const configs = this.configs;
if (configs === null)
return true;
// this is only possible when an instruction is instantiated before the class itself is completely defined
// in this case, we can only compare the instances themselves
if (configs === undefined)
return this === other;
for (const config of this.configs) {
if (!configEquals(config.type, this[config.field], other[config.field]))
return false;
}
return true;
}
}