fix: lazier about triggering change on spec updates

This commit is contained in:
pelikhan 2023-02-23 11:22:36 -08:00
Родитель 205ec69944
Коммит 459676250a
2 изменённых файлов: 15 добавлений и 7 удалений

Просмотреть файл

@ -1424,9 +1424,12 @@ ${dev
* @param services
*/
setCustomServiceSpecifications(services: jdspec.ServiceSpec[]) {
loadServiceSpecifications(services)
this.clearDevices()
this.emit(CHANGE)
const res = loadServiceSpecifications(services)
if (res.changed) {
this.clearDevices()
this.emit(CHANGE)
}
return res
}
/**

Просмотреть файл

@ -38,7 +38,10 @@ export function loadServiceSpecifications(
): {
added: jdspec.ServiceSpec[]
errors: { message: string; spec: jdspec.ServiceSpec }[]
changed: boolean
} {
const previous = _serviceSpecifications
// combine builtin specs with new specs
const builtins = (serviceSpecificationData ||
[]) as any as jdspec.ServiceSpec[]
@ -79,10 +82,12 @@ export function loadServiceSpecifications(
}
}
_serviceSpecifications = specs
_serviceSpecificationMap = undefined
return { added, errors }
const changed = JSON.stringify(previous) !== JSON.stringify(specs)
if (changed) {
_serviceSpecifications = specs
_serviceSpecificationMap = undefined
}
return { added, errors, changed }
}
/**