1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-07-31 15:24:23 +03:00

Misc lint

This commit is contained in:
Travis Ralston
2021-06-17 14:24:39 -06:00
parent 17402e8475
commit b15487ec03
3 changed files with 10 additions and 8 deletions

View File

@ -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);
});
});

View File

@ -2,7 +2,8 @@ import * as utils from "../../src/utils";
import {
alphabetPad,
averageBetweenStrings,
baseToString, deepSortedObjectEntries,
baseToString,
deepSortedObjectEntries,
DEFAULT_ALPHABET,
lexicographicCompare,
nextString,

View File

@ -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.
*/