co-consistent
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -18,2 +18,3 @@ /** | ||
private readonly applyExtrapolatedState; | ||
private readonly compareAction; | ||
private readonly clock; | ||
@@ -28,3 +29,3 @@ private readonly historyDuration; | ||
*/ | ||
history: Array<ContisistentTimelineEntry<S, A>>, createState: () => S, applyAction: (ref: S, action: A) => void, applyExtrapolatedState: (ref: S, state: S, time: number) => void, clock: StateClock, historyDuration: number, onChange?: (() => void) | undefined); | ||
history: Array<ContisistentTimelineEntry<S, A>>, createState: () => S, applyAction: (ref: S, action: A) => void, applyExtrapolatedState: (ref: S, state: S, time: number) => void, compareAction: (a1: A, a2: A) => number, clock: StateClock, historyDuration: number, onChange?: (() => void) | undefined); | ||
applyCurrentState(ref: S): void; | ||
@@ -34,4 +35,7 @@ private cleanObservers; | ||
getCurrentTime(): number; | ||
insert(stateTime: number, action: A): () => void; | ||
/** | ||
* @returns 'undefined' if the action is already contained (stateTime equal & compareAction function returns 0) | ||
*/ | ||
insert(stateTime: number, action: A): (() => void) | undefined; | ||
/** | ||
* | ||
@@ -38,0 +42,0 @@ * @param stateTime |
@@ -13,3 +13,3 @@ "use strict"; | ||
*/ | ||
history, createState, applyAction, applyExtrapolatedState, clock, historyDuration, onChange) { | ||
history, createState, applyAction, applyExtrapolatedState, compareAction, clock, historyDuration, onChange) { | ||
this.history = history; | ||
@@ -19,2 +19,3 @@ this.createState = createState; | ||
this.applyExtrapolatedState = applyExtrapolatedState; | ||
this.compareAction = compareAction; | ||
this.clock = clock; | ||
@@ -48,2 +49,5 @@ this.historyDuration = historyDuration; | ||
}; | ||
/** | ||
* @returns 'undefined' if the action is already contained (stateTime equal & compareAction function returns 0) | ||
*/ | ||
ConsistentTimeline.prototype.insert = function (stateTime, action) { | ||
@@ -56,7 +60,10 @@ var _this = this; | ||
var prev = this_1.history[i]; | ||
if (prev.stateTime === stateTime) { | ||
//TODO: use a second attribute for consistency | ||
throw "two event can not happen at the same time (" + stateTime + ")"; | ||
var comparison = prev.stateTime - stateTime; | ||
if (comparison === 0) { | ||
comparison = this_1.compareAction(prev.action, action); | ||
if (comparison === 0) { | ||
return { value: undefined }; | ||
} | ||
} | ||
if (prev.stateTime < stateTime) { | ||
if (comparison < 0) { | ||
if (currentTime < stateTime) { | ||
@@ -63,0 +70,0 @@ this_1.clock.jump(stateTime - currentTime); |
{ | ||
"name": "co-consistent", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "globally consistent event ordering for decentralized distributed systems", | ||
@@ -5,0 +5,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
18928
279