diff --git a/libs/common/src/platform/services/default-active-user-state.provider.ts b/libs/common/src/platform/services/default-active-user-state.provider.ts index 24792e07dc9..abbe2b8ea1c 100644 --- a/libs/common/src/platform/services/default-active-user-state.provider.ts +++ b/libs/common/src/platform/services/default-active-user-state.provider.ts @@ -103,7 +103,7 @@ class DefaultActiveUserState implements ActiveUserState { return null; } const jsonData = await this.chosenStorageLocation.get>(key); - const data = keyDefinition.serializer(jsonData); + const data = keyDefinition.deserializer(jsonData); return data; }), tap((data) => { @@ -149,7 +149,7 @@ class DefaultActiveUserState implements ActiveUserState { } const key = userKeyBuilder(activeUser.id, this.keyDefinition); const data = (await this.chosenStorageLocation.get(key)) as Jsonify; - return this.keyDefinition.serializer(data); + return this.keyDefinition.deserializer(data); } createDerived( @@ -169,7 +169,7 @@ class DefaultActiveUserState implements ActiveUserState { private async seedInitial(key: string): Promise { const data = await this.chosenStorageLocation.get>(key); this.seededInitial = true; - return this.keyDefinition.serializer(data); + return this.keyDefinition.deserializer(data); } private chooseStorage(storageLocation: StorageLocation): AbstractStorageService { diff --git a/libs/common/src/platform/services/default-global-state.provider.ts b/libs/common/src/platform/services/default-global-state.provider.ts index 449985d80dc..bce08afd756 100644 --- a/libs/common/src/platform/services/default-global-state.provider.ts +++ b/libs/common/src/platform/services/default-global-state.provider.ts @@ -28,7 +28,7 @@ class GlobalStateImplementation implements GlobalState { this.storageKey = globalKeyBuilder(this.keyDefinition); this.seededPromise = this.chosenLocation.get>(this.storageKey).then((data) => { - const serializedData = this.keyDefinition.serializer(data); + const serializedData = this.keyDefinition.deserializer(data); this.stateSubject.next(serializedData); }); @@ -45,7 +45,7 @@ class GlobalStateImplementation implements GlobalState { async getFromState(): Promise { const data = await this.chosenLocation.get>(this.storageKey); - return this.keyDefinition.serializer(data); + return this.keyDefinition.deserializer(data); } } diff --git a/libs/common/src/platform/types/key-definition.ts b/libs/common/src/platform/types/key-definition.ts index 57c3ce6c1fe..64ccaf095a6 100644 --- a/libs/common/src/platform/types/key-definition.ts +++ b/libs/common/src/platform/types/key-definition.ts @@ -12,34 +12,34 @@ export class KeyDefinition { * Creates a new instance of a KeyDefinition * @param stateDefinition The state definition for which this key belongs to. * @param key The name of the key, this should be unique per domain - * @param serializer A function to use to safely convert your type from json to your expected type. + * @param deserializer A function to use to safely convert your type from json to your expected type. */ constructor( readonly stateDefinition: StateDefinition, readonly key: string, - readonly serializer: (jsonValue: Jsonify) => T + readonly deserializer: (jsonValue: Jsonify) => T ) {} static array( stateDefinition: StateDefinition, key: string, - serializer: (jsonValue: Jsonify) => T + deserializer: (jsonValue: Jsonify) => T ) { return new KeyDefinition(stateDefinition, key, (jsonValue) => { // TODO: Should we handle null for them, I feel like we should discourage null for an array? - return jsonValue.map((v) => serializer(v)); + return jsonValue.map((v) => deserializer(v)); }); } static record( stateDefinition: StateDefinition, key: string, - serializer: (jsonValue: Jsonify) => T + deserializer: (jsonValue: Jsonify) => T ) { return new KeyDefinition>(stateDefinition, key, (jsonValue) => { const output: Record = {}; for (const key in jsonValue) { - output[key] = serializer((jsonValue as Record>)[key]); + output[key] = deserializer((jsonValue as Record>)[key]); } return output; });