-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(): reimplement replay and remove dep on @most/hold
Adjust tests Reimplement replay to be more specific to most-subject Remove sink in favor of observer as that's the ES Observable spec definition Add ESLint Update all dev dependencies Update README
- Loading branch information
Showing
9 changed files
with
183 additions
and
298 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"parser": "babel-eslint", | ||
"extends": "eslint-config-cycle", | ||
"env": { | ||
"browser": true, | ||
"node": true | ||
}, | ||
"rules": { | ||
"no-class/no-class": 0, | ||
"quotes": 0 | ||
} | ||
} |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import {Stream} from 'most' | ||
import MulticastSource from 'most/lib/source/MulticastSource' | ||
|
||
function pushEvents(sink, buffer) { | ||
let i = 0 | ||
for (; i < buffer.length; ++i) { | ||
let item = buffer[i] | ||
sink.event(item.time, item.value) | ||
} | ||
} | ||
|
||
function replayAdd(sink) { | ||
const length = this._replayAdd(sink) | ||
if (this._replay.buffer.length > 0) { | ||
pushEvents(sink, this._replay.buffer) | ||
} | ||
return length | ||
} | ||
|
||
function addToBuffer(event, replay) { | ||
if (replay.buffer.length >= replay.bufferSize) { | ||
replay.buffer.shift() | ||
} | ||
replay.buffer.push(event) | ||
} | ||
|
||
function replayEvent(time, value) { | ||
if (this._replay.bufferSize > 0) { | ||
addToBuffer({time, value}, this._replay) | ||
} | ||
this._replayEvent(time, value) | ||
} | ||
|
||
class Replay { | ||
constructor(bufferSize, source) { | ||
this.source = source | ||
this.bufferSize = bufferSize | ||
this.buffer = [] | ||
} | ||
|
||
run(sink, scheduler) { | ||
if (sink._replay !== this) { | ||
sink._replay = this | ||
sink._replayAdd = sink.add | ||
sink.add = replayAdd | ||
|
||
sink._replayEvent = sink.event | ||
sink.event = replayEvent | ||
} | ||
|
||
return this.source.run(sink, scheduler) | ||
} | ||
} | ||
|
||
const replay = (bufferSize, stream) => | ||
new Stream(new MulticastSource(new Replay(bufferSize, stream.source))) | ||
|
||
export {replay} |
Oops, something went wrong.