Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

wonka

Package Overview
Dependencies
Maintainers
1
Versions
83
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wonka - npm Package Compare versions

Comparing version 6.0.0 to 6.1.0

dist/types/combine.d.ts

2

dist/types/helpers.d.ts
import { TalkbackFn, TeardownFn, Start, Push } from './types';
export declare const teardownPlaceholder: TeardownFn;
export declare const talkbackPlaceholder: TalkbackFn;
export declare const teardownPlaceholder: TeardownFn;
export declare function start<T>(talkback: TalkbackFn): Start<T>;
export declare function push<T>(value: T): Push<T>;

@@ -5,4 +5,5 @@ export * from './types';

export * from './sinks';
export * from './combine';
export * from './observable';
export * from './callbag';
export * from './pipe';
import { Source, Operator } from './types';
export declare function buffer<S, T>(notifier: Source<S>): Operator<T, T[]>;
export declare function combine<A, B>(sourceA: Source<A>, sourceB: Source<B>): Source<[A, B]>;
export declare function concatMap<In, Out>(map: (value: In) => Source<Out>): Operator<In, Out>;

@@ -5,0 +4,0 @@ export declare function concatAll<T>(source: Source<Source<T>>): Source<T>;

import { Source, Observer, Subject, TeardownFn } from './types';
export declare function fromArray<T>(array: T[]): Source<T>;
export declare function lazy<T>(make: () => Source<T>): Source<T>;
export declare function fromAsyncIterable<T>(iterable: AsyncIterable<T>): Source<T>;
export declare function fromIterable<T>(iterable: Iterable<T> | AsyncIterable<T>): Source<T>;
export declare const fromArray: <T>(array: T[]) => Source<T>;
export declare function fromValue<T>(value: T): Source<T>;

@@ -4,0 +7,0 @@ export declare function make<T>(produce: (observer: Observer<T>) => TeardownFn): Source<T>;

@@ -29,2 +29,4 @@ /** A talkback signal is used to tell a [Source] that either the [Sink] is ready for new values or that the stream should be cancelled */

export declare type Operator<In, Out> = (a: Source<In>) => Source<Out>;
/** Extracts the type of a given Source */
export declare type TypeOfSource<T> = T extends Source<infer U> ? U : never;
export interface Subscription {

@@ -31,0 +33,0 @@ unsubscribe(): void;

@@ -5,4 +5,6 @@ Object.defineProperty(exports, "__esModule", {

var talkbackPlaceholder = e => {};
var teardownPlaceholder = () => {};
var e = teardownPlaceholder;
function start(e) {

@@ -20,60 +22,33 @@ var r = [ e ];

function fromArray(e) {
return r => {
var t = !1;
var i = !1;
var s = !1;
var f = 0;
r(start((a => {
if (1 === a) {
t = !0;
} else if (i) {
s = !0;
} else {
for (s = i = !0; s && !t; f++) {
if (f < e.length) {
s = !1;
r(push(e[f]));
} else {
t = !0;
r(0);
}
}
i = !1;
}
})));
};
}
var identity = e => e;
function concatMap(e) {
return r => t => {
var i = [];
var s = talkbackPlaceholder;
var f = talkbackPlaceholder;
var a = !1;
function concatMap(r) {
return t => i => {
var s = [];
var a = e;
var f = e;
var n = !1;
var l = !1;
var n = !1;
var o = !1;
function applyInnerSource(r) {
n = !0;
r((r => {
if (0 === r) {
if (n) {
n = !1;
if (i.length) {
applyInnerSource(e(i.shift()));
} else if (o) {
t(0);
} else if (!a) {
a = !0;
s(0);
var u = !1;
function applyInnerSource(e) {
o = !0;
e((e => {
if (0 === e) {
if (o) {
o = !1;
if (s.length) {
applyInnerSource(r(s.shift()));
} else if (u) {
i(0);
} else if (!n) {
n = !0;
a(0);
}
}
} else if (0 === r.tag) {
} else if (0 === e.tag) {
l = !1;
(f = r[0])(0);
} else if (n) {
t(r);
(f = e[0])(0);
} else if (o) {
i(e);
if (l) {

@@ -87,35 +62,35 @@ l = !1;

}
r((r => {
if (o) {} else if (0 === r) {
o = !0;
if (!n && !i.length) {
t(0);
t((e => {
if (u) {} else if (0 === e) {
u = !0;
if (!o && !s.length) {
i(0);
}
} else if (0 === r.tag) {
s = r[0];
} else if (0 === e.tag) {
a = e[0];
} else {
a = !1;
if (n) {
i.push(r[0]);
n = !1;
if (o) {
s.push(e[0]);
} else {
applyInnerSource(e(r[0]));
applyInnerSource(r(e[0]));
}
}
}));
t(start((e => {
i(start((e => {
if (1 === e) {
if (!o) {
o = !0;
s(1);
if (!u) {
u = !0;
a(1);
}
if (n) {
n = !1;
if (o) {
o = !1;
f(1);
}
} else {
if (!o && !a) {
a = !0;
s(0);
if (!u && !n) {
n = !0;
a(0);
}
if (n && !l) {
if (o && !l) {
l = !0;

@@ -133,33 +108,33 @@ f(0);

function mergeMap(e) {
return r => t => {
var i = [];
var s = talkbackPlaceholder;
function mergeMap(r) {
return t => i => {
var s = [];
var a = e;
var f = !1;
var a = !1;
r((r => {
if (a) {} else if (0 === r) {
a = !0;
if (!i.length) {
t(0);
var n = !1;
t((t => {
if (n) {} else if (0 === t) {
n = !0;
if (!s.length) {
i(0);
}
} else if (0 === r.tag) {
s = r[0];
} else if (0 === t.tag) {
a = t[0];
} else {
f = !1;
!function applyInnerSource(e) {
var r = talkbackPlaceholder;
e((e => {
!function applyInnerSource(r) {
var t = e;
r((e => {
if (0 === e) {
if (i.length) {
var l = i.indexOf(r);
if (l > -1) {
(i = i.slice()).splice(l, 1);
if (s.length) {
var r = s.indexOf(t);
if (r > -1) {
(s = s.slice()).splice(r, 1);
}
if (!i.length) {
if (a) {
t(0);
if (!s.length) {
if (n) {
i(0);
} else if (!f) {
f = !0;
s(0);
a(0);
}

@@ -169,35 +144,35 @@ }

} else if (0 === e.tag) {
i.push(r = e[0]);
r(0);
} else if (i.length) {
t(e);
r(0);
s.push(t = e[0]);
t(0);
} else if (s.length) {
i(e);
t(0);
}
}));
}(e(r[0]));
}(r(t[0]));
if (!f) {
f = !0;
s(0);
a(0);
}
}
}));
t(start((e => {
i(start((e => {
if (1 === e) {
if (!a) {
a = !0;
s(1);
if (!n) {
n = !0;
a(1);
}
for (var r = 0, t = i, l = i.length; r < l; r++) {
for (var r = 0, t = s, i = s.length; r < i; r++) {
t[r](1);
}
i.length = 0;
s.length = 0;
} else {
if (!a && !f) {
if (!n && !f) {
f = !0;
s(0);
a(0);
} else {
f = !1;
}
for (var n = 0, o = i, u = i.length; n < u; n++) {
o[n](0);
for (var l = 0, o = s, u = s.length; l < u; l++) {
o[l](0);
}

@@ -236,26 +211,66 @@ }

function switchMap(e) {
return r => t => {
var i = talkbackPlaceholder;
var s = talkbackPlaceholder;
function share(r) {
var t = [];
var i = e;
var s = !1;
return e => {
t.push(e);
if (1 === t.length) {
r((e => {
if (0 === e) {
for (var r = 0, a = t, f = t.length; r < f; r++) {
a[r](0);
}
t.length = 0;
} else if (0 === e.tag) {
i = e[0];
} else {
s = !1;
for (var n = 0, l = t, o = t.length; n < o; n++) {
l[n](e);
}
}
}));
}
e(start((r => {
if (1 === r) {
var a = t.indexOf(e);
if (a > -1) {
(t = t.slice()).splice(a, 1);
}
if (!t.length) {
i(1);
}
} else if (!s) {
s = !0;
i(0);
}
})));
};
}
function switchMap(r) {
return t => i => {
var s = e;
var a = e;
var f = !1;
var a = !1;
var n = !1;
var l = !1;
var n = !1;
r((r => {
if (n) {} else if (0 === r) {
n = !0;
var o = !1;
t((t => {
if (o) {} else if (0 === t) {
o = !0;
if (!l) {
t(0);
i(0);
}
} else if (0 === r.tag) {
i = r[0];
} else if (0 === t.tag) {
s = t[0];
} else {
if (l) {
s(1);
s = talkbackPlaceholder;
a(1);
a = e;
}
if (!f) {
f = !0;
i(0);
s(0);
} else {

@@ -269,42 +284,42 @@ f = !1;

l = !1;
if (n) {
t(0);
if (o) {
i(0);
} else if (!f) {
f = !0;
i(0);
s(0);
}
} else if (0 === e.tag) {
a = !1;
(s = e[0])(0);
n = !1;
(a = e[0])(0);
} else {
t(e);
if (!a) {
s(0);
i(e);
if (!n) {
a(0);
} else {
a = !1;
n = !1;
}
}
}));
}(e(r[0]));
}(r(t[0]));
}
}));
t(start((e => {
i(start((e => {
if (1 === e) {
if (!n) {
n = !0;
i(1);
if (!o) {
o = !0;
s(1);
}
if (l) {
l = !1;
s(1);
a(1);
}
} else {
if (!n && !f) {
if (!o && !f) {
f = !0;
i(0);
}
if (l && !a) {
a = !0;
s(0);
}
if (l && !n) {
n = !0;
a(0);
}
}

@@ -315,21 +330,139 @@ })));

function subscribe(e) {
function fromAsyncIterable(e) {
return r => {
var t = talkbackPlaceholder;
var t = e[Symbol.asyncIterator]();
var i = !1;
r((r => {
if (0 === r) {
var s = !1;
var a = !1;
var f;
r(start((async e => {
if (1 === e) {
i = !0;
} else if (0 === r.tag) {
(t = r[0])(0);
} else if (!i) {
e(r[0]);
t(0);
if (t.return) {
t.return();
}
} else if (s) {
a = !0;
} else {
for (a = s = !0; a && !i; ) {
if ((f = await t.next()).done) {
i = !0;
if (t.return) {
await t.return();
}
r(0);
} else {
try {
a = !1;
r(push(f.value));
} catch (e) {
if (t.throw) {
if (i = !!(await t.throw(e)).done) {
r(0);
}
} else {
throw e;
}
}
}
}
s = !1;
}
})));
};
}
function fromIterable(e) {
if (e[Symbol.asyncIterator]) {
return fromAsyncIterable(e);
}
return r => {
var t = e[Symbol.iterator]();
var i = !1;
var s = !1;
var a = !1;
var f;
r(start((e => {
if (1 === e) {
i = !0;
if (t.return) {
t.return();
}
} else if (s) {
a = !0;
} else {
for (a = s = !0; a && !i; ) {
if ((f = t.next()).done) {
i = !0;
if (t.return) {
t.return();
}
r(0);
} else {
try {
a = !1;
r(push(f.value));
} catch (e) {
if (t.throw) {
if (i = !!t.throw(e).done) {
r(0);
}
} else {
throw e;
}
}
}
}
s = !1;
}
})));
};
}
var r = fromIterable;
function make(e) {
return r => {
var t = !1;
var i = e({
next(e) {
if (!t) {
r(push(e));
}
},
complete() {
if (!t) {
t = !0;
r(0);
}
}
});
r(start((e => {
if (1 === e && !t) {
t = !0;
i();
}
})));
};
}
function subscribe(r) {
return t => {
var i = e;
var s = !1;
t((e => {
if (0 === e) {
s = !0;
} else if (0 === e.tag) {
(i = e[0])(0);
} else if (!s) {
r(e[0]);
i(0);
}
}));
return {
unsubscribe() {
if (!i) {
i = !0;
t(1);
if (!s) {
s = !0;
i(1);
}

@@ -341,56 +474,119 @@ }

var e = "function" == typeof Symbol ? Symbol.observable || (Symbol.observable = Symbol("observable")) : "@@observable";
function zip(r) {
var t = Object.keys(r).length;
return i => {
var s = new Set;
var a = Array.isArray(r) ? new Array(t).fill(e) : {};
var f = Array.isArray(r) ? new Array(t) : {};
var n = !1;
var l = !1;
var o = !1;
var u = 0;
var loop = function(v) {
r[v]((c => {
if (0 === c) {
if (u >= t - 1) {
o = !0;
i(0);
} else {
u++;
}
} else if (0 === c.tag) {
a[v] = c[0];
} else if (!o) {
f[v] = c[0];
s.add(v);
if (!n && s.size < t) {
if (!l) {
for (var p in r) {
if (!s.has(p)) {
(a[p] || e)(0);
}
}
} else {
l = !1;
}
} else {
n = !0;
l = !1;
i(push(Array.isArray(f) ? f.slice() : {
...f
}));
}
}
}));
};
for (var v in r) {
loop(v);
}
i(start((e => {
if (o) {} else if (1 === e) {
o = !0;
for (var r in a) {
a[r](1);
}
} else if (!l) {
l = !0;
for (var t in a) {
a[t](0);
}
}
})));
};
}
exports.buffer = function buffer(e) {
return r => t => {
var i = [];
var s = talkbackPlaceholder;
var f = talkbackPlaceholder;
var a = !1;
var observableSymbol = () => Symbol.observable || (Symbol.observable = Symbol("observable"));
exports.buffer = function buffer(r) {
return t => i => {
var s = [];
var a = e;
var f = e;
var n = !1;
var l = !1;
r((r => {
if (l) {} else if (0 === r) {
t((e => {
if (l) {} else if (0 === e) {
l = !0;
f(1);
if (i.length) {
t(push(i));
if (s.length) {
i(push(s));
}
t(0);
} else if (0 === r.tag) {
s = r[0];
e((e => {
i(0);
} else if (0 === e.tag) {
a = e[0];
r((e => {
if (l) {} else if (0 === e) {
l = !0;
s(1);
if (i.length) {
t(push(i));
a(1);
if (s.length) {
i(push(s));
}
t(0);
i(0);
} else if (0 === e.tag) {
f = e[0];
} else if (i.length) {
var r = push(i);
i = [];
t(r);
} else if (s.length) {
var r = push(s);
s = [];
i(r);
}
}));
} else {
i.push(r[0]);
if (!a) {
a = !0;
s(0);
s.push(e[0]);
if (!n) {
n = !0;
a(0);
f(0);
} else {
a = !1;
n = !1;
}
}
}));
t(start((e => {
i(start((e => {
if (1 === e && !l) {
l = !0;
s(1);
a(1);
f(1);
} else if (!l && !a) {
a = !0;
s(0);
} else if (!l && !n) {
n = !0;
a(0);
f(0);

@@ -402,71 +598,8 @@ }

exports.combine = function combine(e, r) {
return t => {
var i;
var s;
var f = talkbackPlaceholder;
var a = talkbackPlaceholder;
var l = !1;
var n = !1;
var o = !1;
e((e => {
if (0 === e) {
if (!n) {
n = !0;
} else {
o = !0;
t(0);
}
} else if (0 === e.tag) {
f = e[0];
} else if (void 0 === s) {
i = e[0];
if (!l) {
a(0);
} else {
l = !1;
}
} else if (!o) {
l = !1;
t(push([ i = e[0], s ]));
}
}));
r((e => {
if (0 === e) {
if (!n) {
n = !0;
} else {
o = !0;
t(0);
}
} else if (0 === e.tag) {
a = e[0];
} else if (void 0 === i) {
s = e[0];
if (!l) {
f(0);
} else {
l = !1;
}
} else if (!o) {
l = !1;
t(push([ i, s = e[0] ]));
}
}));
t(start((e => {
if (o) {} else if (1 === e) {
o = !0;
f(1);
a(1);
} else if (!l) {
l = !0;
f(0);
a(0);
}
})));
};
exports.combine = function combine(...e) {
return zip(e);
};
exports.concat = function concat(e) {
return concatAll(fromArray(e));
return concatAll(r(e));
};

@@ -482,6 +615,6 @@

var s = !1;
var f = !1;
var a = !1;
r((r => {
if (f) {} else if (0 === r) {
f = !0;
if (a) {} else if (0 === r) {
a = !0;
if (i) {

@@ -493,6 +626,6 @@ s = !0;

} else if (0 === r.tag) {
var a = r[0];
var f = r[0];
t(start((e => {
if (1 === e && !f) {
f = !0;
if (1 === e && !a) {
a = !0;
s = !1;

@@ -502,5 +635,5 @@ if (i) {

}
a(1);
} else if (!f) {
a(0);
f(1);
} else if (!a) {
f(0);
}

@@ -528,3 +661,3 @@ })));

r((r => {
if ("number" != typeof r && 0 === r.tag) {
if (0 !== r && 0 === r.tag) {
t(r);

@@ -556,15 +689,15 @@ } else {

exports.filter = function filter(e) {
return r => t => {
var i = talkbackPlaceholder;
r((r => {
if (0 === r) {
t(0);
} else if (0 === r.tag) {
i = r[0];
t(r);
} else if (!e(r[0])) {
exports.filter = function filter(r) {
return t => i => {
var s = e;
t((e => {
if (0 === e) {
i(0);
} else if (0 === e.tag) {
s = e[0];
i(e);
} else if (!r(e[0])) {
s(0);
} else {
t(r);
i(e);
}

@@ -583,4 +716,6 @@ }));

exports.fromArray = fromArray;
exports.fromArray = r;
exports.fromAsyncIterable = fromAsyncIterable;
exports.fromCallbag = function fromCallbag(e) {

@@ -591,11 +726,7 @@ return r => {

r(start((e => {
if (0 === e) {
t(1);
} else {
t(2);
}
t(e + 1);
})));
} else if (1 === e) {
r(push(t));
} else if (2 === e) {
} else {
r(0);

@@ -608,30 +739,25 @@ }

exports.fromDomEvent = function fromDomEvent(e, r) {
return t => {
var handler = e => {
t(push(e));
};
t(start((t => {
if (1 === t) {
e.removeEventListener(r, handler);
}
})));
e.addEventListener(r, handler);
};
return make((t => {
e.addEventListener(r, t.next);
return () => e.removeEventListener(r, t.next);
}));
};
exports.fromObservable = function fromObservable(r) {
var t = r[e] ? r[e]() : r;
return e => {
var r = t.subscribe({
next(r) {
e(push(r));
exports.fromIterable = fromIterable;
exports.fromObservable = function fromObservable(e) {
e = e[observableSymbol()] ? e[observableSymbol()]() : e;
return r => {
var t = e.subscribe({
next(e) {
r(push(e));
},
complete() {
e(0);
r(0);
},
error() {}
});
e(start((e => {
r(start((e => {
if (1 === e) {
r.unsubscribe();
t.unsubscribe();
}

@@ -643,16 +769,11 @@ })));

exports.fromPromise = function fromPromise(e) {
return r => {
var t = !1;
return make((r => {
e.then((e => {
if (!t) {
r(push(e));
r(0);
}
Promise.resolve(e).then((() => {
r.next(e);
r.complete();
}));
}));
r(start((e => {
if (1 === e) {
t = !0;
}
})));
};
return teardownPlaceholder;
}));
};

@@ -676,69 +797,32 @@

exports.interval = function interval(e) {
return r => {
return make((r => {
var t = 0;
var i = setInterval((() => {
r(push(t++));
}), e);
r(start((e => {
if (1 === e) {
clearInterval(i);
}
})));
};
var i = setInterval((() => r.next(t++)), e);
return () => clearInterval(i);
}));
};
exports.make = function make(e) {
return r => {
var t = !1;
var i = e({
next(e) {
if (!t) {
r(push(e));
}
},
complete() {
if (!t) {
t = !0;
r(0);
}
}
});
r(start((e => {
if (1 === e && !t) {
t = !0;
i();
}
})));
};
exports.lazy = function lazy(e) {
return r => e()(r);
};
exports.make = make;
exports.makeSubject = function makeSubject() {
var e = [];
var r = !1;
var e;
var r;
return {
source(r) {
e.push(r);
r(start((t => {
if (1 === t) {
var i = e.indexOf(r);
if (i > -1) {
(e = e.slice()).splice(i, 1);
}
}
})));
},
next(t) {
if (!r) {
var i = push(t);
for (var s = 0, f = e, a = e.length; s < a; s++) {
f[s](i);
}
source: share(make((t => {
e = t.next;
r = t.complete;
return teardownPlaceholder;
}))),
next(r) {
if (e) {
e(r);
}
},
complete() {
if (!r) {
r = !0;
for (var t = 0, i = e, s = e.length; t < s; t++) {
i[t](0);
}
if (r) {
r();
}

@@ -760,3 +844,3 @@ }

exports.merge = function merge(e) {
return mergeAll(fromArray(e));
return mergeAll(r(e));
};

@@ -768,4 +852,4 @@

exports.never = e => {
e(start(talkbackPlaceholder));
exports.never = r => {
r(start(e));
};

@@ -814,8 +898,8 @@

exports.pipe = function pipe() {
var e = arguments[0];
for (var r = 1, t = arguments.length; r < t; r++) {
e = arguments[r](e);
exports.pipe = function pipe(...e) {
var r = e[0];
for (var t = 1, i = e.length; t < i; t++) {
r = e[t](r);
}
return e;
return r;
};

@@ -827,49 +911,49 @@

exports.sample = function sample(e) {
return r => t => {
var i = talkbackPlaceholder;
var s = talkbackPlaceholder;
exports.sample = function sample(r) {
return t => i => {
var s = e;
var a = e;
var f;
var a = !1;
var n = !1;
var l = !1;
r((e => {
t((e => {
if (l) {} else if (0 === e) {
l = !0;
s(1);
t(0);
a(1);
i(0);
} else if (0 === e.tag) {
i = e[0];
s = e[0];
} else {
f = e[0];
if (!a) {
a = !0;
if (!n) {
n = !0;
a(0);
s(0);
i(0);
} else {
a = !1;
n = !1;
}
}
}));
e((e => {
r((e => {
if (l) {} else if (0 === e) {
l = !0;
i(1);
t(0);
s(1);
i(0);
} else if (0 === e.tag) {
s = e[0];
a = e[0];
} else if (void 0 !== f) {
var r = push(f);
f = void 0;
t(r);
i(r);
}
}));
t(start((e => {
i(start((e => {
if (1 === e && !l) {
l = !0;
i(1);
s(1);
} else if (!l && !a) {
a = !0;
i(0);
a(1);
} else if (!l && !n) {
n = !0;
s(0);
a(0);
}

@@ -895,56 +979,18 @@ })));

exports.share = function share(e) {
var r = [];
var t = talkbackPlaceholder;
var i = !1;
return s => {
r.push(s);
if (1 === r.length) {
e((e => {
if (0 === e) {
for (var s = 0, f = r, a = r.length; s < a; s++) {
f[s](0);
}
r.length = 0;
} else if (0 === e.tag) {
t = e[0];
} else {
i = !1;
for (var l = 0, n = r, o = r.length; l < o; l++) {
n[l](e);
}
}
}));
}
s(start((e => {
if (1 === e) {
var f = r.indexOf(s);
if (f > -1) {
(r = r.slice()).splice(f, 1);
}
if (!r.length) {
t(1);
}
} else if (!i) {
i = !0;
t(0);
}
})));
};
};
exports.share = share;
exports.skip = function skip(e) {
return r => t => {
var i = talkbackPlaceholder;
exports.skip = function skip(r) {
return t => i => {
var s = e;
r((e => {
var a = r;
t((e => {
if (0 === e) {
t(0);
i(0);
} else if (0 === e.tag) {
i = e[0];
t(e);
} else if (s-- > 0) {
i(0);
s = e[0];
i(e);
} else if (a-- > 0) {
s(0);
} else {
t(e);
i(e);
}

@@ -955,55 +1001,55 @@ }));

exports.skipUntil = function skipUntil(e) {
return r => t => {
var i = talkbackPlaceholder;
var s = talkbackPlaceholder;
exports.skipUntil = function skipUntil(r) {
return t => i => {
var s = e;
var a = e;
var f = !0;
var a = !1;
var n = !1;
var l = !1;
r((r => {
if (l) {} else if (0 === r) {
t((e => {
if (l) {} else if (0 === e) {
l = !0;
if (f) {
s(1);
a(1);
}
t(0);
} else if (0 === r.tag) {
i = r[0];
e((e => {
i(0);
} else if (0 === e.tag) {
s = e[0];
r((e => {
if (0 === e) {
if (f) {
l = !0;
i(1);
s(1);
}
} else if (0 === e.tag) {
(s = e[0])(0);
(a = e[0])(0);
} else {
f = !1;
s(1);
a(1);
}
}));
} else if (!f) {
a = !1;
t(r);
} else if (!a) {
a = !0;
i(0);
n = !1;
i(e);
} else if (!n) {
n = !0;
s(0);
a(0);
} else {
a = !1;
n = !1;
}
}));
t(start((e => {
i(start((e => {
if (1 === e && !l) {
l = !0;
i(1);
s(1);
if (f) {
s(1);
a(1);
}
} else if (!l && !a) {
a = !0;
} else if (!l && !n) {
n = !0;
if (f) {
s(0);
a(0);
}
i(0);
s(0);
}

@@ -1014,21 +1060,21 @@ })));

exports.skipWhile = function skipWhile(e) {
return r => t => {
var i = talkbackPlaceholder;
var s = !0;
r((r => {
if (0 === r) {
t(0);
} else if (0 === r.tag) {
i = r[0];
t(r);
} else if (s) {
if (e(r[0])) {
i(0);
exports.skipWhile = function skipWhile(r) {
return t => i => {
var s = e;
var a = !0;
t((e => {
if (0 === e) {
i(0);
} else if (0 === e.tag) {
s = e[0];
i(e);
} else if (a) {
if (r(e[0])) {
s(0);
} else {
s = !1;
t(r);
a = !1;
i(e);
}
} else {
t(r);
i(e);
}

@@ -1047,36 +1093,36 @@ }));

exports.take = function take(e) {
return r => t => {
var i = talkbackPlaceholder;
var s = !1;
exports.take = function take(r) {
return t => i => {
var s = e;
var a = !1;
var f = 0;
r((r => {
if (s) {} else if (0 === r) {
s = !0;
t(0);
} else if (0 === r.tag) {
if (e <= 0) {
s = !0;
t(0);
r[0](1);
t((e => {
if (a) {} else if (0 === e) {
a = !0;
i(0);
} else if (0 === e.tag) {
if (r <= 0) {
a = !0;
i(0);
e[0](1);
} else {
i = r[0];
s = e[0];
}
} else if (f++ < e) {
t(r);
if (!s && f >= e) {
s = !0;
t(0);
i(1);
} else if (f++ < r) {
i(e);
if (!a && f >= r) {
a = !0;
i(0);
s(1);
}
} else {
t(r);
i(e);
}
}));
t(start((r => {
if (1 === r && !s) {
s = !0;
i(1);
} else if (0 === r && !s && f < e) {
i(0);
i(start((e => {
if (1 === e && !a) {
a = !0;
s(1);
} else if (0 === e && !a && f < r) {
s(0);
}

@@ -1087,22 +1133,22 @@ })));

exports.takeLast = function takeLast(e) {
return r => t => {
var i = [];
var s = talkbackPlaceholder;
r((r => {
if (0 === r) {
fromArray(i)(t);
} else if (0 === r.tag) {
if (e <= 0) {
r[0](1);
fromArray(i)(t);
exports.takeLast = function takeLast(t) {
return i => s => {
var a = [];
var f = e;
i((e => {
if (0 === e) {
r(a)(s);
} else if (0 === e.tag) {
if (t <= 0) {
e[0](1);
r(a)(s);
} else {
(s = r[0])(0);
(f = e[0])(0);
}
} else {
if (i.length >= e && e) {
i.shift();
if (a.length >= t && t) {
a.shift();
}
i.push(r[0]);
s(0);
a.push(e[0]);
f(0);
}

@@ -1113,34 +1159,34 @@ }));

exports.takeUntil = function takeUntil(e) {
return r => t => {
var i = talkbackPlaceholder;
var s = talkbackPlaceholder;
exports.takeUntil = function takeUntil(r) {
return t => i => {
var s = e;
var a = e;
var f = !1;
r((r => {
if (f) {} else if (0 === r) {
t((e => {
if (f) {} else if (0 === e) {
f = !0;
s(1);
t(0);
} else if (0 === r.tag) {
i = r[0];
e((e => {
a(1);
i(0);
} else if (0 === e.tag) {
s = e[0];
r((e => {
if (0 === e) {} else if (0 === e.tag) {
(s = e[0])(0);
(a = e[0])(0);
} else {
f = !0;
i(1);
t(0);
s(1);
i(0);
}
}));
} else {
t(r);
i(e);
}
}));
t(start((e => {
i(start((e => {
if (1 === e && !f) {
f = !0;
i(1);
s(1);
a(1);
} else if (!f) {
i(0);
s(0);
}

@@ -1151,19 +1197,19 @@ })));

exports.takeWhile = function takeWhile(e) {
return r => t => {
var i = talkbackPlaceholder;
var s = !1;
r((r => {
if (s) {} else if (0 === r) {
s = !0;
t(0);
} else if (0 === r.tag) {
i = r[0];
t(r);
} else if (!e(r[0])) {
s = !0;
t(0);
i(1);
exports.takeWhile = function takeWhile(r) {
return t => i => {
var s = e;
var a = !1;
t((e => {
if (a) {} else if (0 === e) {
a = !0;
i(0);
} else if (0 === e.tag) {
s = e[0];
i(e);
} else if (!r(e[0])) {
a = !0;
i(0);
s(1);
} else {
t(r);
i(e);
}

@@ -1187,3 +1233,3 @@ }));

} else if (0 === r.tag) {
var f = r[0];
var a = r[0];
t(start((e => {

@@ -1194,5 +1240,5 @@ if (1 === e) {

}
f(1);
a(1);
} else {
f(0);
a(0);
}

@@ -1215,20 +1261,20 @@ })));

exports.toArray = function toArray(e) {
var r = [];
var t = talkbackPlaceholder;
var i = !1;
e((e => {
exports.toArray = function toArray(r) {
var t = [];
var i = e;
var s = !1;
r((e => {
if (0 === e) {
i = !0;
s = !0;
} else if (0 === e.tag) {
(t = e[0])(0);
(i = e[0])(0);
} else {
r.push(e[0]);
t(0);
t.push(e[0]);
i(0);
}
}));
if (!i) {
t(1);
if (!s) {
i(1);
}
return r;
return t;
};

@@ -1244,6 +1290,4 @@

t(0, (r => {
if (1 === r) {
e[0](0);
} else if (2 === r) {
e[0](1);
if (r < 3) {
e[0](r - 1);
}

@@ -1260,44 +1304,45 @@ }));

exports.toObservable = function toObservable(r) {
var t = {
subscribe(e) {
var t = talkbackPlaceholder;
var i = !1;
r((r => {
if (i) {} else if (0 === r) {
i = !0;
e.complete();
} else if (0 === r.tag) {
(t = r[0])(0);
return {
subscribe(t) {
var i = e;
var s = !1;
r((e => {
if (s) {} else if (0 === e) {
s = !0;
t.complete();
} else if (0 === e.tag) {
(i = e[0])(0);
} else {
e.next(r[0]);
t(0);
t.next(e[0]);
i(0);
}
}));
var s = {
var a = {
closed: !1,
unsubscribe() {
s.closed = !0;
i = !0;
t(1);
a.closed = !0;
s = !0;
i(1);
}
};
return s;
return a;
},
[observableSymbol()]() {
return this;
}
};
t[e] = () => t;
return t;
};
exports.toPromise = function toPromise(e) {
return new Promise((r => {
var t = talkbackPlaceholder;
var i;
e((e => {
exports.toPromise = function toPromise(r) {
return new Promise((t => {
var i = e;
var s;
r((e => {
if (0 === e) {
r(i);
t(s);
} else if (0 === e.tag) {
(t = e[0])(0);
(i = e[0])(0);
} else {
i = e[0];
t(0);
s = e[0];
i(0);
}

@@ -1307,2 +1352,4 @@ }));

};
exports.zip = zip;
//# sourceMappingURL=wonka.js.map
{
"name": "wonka",
"description": "A tiny but capable push & pull stream library for TypeScript and Flow",
"version": "6.0.0",
"version": "6.1.0",
"author": "0no.co <hi@0no.co>",

@@ -73,2 +73,3 @@ "source": "./src/index.ts",

"jest": {
"testRegex": "(src/.*(\\.|/)(test|spec))\\.ts$",
"transform": {

@@ -109,5 +110,5 @@ "^.+\\.tsx?$": "@sucrase/jest-plugin"

"tslib": "^2.4.0",
"typescript": "^4.7.4",
"typescript": "^4.8.2",
"zen-observable": "^0.8.15"
}
}

@@ -1,4 +0,16 @@

import { Source, Sink, Operator, Signal, SignalKind, TalkbackKind, TalkbackFn } from '../types';
import { Source, Sink, Signal, SignalKind, TalkbackKind, TalkbackFn } from '../types';
import { push, start } from '../helpers';
import {
passesPassivePull,
passesActivePush,
passesSinkClose,
passesSourceEnd,
passesSingleStart,
passesStrictEnd,
passesSourcePushThenEnd,
passesAsyncSequence,
passesCloseAndEnd,
} from './compliance';
import * as sources from '../sources';

@@ -8,404 +20,2 @@ import * as sinks from '../sinks';

/* This tests a noop operator for passive Pull talkback signals.
A Pull will be sent from the sink upwards and should pass through
the operator until the source receives it, which then pushes a
value down. */
const passesPassivePull = (operator: Operator<any, any>, output: any = 0) => {
it('responds to Pull talkback signals (spec)', () => {
let talkback: TalkbackFn | null = null;
let pushes = 0;
const values: any[] = [];
const source: Source<any> = sink => {
sink(
start(signal => {
if (!pushes && signal === TalkbackKind.Pull) {
pushes++;
sink(push(0));
}
})
);
};
const sink: Sink<any> = signal => {
expect(signal).not.toBe(SignalKind.End);
if (signal === SignalKind.End) {
/*noop*/
} else if (signal.tag === SignalKind.Push) {
values.push(signal[0]);
} else {
talkback = signal[0];
}
};
operator(source)(sink);
// The Start signal should always come in immediately
expect(talkback).not.toBe(null);
// No Push signals should be issued initially
expect(values).toEqual([]);
// When pulling a value we expect an immediate response
talkback!(TalkbackKind.Pull);
jest.runAllTimers();
expect(values).toEqual([output]);
});
};
/* This tests a noop operator for regular, active Push signals.
A Push will be sent downwards from the source, through the
operator to the sink. Pull events should be let through from
the sink after every Push event. */
const passesActivePush = (operator: Operator<any, any>, result: any = 0) => {
it('responds to eager Push signals (spec)', () => {
const values: any[] = [];
let talkback: TalkbackFn | null = null;
let sink: Sink<any> | null = null;
let pulls = 0;
const source: Source<any> = _sink => {
(sink = _sink)(
start(signal => {
if (signal === TalkbackKind.Pull) pulls++;
})
);
};
operator(source)(signal => {
expect(signal).not.toBe(SignalKind.End);
if (signal === SignalKind.End) {
/*noop*/
} else if (signal.tag === SignalKind.Start) {
talkback = signal[0];
} else if (signal.tag === SignalKind.Push) {
values.push(signal[0]);
talkback!(TalkbackKind.Pull);
}
});
// No Pull signals should be issued initially
expect(pulls).toBe(0);
// When pushing a value we expect an immediate response
sink!(push(0));
jest.runAllTimers();
expect(values).toEqual([result]);
// Subsequently the Pull signal should have travelled upwards
expect(pulls).toBe(1);
});
};
/* This tests a noop operator for Close talkback signals from the sink.
A Close signal will be sent, which should be forwarded to the source,
which then ends the communication without sending an End signal. */
const passesSinkClose = (operator: Operator<any, any>) => {
it('responds to Close signals from sink (spec)', () => {
let talkback: TalkbackFn | null = null;
let closing = 0;
const source: Source<any> = sink => {
sink(
start(signal => {
if (signal === TalkbackKind.Pull && !closing) {
sink(push(0));
} else if (signal === TalkbackKind.Close) {
closing++;
}
})
);
};
const sink: Sink<any> = signal => {
expect(signal).not.toBe(SignalKind.End);
if (signal === SignalKind.End) {
/*noop*/
} else if (signal.tag === SignalKind.Push) {
talkback!(TalkbackKind.Close);
} else {
talkback = signal[0];
}
};
operator(source)(sink);
// When pushing a value we expect an immediate close signal
talkback!(TalkbackKind.Pull);
jest.runAllTimers();
expect(closing).toBe(1);
});
};
/* This tests a noop operator for End signals from the source.
A Push and End signal will be sent after the first Pull talkback
signal from the sink, which shouldn't lead to any extra Close or Pull
talkback signals. */
const passesSourceEnd = (operator: Operator<any, any>, result: any = 0) => {
it('passes on immediate Push then End signals from source (spec)', () => {
const signals: Signal<any>[] = [];
let talkback: TalkbackFn | null = null;
let pulls = 0;
let ending = 0;
const source: Source<any> = sink => {
sink(
start(signal => {
expect(signal).not.toBe(TalkbackKind.Close);
if (signal === TalkbackKind.Pull) {
pulls++;
if (pulls === 1) {
sink(push(0));
sink(SignalKind.End);
}
}
})
);
};
const sink: Sink<any> = signal => {
if (signal === SignalKind.End) {
signals.push(signal);
ending++;
} else if (signal.tag === SignalKind.Push) {
signals.push(signal);
} else {
talkback = signal[0];
}
};
operator(source)(sink);
// When pushing a value we expect an immediate Push then End signal
talkback!(TalkbackKind.Pull);
jest.runAllTimers();
expect(ending).toBe(1);
expect(signals).toEqual([push(result), SignalKind.End]);
// Also no additional pull event should be created by the operator
expect(pulls).toBe(1);
});
};
/* This tests a noop operator for End signals from the source
after the first pull in response to another.
This is similar to passesSourceEnd but more well behaved since
mergeMap/switchMap/concatMap are eager operators. */
const passesSourcePushThenEnd = (operator: Operator<any, any>, result: any = 0) => {
it('passes on End signals from source (spec)', () => {
const signals: Signal<any>[] = [];
let talkback: TalkbackFn | null = null;
let pulls = 0;
let ending = 0;
const source: Source<any> = sink => {
sink(
start(signal => {
expect(signal).not.toBe(TalkbackKind.Close);
if (signal === TalkbackKind.Pull) {
pulls++;
if (pulls <= 2) {
sink(push(0));
} else {
sink(SignalKind.End);
}
}
})
);
};
const sink: Sink<any> = signal => {
if (signal === SignalKind.End) {
signals.push(signal);
ending++;
} else if (signal.tag === SignalKind.Push) {
signals.push(signal);
talkback!(TalkbackKind.Pull);
} else {
talkback = signal[0];
}
};
operator(source)(sink);
// When pushing a value we expect an immediate Push then End signal
talkback!(TalkbackKind.Pull);
jest.runAllTimers();
expect(ending).toBe(1);
expect(pulls).toBe(3);
expect(signals).toEqual([push(result), push(result), SignalKind.End]);
});
};
/* This tests a noop operator for Start signals from the source.
When the operator's sink is started by the source it'll receive
a Start event. As a response it should never send more than one
Start signals to the sink. */
const passesSingleStart = (operator: Operator<any, any>) => {
it('sends a single Start event to the incoming sink (spec)', () => {
let starts = 0;
const source: Source<any> = sink => {
sink(start(() => {}));
};
const sink: Sink<any> = signal => {
if (signal !== SignalKind.End && signal.tag === SignalKind.Start) {
starts++;
}
};
// When starting the operator we expect a single start event on the sink
operator(source)(sink);
expect(starts).toBe(1);
});
};
/* This tests a noop operator for silence after End signals from the source.
When the operator receives the End signal it shouldn't forward any other
signals to the sink anymore.
This isn't a strict requirement, but some operators should ensure that
all sources are well behaved. This is particularly true for operators
that either Close sources themselves or may operate on multiple sources. */
const passesStrictEnd = (operator: Operator<any, any>) => {
it('stops all signals after End has been received (spec: strict end)', () => {
let pulls = 0;
const signals: Signal<any>[] = [];
const source: Source<any> = sink => {
sink(
start(signal => {
if (signal === TalkbackKind.Pull) {
pulls++;
sink(SignalKind.End);
sink(push(123));
}
})
);
};
const sink: Sink<any> = signal => {
if (signal === SignalKind.End) {
signals.push(signal);
} else if (signal.tag === SignalKind.Push) {
signals.push(signal);
} else {
signal[0](TalkbackKind.Pull);
}
};
operator(source)(sink);
// The Push signal should've been dropped
jest.runAllTimers();
expect(signals).toEqual([SignalKind.End]);
expect(pulls).toBe(1);
});
it('stops all signals after Close has been received (spec: strict close)', () => {
const signals: Signal<any>[] = [];
const source: Source<any> = sink => {
sink(
start(signal => {
if (signal === TalkbackKind.Close) {
sink(push(123));
}
})
);
};
const sink: Sink<any> = signal => {
if (signal === SignalKind.End) {
signals.push(signal);
} else if (signal.tag === SignalKind.Push) {
signals.push(signal);
} else {
signal[0](TalkbackKind.Close);
}
};
operator(source)(sink);
// The Push signal should've been dropped
jest.runAllTimers();
expect(signals).toEqual([]);
});
};
/* This tests an immediately closing operator for End signals to
the sink and Close signals to the source.
When an operator closes immediately we expect to see a Close
signal at the source and an End signal to the sink, since the
closing operator is expected to end the entire chain. */
const passesCloseAndEnd = (closingOperator: Operator<any, any>) => {
it('closes the source and ends the sink correctly (spec: ending operator)', () => {
let closing = 0;
let ending = 0;
const source: Source<any> = sink => {
sink(
start(signal => {
// For some operator tests we do need to send a single value
if (signal === TalkbackKind.Pull) {
sink(push(null));
} else {
closing++;
}
})
);
};
const sink: Sink<any> = signal => {
if (signal === SignalKind.End) {
ending++;
} else if (signal.tag === SignalKind.Start) {
signal[0](TalkbackKind.Pull);
}
};
// We expect the operator to immediately end and close
closingOperator(source)(sink);
expect(closing).toBe(1);
expect(ending).toBe(1);
});
};
const passesAsyncSequence = (operator: Operator<any, any>, result: any = 0) => {
it('passes an async push with an async end (spec)', () => {
let hasPushed = false;
const signals: Signal<any>[] = [];
const source: Source<any> = sink => {
sink(
start(signal => {
if (signal === TalkbackKind.Pull && !hasPushed) {
hasPushed = true;
setTimeout(() => sink(push(0)), 10);
setTimeout(() => sink(SignalKind.End), 20);
}
})
);
};
const sink: Sink<any> = signal => {
if (signal === SignalKind.End) {
signals.push(signal);
} else if (signal.tag === SignalKind.Push) {
signals.push(signal);
} else {
setTimeout(() => {
signal[0](TalkbackKind.Pull);
}, 5);
}
};
// We initially expect to see the push signal
// Afterwards after all timers all other signals come in
operator(source)(sink);
expect(signals.length).toBe(0);
jest.advanceTimersByTime(5);
expect(hasPushed).toBeTruthy();
jest.runAllTimers();
expect(signals).toEqual([push(result), SignalKind.End]);
});
};
beforeEach(() => {

@@ -415,26 +25,2 @@ jest.useFakeTimers();

describe('combine', () => {
const noop = (source: Source<any>) => operators.combine(sources.fromValue(0), source);
passesPassivePull(noop, [0, 0]);
passesActivePush(noop, [0, 0]);
passesSinkClose(noop);
passesSourceEnd(noop, [0, 0]);
passesSingleStart(noop);
passesStrictEnd(noop);
it('emits the zipped values of two sources', () => {
const { source: sourceA, next: nextA } = sources.makeSubject();
const { source: sourceB, next: nextB } = sources.makeSubject();
const fn = jest.fn();
sinks.forEach(fn)(operators.combine(sourceA, sourceB));
nextA(1);
expect(fn).not.toHaveBeenCalled();
nextB(2);
expect(fn).toHaveBeenCalledWith([1, 2]);
});
});
describe('buffer', () => {

@@ -441,0 +27,0 @@ const valueThenNever: Source<any> = sink =>

@@ -277,3 +277,5 @@ import { Source, Sink, Signal, SignalKind, TalkbackKind, TalkbackFn } from '../types';

await Promise.resolve();
await promise;
await Promise.resolve();

@@ -280,0 +282,0 @@ expect(signals).toEqual([start(expect.any(Function)), push(1), SignalKind.End]);

@@ -1,2 +0,2 @@

import { Source, SignalKind, TalkbackKind } from './types';
import { Source, SignalKind } from './types';
import { push, start } from './helpers';

@@ -16,7 +16,3 @@

start(signal => {
if (signal === TalkbackKind.Pull) {
data(1);
} else {
data(2);
}
data(signal + 1);
})

@@ -26,3 +22,3 @@ );

sink(push(data));
} else if (signal === 2) {
} else {
sink(SignalKind.End);

@@ -42,7 +38,3 @@ }

sink(0, (num: number) => {
if (num === 1) {
signal[0](TalkbackKind.Pull);
} else if (num === 2) {
signal[0](TalkbackKind.Close);
}
if (num < 3) signal[0](num - 1);
});

@@ -49,0 +41,0 @@ } else {

import { TalkbackFn, TeardownFn, Start, Push, SignalKind } from './types';
export const talkbackPlaceholder: TalkbackFn = _signal => {
/*noop*/
};
export const teardownPlaceholder: TeardownFn = () => {
/*noop*/
};
export const talkbackPlaceholder: TalkbackFn = teardownPlaceholder;

@@ -10,0 +8,0 @@ export function start<T>(talkback: TalkbackFn): Start<T> {

@@ -5,4 +5,5 @@ export * from './types';

export * from './sinks';
export * from './combine';
export * from './observable';
export * from './callbag';
export * from './pipe';

@@ -19,13 +19,9 @@ import { Source, SignalKind, TalkbackKind } from './types';

const observableSymbol: unique symbol =
typeof Symbol === 'function'
? (Symbol as any).observable || ((Symbol as any).observable = Symbol('observable'))
: '@@observable';
const observableSymbol = (): symbol =>
(Symbol as any).observable || ((Symbol as any).observable = Symbol('observable'));
export function fromObservable<T>(input: Observable<T>): Source<T> {
const observable: Observable<T> = input[observableSymbol]
? (input as any)[observableSymbol]()
: input;
input = input[observableSymbol()] ? (input as any)[observableSymbol()]() : input;
return sink => {
const subscription = observable.subscribe({
const subscription = input.subscribe({
next(value: T) {

@@ -50,3 +46,3 @@ sink(push(value));

export function toObservable<T>(source: Source<T>): Observable<T> {
const observable: Observable<T> = {
return {
subscribe(observer: ObservableObserver<T>) {

@@ -78,5 +74,6 @@ let talkback = talkbackPlaceholder;

},
[observableSymbol()]() {
return this;
},
};
observable[observableSymbol] = () => observable;
return observable;
}

@@ -67,75 +67,2 @@ import { Source, Sink, Operator, SignalKind, TalkbackKind, TalkbackFn } from './types';

export function combine<A, B>(sourceA: Source<A>, sourceB: Source<B>): Source<[A, B]> {
return sink => {
let lastValA: A | void;
let lastValB: B | void;
let talkbackA = talkbackPlaceholder;
let talkbackB = talkbackPlaceholder;
let gotSignal = false;
let gotEnd = false;
let ended = false;
sourceA(signal => {
if (signal === SignalKind.End) {
if (!gotEnd) {
gotEnd = true;
} else {
ended = true;
sink(SignalKind.End);
}
} else if (signal.tag === SignalKind.Start) {
talkbackA = signal[0];
} else if (lastValB === undefined) {
lastValA = signal[0];
if (!gotSignal) {
talkbackB(TalkbackKind.Pull);
} else {
gotSignal = false;
}
} else if (!ended) {
lastValA = signal[0];
gotSignal = false;
sink(push([lastValA, lastValB] as [A, B]));
}
});
sourceB(signal => {
if (signal === SignalKind.End) {
if (!gotEnd) {
gotEnd = true;
} else {
ended = true;
sink(SignalKind.End);
}
} else if (signal.tag === SignalKind.Start) {
talkbackB = signal[0];
} else if (lastValA === undefined) {
lastValB = signal[0];
if (!gotSignal) {
talkbackA(TalkbackKind.Pull);
} else {
gotSignal = false;
}
} else if (!ended) {
lastValB = signal[0];
gotSignal = false;
sink(push([lastValA, lastValB] as [A, B]));
}
});
sink(
start(signal => {
if (ended) {
/*noop*/
} else if (signal === TalkbackKind.Close) {
ended = true;
talkbackA(TalkbackKind.Close);
talkbackB(TalkbackKind.Close);
} else if (!gotSignal) {
gotSignal = true;
talkbackA(TalkbackKind.Pull);
talkbackB(TalkbackKind.Pull);
}
})
);
};
}
export function concatMap<In, Out>(map: (value: In) => Source<Out>): Operator<In, Out> {

@@ -878,3 +805,3 @@ return source => sink => {

source(signal => {
if (typeof signal !== 'number' && signal.tag === SignalKind.Start) {
if (signal !== SignalKind.End && signal.tag === SignalKind.Start) {
sink(signal);

@@ -881,0 +808,0 @@ } else {

@@ -154,5 +154,5 @@ import { Source } from './types';

function pipe() {
let x = arguments[0];
for (let i = 1, l = arguments.length; i < l; i++) x = arguments[i](x);
function pipe(...args: any[]) {
let x = args[0];
for (let i = 1, l = args.length; i < l; i++) x = args[i](x);
return x;

@@ -159,0 +159,0 @@ }

import { Source, Sink, SignalKind, TalkbackKind, Observer, Subject, TeardownFn } from './types';
import { push, start, talkbackPlaceholder } from './helpers';
import { push, start, talkbackPlaceholder, teardownPlaceholder } from './helpers';
import { share } from './operators';
export function fromArray<T>(array: T[]): Source<T> {
export function lazy<T>(make: () => Source<T>): Source<T> {
return sink => make()(sink);
}
export function fromAsyncIterable<T>(iterable: AsyncIterable<T>): Source<T> {
return sink => {
const iterator = iterable[Symbol.asyncIterator]();
let ended = false;
let looping = false;
let pulled = false;
let current = 0;
let next: IteratorResult<T>;
sink(
start(async signal => {
if (signal === TalkbackKind.Close) {
ended = true;
if (iterator.return) iterator.return();
} else if (looping) {
pulled = true;
} else {
for (pulled = looping = true; pulled && !ended; ) {
if ((next = await iterator.next()).done) {
ended = true;
if (iterator.return) await iterator.return();
sink(SignalKind.End);
} else {
try {
pulled = false;
sink(push(next.value));
} catch (error) {
if (iterator.throw) {
if ((ended = !!(await iterator.throw(error)).done)) sink(SignalKind.End);
} else {
throw error;
}
}
}
}
looping = false;
}
})
);
};
}
export function fromIterable<T>(iterable: Iterable<T> | AsyncIterable<T>): Source<T> {
if (iterable[Symbol.asyncIterator]) return fromAsyncIterable(iterable as AsyncIterable<T>);
return sink => {
const iterator = iterable[Symbol.iterator]();
let ended = false;
let looping = false;
let pulled = false;
let next: IteratorResult<T>;
sink(
start(signal => {
if (signal === TalkbackKind.Close) {
ended = true;
if (iterator.return) iterator.return();
} else if (looping) {
pulled = true;
} else {
for (pulled = looping = true; pulled && !ended; current++) {
if (current < array.length) {
pulled = false;
sink(push(array[current]));
} else {
for (pulled = looping = true; pulled && !ended; ) {
if ((next = iterator.next()).done) {
ended = true;
if (iterator.return) iterator.return();
sink(SignalKind.End);
} else {
try {
pulled = false;
sink(push(next.value));
} catch (error) {
if (iterator.throw) {
if ((ended = !!iterator.throw(error).done)) sink(SignalKind.End);
} else {
throw error;
}
}
}

@@ -33,2 +90,4 @@ }

export const fromArray: <T>(array: T[]) => Source<T> = fromIterable;
export function fromValue<T>(value: T): Source<T> {

@@ -77,27 +136,17 @@ return sink => {

export function makeSubject<T>(): Subject<T> {
let sinks: Sink<T>[] = [];
let ended = false;
let next: Subject<T>['next'] | void;
let complete: Subject<T>['complete'] | void;
return {
source(sink: Sink<T>) {
sinks.push(sink);
sink(
start(signal => {
if (signal === TalkbackKind.Close) {
const index = sinks.indexOf(sink);
if (index > -1) (sinks = sinks.slice()).splice(index, 1);
}
})
);
},
source: share(
make(observer => {
next = observer.next;
complete = observer.complete;
return teardownPlaceholder;
})
),
next(value: T) {
if (!ended) {
const signal = push(value);
for (let i = 0, a = sinks, l = sinks.length; i < l; i++) a[i](signal);
}
if (next) next(value);
},
complete() {
if (!ended) {
ended = true;
for (let i = 0, a = sinks, l = sinks.length; i < l; i++) a[i](SignalKind.End);
}
if (complete) complete();
},

@@ -126,44 +175,26 @@ };

export function interval(ms: number): Source<number> {
return sink => {
return make(observer => {
let i = 0;
const id = setInterval(() => {
sink(push(i++));
}, ms);
sink(
start(signal => {
if (signal === TalkbackKind.Close) clearInterval(id);
})
);
};
const id = setInterval(() => observer.next(i++), ms);
return () => clearInterval(id);
});
}
export function fromDomEvent(element: HTMLElement, event: string): Source<Event> {
return sink => {
const handler = (payload: Event) => {
sink(push(payload));
};
sink(
start(signal => {
if (signal === TalkbackKind.Close) element.removeEventListener(event, handler);
})
);
element.addEventListener(event, handler);
};
return make(observer => {
element.addEventListener(event, observer.next);
return () => element.removeEventListener(event, observer.next);
});
}
export function fromPromise<T>(promise: Promise<T>): Source<T> {
return sink => {
let ended = false;
return make(observer => {
promise.then(value => {
if (!ended) {
sink(push(value));
sink(SignalKind.End);
}
Promise.resolve(value).then(() => {
observer.next(value);
observer.complete();
});
});
sink(
start(signal => {
if (signal === TalkbackKind.Close) ended = true;
})
);
};
return teardownPlaceholder;
});
}

@@ -36,2 +36,5 @@ /** A talkback signal is used to tell a [Source] that either the [Sink] is ready for new values or that the stream should be cancelled */

/** Extracts the type of a given Source */
export type TypeOfSource<T> = T extends Source<infer U> ? U : never;
export interface Subscription {

@@ -38,0 +41,0 @@ unsubscribe(): void;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc