Created
August 31, 2018 12:56
-
-
Save mweststrate/1c15569ee4ee1f7b423c06d11fe887a7 to your computer and use it in GitHub Desktop.
Sending changes to the server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async distributeFirstChange() { | |
const p = this.pendingActions[0]; | |
const response = await this.server.propose(this, { | |
base: this.confirmedState.id, | |
patches: p.patches, | |
changeId: p.id | |
}); | |
if (response === "NOPE") { | |
console.warn(this.name + ": Change rejected; outdated"); | |
// we keep the actions for now, and we will try to replay them after receiving the next change | |
} else { | |
// cool, accepted! | |
this.confirmedState = { | |
id: p.id, | |
state: applyPatches(this.confirmedState.state, p.patches) | |
}; | |
this.pendingActions.shift()!; | |
// send the next change | |
if (this.pendingActions.length) this.distributeFirstChange(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment