From 3380a9d514f361f9559ba369b222c24a711f1e11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Farkas=20J=C3=B3zsef?= Date: Tue, 13 Dec 2016 22:58:18 +0100 Subject: [PATCH] Fix config cleaner --- src/store/storage/index.ts | 4 ++-- src/store/storage/local.ts | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/store/storage/index.ts b/src/store/storage/index.ts index a7a29312..da4b555d 100644 --- a/src/store/storage/index.ts +++ b/src/store/storage/index.ts @@ -44,7 +44,7 @@ export class DataStorage { } // Local storage else { - this._environment = new Local(); + this._environment = new Local(this.uhkConfiguration.dataModelVersion); } } @@ -88,7 +88,7 @@ export class DataStorage { getConfiguration(): UhkConfiguration { let config: UhkConfiguration = this._environment.getConfig(); - if (!config || config.dataModelVersion !== this.uhkConfiguration.dataModelVersion) { + if (!config) { config = this.uhkConfiguration; } return config; diff --git a/src/store/storage/local.ts b/src/store/storage/local.ts index c5d73be8..3fe2c64a 100644 --- a/src/store/storage/local.ts +++ b/src/store/storage/local.ts @@ -2,14 +2,17 @@ import { UhkConfiguration } from '../../config-serializer/config-items/UhkConfig export class Local { - constructor() { } + constructor(private dataModelVersion: number) { } getConfig(): UhkConfiguration { - let configJson = localStorage.getItem('config'); + let configJsonString = localStorage.getItem('config'); let config: UhkConfiguration; - if (configJson) { - config = new UhkConfiguration().fromJsObject(JSON.parse(configJson)); + if (configJsonString) { + const configJsonObject = JSON.parse(configJsonString); + if (configJsonObject.dataModelVersion === this.dataModelVersion) { + config = new UhkConfiguration().fromJsObject(configJsonObject); + } } return config;