avocado-old/packages/net/packet/synchronized.js
2019-09-16 21:52:08 -05:00

38 lines
739 B
JavaScript

export function SynchronizedMixin(Superclass) {
return class Synchronized extends Superclass {
constructor() {
super();
this._idempotentPackets = [];
}
cleanPackets() {
this._idempotentPackets = [];
}
packetsAreIdempotent() {
return true;
}
packets(informed) {
if (this._idempotentPackets.length > 0) {
return this._idempotentPackets;
}
let packets = this.packetsForTick(informed);
if (!packets) {
return [];
}
packets = Array.isArray(packets) ? packets : [packets];
if (this.packetsAreIdempotent()) {
this._idempotentPackets = packets;
}
return packets;
}
packetsForTick(informed) {}
}
}