mirror of
https://github.com/jwetzell/showbridge-webui.git
synced 2026-09-06 22:08:58 +00:00
fix infinite change loop
This commit is contained in:
+2
-18
@@ -80,15 +80,7 @@ export class App {
|
|||||||
console.error('modules is undefined, not updating');
|
console.error('modules is undefined, not updating');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.configService.currentlyShownConfig.update((config) => {
|
this.configService.updateModules(modules);
|
||||||
if (config) {
|
|
||||||
return {
|
|
||||||
...config,
|
|
||||||
modules: modules,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return config;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
routesUpdated(routes: RouteConfig[] | undefined) {
|
routesUpdated(routes: RouteConfig[] | undefined) {
|
||||||
@@ -96,14 +88,6 @@ export class App {
|
|||||||
console.error('routes is undefined, not updating');
|
console.error('routes is undefined, not updating');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.configService.currentlyShownConfig.update((config) => {
|
this.configService.updateRoutes(routes);
|
||||||
if (config) {
|
|
||||||
return {
|
|
||||||
...config,
|
|
||||||
routes: routes,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return config;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { MatInputModule } from '@angular/material/input';
|
|||||||
import { MatTabsModule } from '@angular/material/tabs';
|
import { MatTabsModule } from '@angular/material/tabs';
|
||||||
import { MatTooltipModule } from '@angular/material/tooltip';
|
import { MatTooltipModule } from '@angular/material/tooltip';
|
||||||
import { SomeJSONSchema } from 'ajv/dist/types/json-schema';
|
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 { Subscription } from 'rxjs';
|
||||||
import { ParamInfo, ParamsFormInfo } from '../../models/form';
|
import { ParamInfo, ParamsFormInfo } from '../../models/form';
|
||||||
import { cleanParams, schemaToParamsFormInfo } from '../../utils/params';
|
import { cleanParams, schemaToParamsFormInfo } from '../../utils/params';
|
||||||
@@ -103,6 +103,10 @@ export class ParamsFormComponent implements OnDestroy {
|
|||||||
const paramsSchema = this.paramsSchema();
|
const paramsSchema = this.paramsSchema();
|
||||||
if (paramsSchema) {
|
if (paramsSchema) {
|
||||||
const params = cleanParams(paramsSchema, this.paramsFormInfo?.formGroup.value);
|
const params = cleanParams(paramsSchema, this.paramsFormInfo?.formGroup.value);
|
||||||
|
if (isEqual(params, this.data())) {
|
||||||
|
// NOTE(jwetzell): no update
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.updated.emit(params);
|
this.updated.emit(params);
|
||||||
} else {
|
} else {
|
||||||
console.error('params-form: no paramsSchema loaded');
|
console.error('params-form: no paramsSchema loaded');
|
||||||
|
|||||||
@@ -117,6 +117,42 @@ export class ConfigService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateCurrentlyShownConfig(config: Config) {
|
updateCurrentlyShownConfig(config: Config) {
|
||||||
|
if (isEqual(config, this.currentlyShownConfig())) {
|
||||||
|
// NOTE(jwetzell): no update
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.currentlyShownConfig.set(cloneDeep(config));
|
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,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user