Skip to content

Commit

Permalink
fix(apps): Properly set the initial value state for isDecorated on mo…
Browse files Browse the repository at this point in the history
…dels

Because the model's isDecorated value is set by static methods before construction, we cannot use the initialization support found in typescript.
  • Loading branch information
josephperrott committed Apr 19, 2022
1 parent 8a7e038 commit 2a9fe46
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions apps/shared/models/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ export type Constructor<T> = new (...args: any[]) => T;
/** Base class for all models to inherit from. */
export abstract class BaseModel<T> {
data!: T;
/** The symbol marker for the function which decorated the model for either app or server. */
private isDecorated = false;
/**
* Whether the model is decorated, undecorated models will be undefined.
* Because this value is set by the static properties, we cannot initialize a value for it.
* */
private isDecorated: true | undefined;

/** The data as stored in Firestore. */
constructor(data: T) {
if (this.isDecorated === false) {
if (this.isDecorated !== true) {
throw Error();
}
this.data = data;
this.setData(data);
}

Expand Down

0 comments on commit 2a9fe46

Please sign in to comment.