remove redundant guards before snapshot.merge (#32937)
* remove redundant guards before snapshot.merge * fix(viewmodels): restore RedactedBodyViewModel setting guard * docs(mvvm): note Snapshot.merge change detection
This commit is contained in:
@@ -86,8 +86,6 @@ export class DecryptionFailureBodyViewModel
|
||||
}
|
||||
|
||||
public setDecryptionFailureCode(decryptionFailureCode: DecryptionFailureCode | null): void {
|
||||
if (this.props.decryptionFailureCode === decryptionFailureCode) return;
|
||||
|
||||
this.props.decryptionFailureCode = decryptionFailureCode;
|
||||
this.snapshot.merge({
|
||||
decryptionFailureReason: DecryptionFailureBodyViewModel.getDecryptionReasonFromCode(decryptionFailureCode),
|
||||
|
||||
@@ -99,17 +99,10 @@ export class ReactionsRowViewModel
|
||||
const nextIsVisible = this.props.isActionable && this.props.reactionGroupCount > 0;
|
||||
const nextShowAllButtonVisible =
|
||||
this.props.reactionGroupCount > MAX_ITEMS_WHEN_LIMITED + 1 && !this.props.showAll;
|
||||
const updates: Partial<ReactionsRowViewSnapshot> = {};
|
||||
|
||||
if (this.snapshot.current.isVisible !== nextIsVisible) {
|
||||
updates.isVisible = nextIsVisible;
|
||||
}
|
||||
if (this.snapshot.current.showAllButtonVisible !== nextShowAllButtonVisible) {
|
||||
updates.showAllButtonVisible = nextShowAllButtonVisible;
|
||||
}
|
||||
if (Object.keys(updates).length > 0) {
|
||||
this.snapshot.merge(updates);
|
||||
}
|
||||
this.snapshot.merge({
|
||||
isVisible: nextIsVisible,
|
||||
showAllButtonVisible: nextShowAllButtonVisible,
|
||||
});
|
||||
}
|
||||
|
||||
public setCanReact(canReact: boolean): void {
|
||||
|
||||
@@ -83,30 +83,15 @@ export class RedactedBodyViewModel
|
||||
}
|
||||
|
||||
public setEvent(mxEvent: MatrixEvent): void {
|
||||
if (this.props.mxEvent === mxEvent) return;
|
||||
|
||||
this.props = { ...this.props, mxEvent };
|
||||
|
||||
const text = RedactedBodyViewModel.computeText(this.props);
|
||||
const tooltip = RedactedBodyViewModel.computeTooltip(this.props.mxEvent, this.showTwelveHour);
|
||||
const updates: Partial<RedactedBodyViewSnapshot> = {};
|
||||
|
||||
if (this.snapshot.current.text !== text) {
|
||||
updates.text = text;
|
||||
}
|
||||
if (this.snapshot.current.tooltip !== tooltip) {
|
||||
updates.tooltip = tooltip;
|
||||
}
|
||||
|
||||
if (Object.keys(updates).length > 0) {
|
||||
this.snapshot.merge(updates);
|
||||
}
|
||||
this.snapshot.merge({ text, tooltip });
|
||||
}
|
||||
|
||||
private updateTooltip(): void {
|
||||
const tooltip = RedactedBodyViewModel.computeTooltip(this.props.mxEvent, this.showTwelveHour);
|
||||
if (this.snapshot.current.tooltip !== tooltip) {
|
||||
this.snapshot.merge({ tooltip });
|
||||
}
|
||||
this.snapshot.merge({ tooltip });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,9 +210,7 @@ export class RoomListItemViewModel
|
||||
*/
|
||||
private async loadAndSetMessagePreview(): Promise<void> {
|
||||
const messagePreview = await this.loadMessagePreview();
|
||||
if (messagePreview !== this.snapshot.current.messagePreview) {
|
||||
this.snapshot.merge({ messagePreview });
|
||||
}
|
||||
this.snapshot.merge({ messagePreview });
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -98,6 +98,6 @@ export class ResizerViewModel
|
||||
};
|
||||
|
||||
public onBlur = (): void => {
|
||||
if (this.getSnapshot().isFocusedViaKeyboard) this.snapshot.merge({ isFocusedViaKeyboard: false });
|
||||
this.snapshot.merge({ isFocusedViaKeyboard: false });
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user