Skip to content

Commit

Permalink
[desk-tool] Make helper methods in Timeline more type-safe
Browse files Browse the repository at this point in the history
  • Loading branch information
judofyr authored and rexxars committed Oct 6, 2020
1 parent 7550a39 commit 49b3a5c
Showing 1 changed file with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,10 @@ export class Timeline {

/** Returns the attributes as seen at the end of the range. */
endAttributes() {
return getAttrs(this.endDocument())
}

endDocument(): CombinedDocument {
const current = this._reconstruction
if (!current) {
throw new Error('range required')
Expand All @@ -386,11 +390,15 @@ export class Timeline {
})
}

return getAttrs(current.endDocument)
return current.endDocument
}

/** Returns the attributes as seen at the end of the range. */
startAttributes() {
return getAttrs(this.startDocument())
}

startDocument(): CombinedDocument {
const current = this._reconstruction
if (!current) {
throw new Error('range required')
Expand All @@ -409,7 +417,7 @@ export class Timeline {
)
}

return getAttrs(current.startDocument)
return current.startDocument
}

private _replayBackwards(
Expand Down Expand Up @@ -445,11 +453,8 @@ export class Timeline {
return current.diff
}

// Make sure that start/endDocument is populated
this.startAttributes()
this.endAttributes()

const doc = current.startDocument!
const doc = this.startDocument()
const finalAttributes = this.endAttributes()

let draftValue = incremental.wrap<Meta>(doc.draft, null)
let publishedValue = incremental.wrap<Meta>(doc.published, null)
Expand Down Expand Up @@ -500,7 +505,6 @@ export class Timeline {
}

const finalValue = incremental.getType(draftValue) === 'null' ? publishedValue : draftValue
const finalAttributes = getAttrs(current.endDocument!)
current.diff = diffValue(this, initialValue, initialAttributes, finalValue, finalAttributes)
return current.diff
}
Expand Down

0 comments on commit 49b3a5c

Please sign in to comment.