Skip to content

Commit

Permalink
Add unsafe addSnapshot method to SnapshotInterpolation class
Browse files Browse the repository at this point in the history
  • Loading branch information
jarvis394 committed Jul 11, 2024
1 parent 6aac41a commit bba90dc
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/SnapshotInterpolation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,23 @@ export class SnapshotInterpolation<T extends Snapshot = Snapshot> {
return this._timeOffset
}

public addSnapshot(snapshot: T) {
public updateTimeOffsetBySnapshot(snapshot: T) {
const timeNow = SnapshotInterpolation.Now()
const timeSnapshot = snapshot.timestamp
const timeOffset = timeNow - timeSnapshot

this._timeOffset = timeOffset
}

public addSnapshot(snapshot: T) {
this.updateTimeOffsetBySnapshot(snapshot)
this.vault.add(snapshot)
}

public unsafe_addSnapshotWithoutSort(snapshot: T) {
this.updateTimeOffsetBySnapshot(snapshot)
this.vault.unsafe_addWithoutSort(snapshot)
}

public calcInterpolation<D extends keyof T['state']>(
parameters: ObjectToMethods<InferFromDeepState<T, D>>,
deep: D
Expand Down

0 comments on commit bba90dc

Please sign in to comment.