-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Harden views #3845
Harden views #3845
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,20 @@ export class View<T extends PlainObject = PlainObject> { | |
*/ | ||
readonly value: Partial<T> = null; | ||
|
||
private readonly model: ViewManagerModel; | ||
|
||
get name(): string { | ||
return this.info?.name ?? 'Default'; | ||
} | ||
|
||
get token(): string { | ||
return this.info?.token ?? null; | ||
} | ||
|
||
get type(): string { | ||
return this.model.type; | ||
} | ||
|
||
get isDefault(): boolean { | ||
return !this.info; | ||
} | ||
|
@@ -33,24 +47,25 @@ export class View<T extends PlainObject = PlainObject> { | |
return this.info?.lastUpdated ?? null; | ||
} | ||
|
||
get token(): string { | ||
return this.info?.token ?? null; | ||
get typedName(): string { | ||
return `${this.model.typeDisplayName} '${this.name}'`; | ||
} | ||
|
||
static fromBlob<T>(blob: JsonBlob, model: ViewManagerModel): View<T> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See comment in constructor re: generic ViewManagerModel type |
||
return new View(new ViewInfo(blob, model), blob.value); | ||
return new View(new ViewInfo(blob, model), blob.value, model); | ||
} | ||
|
||
static createDefault<T>(): View<T> { | ||
return new View(null, {}); | ||
static createDefault<T>(model: ViewManagerModel): View<T> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See comment in constructor re: generic |
||
return new View(null, {}, model); | ||
} | ||
|
||
withUpdatedValue(value: Partial<T>): View<T> { | ||
return new View(this.info, value); | ||
return new View(this.info, value, this.model); | ||
} | ||
|
||
constructor(info: ViewInfo, value: Partial<T>) { | ||
constructor(info: ViewInfo, value: Partial<T>, model: ViewManagerModel) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Believe this should be |
||
this.info = info; | ||
this.value = value; | ||
this.model = model; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wonder if it would make sense to have a getTypedName helper that takes a view and a model or view and a type rather than having it be a top-level property on view itself