From 0ef6696c0a69ec39a04b3e4239807c17ab8fdb7c Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 22 Jul 2020 10:52:45 -0600 Subject: [PATCH] Don't re-freeze AsyncStore's state all the time --- src/stores/AsyncStore.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/stores/AsyncStore.ts b/src/stores/AsyncStore.ts index 1977e808dc..1f310f003c 100644 --- a/src/stores/AsyncStore.ts +++ b/src/stores/AsyncStore.ts @@ -42,7 +42,7 @@ export const UPDATE_EVENT = "update"; * help prevent lock conflicts. */ export abstract class AsyncStore extends EventEmitter { - private storeState: T; + private storeState: Readonly; private lock = new AwaitLock(); private readonly dispatcherRef: string; @@ -62,7 +62,7 @@ export abstract class AsyncStore extends EventEmitter { * The current state of the store. Cannot be mutated. */ protected get state(): T { - return Object.freeze(this.storeState); + return this.storeState; } /** @@ -79,7 +79,7 @@ export abstract class AsyncStore extends EventEmitter { protected async updateState(newState: T | Object) { await this.lock.acquireAsync(); try { - this.storeState = Object.assign({}, this.storeState, newState); + this.storeState = Object.freeze(Object.assign({}, this.storeState, newState)); this.emit(UPDATE_EVENT, this); } finally { await this.lock.release(); @@ -94,7 +94,7 @@ export abstract class AsyncStore extends EventEmitter { protected async reset(newState: T | Object = null, quiet = false) { await this.lock.acquireAsync(); try { - this.storeState = (newState || {}); + this.storeState = Object.freeze((newState || {})); if (!quiet) this.emit(UPDATE_EVENT, this); } finally { await this.lock.release();