UNPKG

@actyx/sdk

Version:
54 lines 1.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.omitObservable = exports.takeWhileInclusive = void 0; /* * Actyx SDK: Functions for writing distributed apps * deployed on peer-to-peer networks, without any servers. * * Copyright (C) 2021 Actyx AG */ /* eslint-disable @typescript-eslint/no-explicit-any */ const rxjs_1 = require("../../node_modules/rxjs"); const typescript_1 = require("./typescript"); /** * Just like takeWhile but will also emit the element on which the predicate has fired * @param predicate the predicate for this operator */ const takeWhileInclusive = (predicate) => (source) => new rxjs_1.Observable((subscriber) => { let index = 0; let sub = true; const s = source.subscribe({ next: (value) => { const result = predicate(value, index); index += 1; subscriber.next(value); if (!result) { subscriber.complete(); typeof sub === 'boolean' ? (sub = false) : sub.unsubscribe(); } }, error: (err) => subscriber.error(err), }); if (!sub) { s.unsubscribe(); } sub = s; return sub; }); exports.takeWhileInclusive = takeWhileInclusive; const omitObservable = (stoppedByError, callback, obs) => { try { // Not passing an error callback seems to cause bad behavior with RXjs internally const sub = obs.subscribe({ next: callback, error: stoppedByError, }); return () => sub.unsubscribe(); } catch (err) { stoppedByError && stoppedByError(err); return typescript_1.noop; } }; exports.omitObservable = omitObservable; //# sourceMappingURL=observable.js.map