Skip to content

Commit

Permalink
Inheriting classes can set data themselves as long as they call `init…
Browse files Browse the repository at this point in the history
…Form()` #9819

Sometimes data is not coming from routing, but from somewhere else, such
as MatDialog data. Those use-cases should also be supported with
`isUpdatePage()`. So as long as they call themselves `initForm()` after
changing data, it's fine.
  • Loading branch information
PowerKiKi committed Aug 23, 2023
1 parent d90298c commit 21eb505
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions projects/natural/src/lib/classes/abstract-detail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class NaturalAbstractDetail<
* so the form does not switch from creation mode to update mode without an actual reload of
* model from DB (by navigating to update page).
*/
#updatePage = false;
#isUpdatePage = false;

public constructor(protected readonly key: string, public readonly service: TService) {
super();
Expand All @@ -88,7 +88,6 @@ export class NaturalAbstractDetail<
this.route.data.subscribe(data => {
this.data = merge({model: this.service.getDefaultForServer()}, data[this.key]);
this.data = merge(this.data, omit(data, [this.key]));
this.#updatePage = !!this.data.model.id;
this.initForm();
});
} else {
Expand All @@ -107,7 +106,7 @@ export class NaturalAbstractDetail<
* This should be used instead of checking `data.model.id` directly, in order to type guard and get proper typing
*/
protected isUpdatePage(): this is {data: {model: ExtractTone<TService>}} {
return this.#updatePage;
return this.#isUpdatePage;
}

public update(now = false): void {
Expand Down Expand Up @@ -229,6 +228,7 @@ export class NaturalAbstractDetail<
}

protected initForm(): void {
this.#isUpdatePage = !!this.data.model.id;
this.form = this.service.getFormGroup(this.data.model);
}

Expand Down

0 comments on commit 21eb505

Please sign in to comment.