From b15487ec03e8ed7f8c15bb67815385c2a0c1e06b Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Thu, 17 Jun 2021 14:24:39 -0600 Subject: [PATCH] Misc lint --- spec/unit/models/event.spec.ts | 6 +++--- spec/unit/utils.spec.ts | 3 ++- src/models/event.js | 9 +++++---- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/spec/unit/models/event.spec.ts b/spec/unit/models/event.spec.ts index cafb318e1..f1a8969dd 100644 --- a/spec/unit/models/event.spec.ts +++ b/spec/unit/models/event.spec.ts @@ -26,7 +26,7 @@ describe('MatrixEvent', () => { }, }); - const clone = a.getSnapshotCopy(); + const clone = a.toSnapshot(); expect(clone).toBeDefined(); expect(clone).not.toBe(a); expect(clone.event).not.toBe(a.event); @@ -54,7 +54,7 @@ describe('MatrixEvent', () => { expect(a.isEquivalentTo(a)).toBe(true); expect(b.isEquivalentTo(a)).toBe(false); expect(b.isEquivalentTo(b)).toBe(true); - expect(a.getSnapshotCopy().isEquivalentTo(a)).toBe(true); - expect(a.getSnapshotCopy().isEquivalentTo(b)).toBe(false); + expect(a.toSnapshot().isEquivalentTo(a)).toBe(true); + expect(a.toSnapshot().isEquivalentTo(b)).toBe(false); }); }); diff --git a/spec/unit/utils.spec.ts b/spec/unit/utils.spec.ts index 5867a9fde..0f01318d2 100644 --- a/spec/unit/utils.spec.ts +++ b/spec/unit/utils.spec.ts @@ -2,7 +2,8 @@ import * as utils from "../../src/utils"; import { alphabetPad, averageBetweenStrings, - baseToString, deepSortedObjectEntries, + baseToString, + deepSortedObjectEntries, DEFAULT_ALPHABET, lexicographicCompare, nextString, diff --git a/src/models/event.js b/src/models/event.js index 838cd1a3d..cce346db0 100644 --- a/src/models/event.js +++ b/src/models/event.js @@ -1148,14 +1148,15 @@ utils.extend(MatrixEvent.prototype, { /** * Get a copy/snapshot of this event. The returned copy will be loosely linked * back to this instance, though will have "frozen" event information. Other - * properties may mutate depending on the state of this instance at the time - * of snapshotting. + * properties of this MatrixEvent instance will be copied verbatim, which can + * mean they are in reference to this instance despite being on the copy too. + * Consumers should be wary of using fields which may mutate over time. * * This is meant to be used to snapshot the event details themselves, not the * features (such as sender) surrounding the event. * @returns {MatrixEvent} A snapshot of this event. */ - getSnapshotCopy() { + toSnapshot() { const ev = new MatrixEvent(JSON.parse(JSON.stringify(this.event))); for (const [p, v] of Object.entries(this)) { if (p !== "event") { // exclude the thing we just cloned @@ -1168,7 +1169,7 @@ utils.extend(MatrixEvent.prototype, { /** * Determines if this event is equivalent to the given event. This only checks * the event object itself, not the other properties of the event. Intended for - * use with getSnapshotCopy() to identify events changing. + * use with toSnapshot() to identify events changing. * @param {MatrixEvent} otherEvent The other event to check against. * @returns {boolean} True if the events are the same, false otherwise. */