From 67c4df49a89e76ffd5173c23a040357c5e3983c5 Mon Sep 17 00:00:00 2001 From: Joel Wetzell Date: Wed, 6 May 2026 16:53:40 -0500 Subject: [PATCH] fix infinite change loop --- src/app/app.ts | 20 ++--------- src/app/components/params-form/params-form.ts | 6 +++- src/app/services/config.ts | 36 +++++++++++++++++++ 3 files changed, 43 insertions(+), 19 deletions(-) diff --git a/src/app/app.ts b/src/app/app.ts index b2e92c6..6bed734 100644 --- a/src/app/app.ts +++ b/src/app/app.ts @@ -80,15 +80,7 @@ export class App { console.error('modules is undefined, not updating'); return; } - this.configService.currentlyShownConfig.update((config) => { - if (config) { - return { - ...config, - modules: modules, - }; - } - return config; - }); + this.configService.updateModules(modules); } routesUpdated(routes: RouteConfig[] | undefined) { @@ -96,14 +88,6 @@ export class App { console.error('routes is undefined, not updating'); return; } - this.configService.currentlyShownConfig.update((config) => { - if (config) { - return { - ...config, - routes: routes, - }; - } - return config; - }); + this.configService.updateRoutes(routes); } } diff --git a/src/app/components/params-form/params-form.ts b/src/app/components/params-form/params-form.ts index 114f590..72203c1 100644 --- a/src/app/components/params-form/params-form.ts +++ b/src/app/components/params-form/params-form.ts @@ -7,7 +7,7 @@ import { MatInputModule } from '@angular/material/input'; import { MatTabsModule } from '@angular/material/tabs'; import { MatTooltipModule } from '@angular/material/tooltip'; import { SomeJSONSchema } from 'ajv/dist/types/json-schema'; -import { cloneDeep, has } from 'lodash-es'; +import { cloneDeep, has, isEqual } from 'lodash-es'; import { Subscription } from 'rxjs'; import { ParamInfo, ParamsFormInfo } from '../../models/form'; import { cleanParams, schemaToParamsFormInfo } from '../../utils/params'; @@ -103,6 +103,10 @@ export class ParamsFormComponent implements OnDestroy { const paramsSchema = this.paramsSchema(); if (paramsSchema) { const params = cleanParams(paramsSchema, this.paramsFormInfo?.formGroup.value); + if (isEqual(params, this.data())) { + // NOTE(jwetzell): no update + return; + } this.updated.emit(params); } else { console.error('params-form: no paramsSchema loaded'); diff --git a/src/app/services/config.ts b/src/app/services/config.ts index 500b6d0..6212f39 100644 --- a/src/app/services/config.ts +++ b/src/app/services/config.ts @@ -117,6 +117,42 @@ export class ConfigService { } updateCurrentlyShownConfig(config: Config) { + if (isEqual(config, this.currentlyShownConfig())) { + // NOTE(jwetzell): no update + return; + } this.currentlyShownConfig.set(cloneDeep(config)); } + + updateModules(modules: ModuleConfig[]) { + const currentConfig = this.currentlyShownConfig(); + if (!currentConfig) { + console.error('No currently shown config to update modules on'); + return; + } + + if (isEqual(modules, currentConfig.modules)) { + return; + } + this.currentlyShownConfig.set({ + ...currentConfig, + modules: modules, + }); + } + + updateRoutes(routes: RouteConfig[]) { + const currentConfig = this.currentlyShownConfig(); + if (!currentConfig) { + console.error('No currently shown config to update routes on'); + return; + } + + if (isEqual(routes, currentConfig.routes)) { + return; + } + this.currentlyShownConfig.set({ + ...currentConfig, + routes: routes, + }); + } }