Browse Source

fix(lib): disable mutating the injected readonly data

pull/6337/head
KenTandrian 1 month ago
parent
commit
d520e69345
  1. 11
      libs/ui/src/lib/historical-market-data-editor/historical-market-data-editor-dialog/historical-market-data-editor-dialog.component.ts
  2. 3
      libs/ui/src/lib/historical-market-data-editor/historical-market-data-editor-dialog/historical-market-data-editor-dialog.html

11
libs/ui/src/lib/historical-market-data-editor/historical-market-data-editor-dialog/historical-market-data-editor-dialog.component.ts

@ -7,7 +7,8 @@ import {
CUSTOM_ELEMENTS_SCHEMA, CUSTOM_ELEMENTS_SCHEMA,
inject, inject,
OnDestroy, OnDestroy,
OnInit OnInit,
signal
} from '@angular/core'; } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { MatButtonModule } from '@angular/material/button'; import { MatButtonModule } from '@angular/material/button';
@ -51,6 +52,8 @@ export class GfHistoricalMarketDataEditorDialogComponent
public readonly data = public readonly data =
inject<HistoricalMarketDataEditorDialogParams>(MAT_DIALOG_DATA); inject<HistoricalMarketDataEditorDialogParams>(MAT_DIALOG_DATA);
protected readonly marketPrice = signal(this.data.marketPrice);
private readonly locale = private readonly locale =
this.data.user.settings.locale ?? inject<string>(MAT_DATE_LOCALE); this.data.user.settings.locale ?? inject<string>(MAT_DATE_LOCALE);
private readonly unsubscribeSubject = new Subject<void>(); private readonly unsubscribeSubject = new Subject<void>();
@ -82,14 +85,14 @@ export class GfHistoricalMarketDataEditorDialogComponent
}) })
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntil(this.unsubscribeSubject))
.subscribe(({ marketPrice }) => { .subscribe(({ marketPrice }) => {
this.data.marketPrice = marketPrice; this.marketPrice.set(marketPrice);
this.changeDetectorRef.markForCheck(); this.changeDetectorRef.markForCheck();
}); });
} }
public onUpdate() { public onUpdate() {
if (this.data.marketPrice === undefined) { if (this.marketPrice() === undefined) {
return; return;
} }
@ -100,7 +103,7 @@ export class GfHistoricalMarketDataEditorDialogComponent
marketData: [ marketData: [
{ {
date: this.data.dateString, date: this.data.dateString,
marketPrice: this.data.marketPrice marketPrice: this.marketPrice()
} }
] ]
}, },

3
libs/ui/src/lib/historical-market-data-editor/historical-market-data-editor-dialog/historical-market-data-editor-dialog.html

@ -28,7 +28,8 @@
matInput matInput
name="marketPrice" name="marketPrice"
type="number" type="number"
[(ngModel)]="data.marketPrice" [ngModel]="marketPrice()"
(ngModelChange)="marketPrice.set($event)"
/> />
<span class="ml-2" matTextSuffix>{{ data.currency }}</span> <span class="ml-2" matTextSuffix>{{ data.currency }}</span>
</mat-form-field> </mat-form-field>

Loading…
Cancel
Save