wonka
Advanced tools
Comparing version 6.2.6 to 6.3.0
# wonka | ||
## 6.3.0 | ||
### Minor Changes | ||
- Add `addOne` argument to `takeWhile`, allowing an additional value to be issued | ||
Submitted by [@kitten](https://github.com/kitten) (See [#156](https://github.com/0no-co/wonka/pull/156)) | ||
### Patch Changes | ||
- Convert `Push<T>` and `Start<T>` signals to `{ tag, 0: value }` objects, which are sufficiently backwards compatible and result in slightly faster execution in v8 | ||
Submitted by [@kitten](https://github.com/kitten) (See [#155](https://github.com/0no-co/wonka/pull/155)) | ||
## 6.2.6 | ||
@@ -4,0 +16,0 @@ |
@@ -961,2 +961,3 @@ /** | ||
* @param predicate - A function returning a boolean per value. | ||
* @param addOne - Lets an additional input value pass on. | ||
* @returns An {@link Operator}. | ||
@@ -969,2 +970,5 @@ * | ||
* | ||
* If `addOne` is set to `true`, the value for which the `predicate` first returned `false` is | ||
* issued and passed on as well instead of being omitted. | ||
* | ||
* @example | ||
@@ -981,3 +985,3 @@ * ```ts | ||
*/ | ||
declare function takeWhile<T>(predicate: (value: T) => boolean): Operator<T, T>; | ||
declare function takeWhile<T>(predicate: (value: T) => boolean, addOne?: boolean): Operator<T, T>; | ||
/** Debounces a Source by omitting values until a given timeframe has passed. | ||
@@ -984,0 +988,0 @@ * |
@@ -10,11 +10,13 @@ Object.defineProperty(exports, "__esModule", { | ||
function start(e) { | ||
var r = [ e ]; | ||
r.tag = 0; | ||
return r; | ||
return { | ||
tag: 0, | ||
0: e | ||
}; | ||
} | ||
function push(e) { | ||
var r = [ e ]; | ||
r.tag = 1; | ||
return r; | ||
return { | ||
tag: 1, | ||
0: e | ||
}; | ||
} | ||
@@ -1174,19 +1176,22 @@ | ||
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); | ||
exports.takeWhile = function takeWhile(r, t) { | ||
return i => s => { | ||
var a = e; | ||
var f = !1; | ||
i((e => { | ||
if (f) {} else if (0 === e) { | ||
f = !0; | ||
s(0); | ||
} else if (0 === e.tag) { | ||
s = e[0]; | ||
i(e); | ||
a = e[0]; | ||
s(e); | ||
} else if (!r(e[0])) { | ||
a = !0; | ||
i(0); | ||
s(1); | ||
f = !0; | ||
if (t) { | ||
s(e); | ||
} | ||
s(0); | ||
a(1); | ||
} else { | ||
i(e); | ||
s(e); | ||
} | ||
@@ -1193,0 +1198,0 @@ })); |
{ | ||
"name": "wonka", | ||
"description": "A tiny but capable push & pull stream library for TypeScript and Flow", | ||
"version": "6.2.6", | ||
"version": "6.3.0", | ||
"author": "0no.co <hi@0no.co>", | ||
@@ -6,0 +6,0 @@ "source": "./src/index.ts", |
@@ -775,5 +775,23 @@ import { describe, it, expect, beforeEach, vi } from 'vitest'; | ||
next(2); | ||
next(3); | ||
expect(fn.mock.calls).toEqual([[start(expect.any(Function))], [push(1)], [SignalKind.End]]); | ||
}); | ||
it('emits values while a predicate passes for all values plus an additional one', () => { | ||
const { source, next } = sources.makeSubject<number>(); | ||
const fn = vi.fn(); | ||
operators.takeWhile((x: any) => x < 2, true)(source)(fn); | ||
next(1); | ||
next(2); | ||
next(3); | ||
expect(fn.mock.calls).toEqual([ | ||
[start(expect.any(Function))], | ||
[push(1)], | ||
[push(2)], | ||
[SignalKind.End], | ||
]); | ||
}); | ||
}); | ||
@@ -780,0 +798,0 @@ |
@@ -27,5 +27,6 @@ import { TalkbackFn, TeardownFn, Start, Push, SignalKind } from './types'; | ||
export function start<T>(talkback: TalkbackFn): Start<T> { | ||
const box: any = [talkback]; | ||
box.tag = SignalKind.Start; | ||
return box; | ||
return { | ||
tag: SignalKind.Start, | ||
0: talkback, | ||
} as Start<T>; | ||
} | ||
@@ -37,5 +38,6 @@ | ||
export function push<T>(value: T): Push<T> { | ||
const box: any = [value]; | ||
box.tag = SignalKind.Push; | ||
return box; | ||
return { | ||
tag: SignalKind.Push, | ||
0: value, | ||
} as Push<T>; | ||
} |
@@ -1257,2 +1257,3 @@ import { Push, Source, Sink, Operator, SignalKind, TalkbackKind, TalkbackFn } from './types'; | ||
* @param predicate - A function returning a boolean per value. | ||
* @param addOne - Lets an additional input value pass on. | ||
* @returns An {@link Operator}. | ||
@@ -1265,2 +1266,5 @@ * | ||
* | ||
* If `addOne` is set to `true`, the value for which the `predicate` first returned `false` is | ||
* issued and passed on as well instead of being omitted. | ||
* | ||
* @example | ||
@@ -1277,3 +1281,3 @@ * ```ts | ||
*/ | ||
export function takeWhile<T>(predicate: (value: T) => boolean): Operator<T, T> { | ||
export function takeWhile<T>(predicate: (value: T) => boolean, addOne?: boolean): Operator<T, T> { | ||
return source => sink => { | ||
@@ -1293,2 +1297,3 @@ let talkback = talkbackPlaceholder; | ||
ended = true; | ||
if (addOne) sink(signal); | ||
sink(SignalKind.End); | ||
@@ -1295,0 +1300,0 @@ talkback(TalkbackKind.Close); |
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
303537
8732