Rename dependents --> contextForEntries

This commit is contained in:
RMidhunSuresh 2021-12-13 14:38:10 +05:30
parent d1818d2a57
commit c3bef6d4d2
2 changed files with 14 additions and 14 deletions

View file

@ -214,8 +214,8 @@ export class Timeline {
// used in replaceEntries // used in replaceEntries
static _entryUpdater(existingEntry, entry) { static _entryUpdater(existingEntry, entry) {
// ensure dependents point to the new entry instead of existingEntry // ensure other entries for which this existingEntry is a context point to the new entry instead of existingEntry
existingEntry.dependents?.forEach(event => event.setContextEntry(entry)); existingEntry.contextForEntries?.forEach(event => event.setContextEntry(entry));
entry.updateFrom(existingEntry); entry.updateFrom(existingEntry);
return entry; return entry;
} }
@ -229,7 +229,7 @@ export class Timeline {
try { try {
this._remoteEntries.getAndUpdate(entry, Timeline._entryUpdater); this._remoteEntries.getAndUpdate(entry, Timeline._entryUpdater);
// Since this entry changed, all dependent entries should be updated // Since this entry changed, all dependent entries should be updated
entry.dependents?.forEach(e => this._updateEntry(e)); entry.contextForEntries?.forEach(e => this._updateEntry(e));
} catch (err) { } catch (err) {
if (err.name === "CompareError") { if (err.name === "CompareError") {
// see FragmentIdComparer, if the replacing entry is on a fragment // see FragmentIdComparer, if the replacing entry is on a fragment
@ -262,7 +262,7 @@ export class Timeline {
const relatedEntry = this._fetchedEventEntries.get(entry.relatedEventId); const relatedEntry = this._fetchedEventEntries.get(entry.relatedEventId);
// todo: can this be called .addRelation instead? // todo: can this be called .addRelation instead?
if (relatedEntry?.addLocalRelation(entry)) { if (relatedEntry?.addLocalRelation(entry)) {
relatedEntry.dependents.forEach(e => this._updateEntry(e)); relatedEntry.contextForEntries.forEach(e => this._updateEntry(e));
} }
} }
} }
@ -272,7 +272,7 @@ export class Timeline {
for (const entry of entries) { for (const entry of entries) {
const fetchedEntry = this._fetchedEventEntries.get(entry.id); const fetchedEntry = this._fetchedEventEntries.get(entry.id);
if (fetchedEntry) { if (fetchedEntry) {
fetchedEntry.dependents.forEach(e => e.setContextEntry(entry)); fetchedEntry.contextForEntries.forEach(e => e.setContextEntry(entry));
entry.updateFrom(fetchedEntry); entry.updateFrom(fetchedEntry);
} }
} }
@ -296,7 +296,7 @@ export class Timeline {
this._fetchedEventEntries.set(id, contextEvent); this._fetchedEventEntries.set(id, contextEvent);
} }
if (contextEvent) { if (contextEvent) {
contextEvent.addDependent(entry); contextEvent.setAsContextOf(entry);
entry.setContextEntry(contextEvent); entry.setContextEntry(contextEvent);
// emit this change // emit this change
this._updateEntry(entry); this._updateEntry(entry);

View file

@ -25,7 +25,7 @@ export class EventEntry extends BaseEventEntry {
this._decryptionError = null; this._decryptionError = null;
this._decryptionResult = null; this._decryptionResult = null;
this._contextEntry = null; this._contextEntry = null;
this._dependents = null; this._contextForEntries = null;
} }
clone() { clone() {
@ -41,22 +41,22 @@ export class EventEntry extends BaseEventEntry {
if (other._decryptionError && !this._decryptionError) { if (other._decryptionError && !this._decryptionError) {
this._decryptionError = other._decryptionError; this._decryptionError = other._decryptionError;
} }
this._dependents = other._dependents; this._contextForEntries = other._contextForEntries;
} }
setContextEntry(entry) { setContextEntry(entry) {
this._contextEntry = entry; this._contextEntry = entry;
} }
addDependent(entry) { setAsContextOf(entry) {
if (!this._dependents) { if (!this._contextForEntries) {
this._dependents = []; this._contextForEntries = [];
} }
this._dependents.push(entry); this._contextForEntries.push(entry);
} }
get dependents() { get contextForEntries() {
return this._dependents; return this._contextForEntries;
} }
get event() { get event() {