stump-cycle-dom
Version:
The standard DOM Driver for Cycle.js, based on Snabbdom
76 lines • 1.8 kB
JavaScript
import { Stream } from 'xstream';
var UponStartOperator = /** @class */ (function () {
function UponStartOperator(op, ins) {
this.op = op;
this.ins = ins;
this.type = 'uponStart';
this.out = null;
}
UponStartOperator.prototype._start = function (out) {
this.op();
this.out = out;
this.ins._add(this);
};
UponStartOperator.prototype._stop = function () {
this.ins._remove(this);
this.out = null;
};
UponStartOperator.prototype._n = function (t) {
this.out._n(t);
};
UponStartOperator.prototype._e = function (err) {
this.out._e(err);
};
UponStartOperator.prototype._c = function () {
this.out._c();
};
return UponStartOperator;
}());
/**
* Delays periodic events by a given time period.
*
* Marble diagram:
*
* ```text
* 1----2--3--4----5|
* delay(60)
* ---1----2--3--4----5|
* ```
*
* Example:
*
* ```js
* import fromDiagram from 'xstream/extra/fromDiagram'
* import uponStart from './uponStart'
*
* let is_complete = false
* const stream = fromDiagram('1----2--3--4----5|')
* .compose(uponStart(() => {
* is_complete = true
* }))
*
* stream.addListener({
* next: i => console.log(i),
* error: err => console.error(err),
* complete: () => console.log('completed')
* })
* ```
*
* ```text
* > 1 (after 60 ms)
* > 2 (after 160 ms)
* > 3 (after 220 ms)
* > 4 (after 280 ms)
* > 5 (after 380 ms)
* > completed
* ```
*
* @param {Function} op The amount of silence required in milliseconds.
* @return {Stream}
*/
export default function uponStart(op) {
return function uponStartOperator(ins) {
return new Stream(new UponStartOperator(op, ins));
};
}
//# sourceMappingURL=uponStart.js.map