mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-06 08:25:19 +01:00
20 lines
451 B
JavaScript
20 lines
451 B
JavaScript
import {StreamBase} from './base';
|
|
import {NOT_INITIALIZED} from './utils';
|
|
|
|
export class PairwiseStream extends StreamBase {
|
|
|
|
constructor(stream, first) {
|
|
super();
|
|
this.stream = stream;
|
|
this.latest = first === undefined ? NOT_INITIALIZED : first;
|
|
}
|
|
|
|
attach(observer) {
|
|
return this.stream.attach(v => {
|
|
if (this.latest !== NOT_INITIALIZED) {
|
|
observer([this.latest, v]);
|
|
}
|
|
this.latest = v;
|
|
});
|
|
}
|
|
}
|