mirror of
https://github.com/re-rxjs/react-rxjs.git
synced 2025-12-08 18:01:51 +00:00
chore(utils): flip order of returned tuple of partitionByKey
This commit is contained in:
parent
957c4e5346
commit
96a397fbf1
@ -14,7 +14,7 @@ describe("partitionByKey", () => {
|
||||
scheduler().run(({ expectObservable, cold }) => {
|
||||
const source = cold("-ab---cd---")
|
||||
const expectedStr = "efg---hi---"
|
||||
const [result] = partitionByKey(
|
||||
const [, result] = partitionByKey(
|
||||
source,
|
||||
(v) => v,
|
||||
() => NEVER,
|
||||
@ -38,7 +38,7 @@ describe("partitionByKey", () => {
|
||||
const c = cold(" 1-|")
|
||||
const expectedStr = "efg--hi-j"
|
||||
const innerStreams = { a, b, c }
|
||||
const [result] = partitionByKey(
|
||||
const [, result] = partitionByKey(
|
||||
source,
|
||||
(v) => v,
|
||||
(v$) =>
|
||||
@ -72,7 +72,7 @@ describe("partitionByKey", () => {
|
||||
const expectC = " ------1-|"
|
||||
|
||||
const innerStreams = { a, b, c }
|
||||
const [, getInstance$] = partitionByKey(
|
||||
const [getInstance$] = partitionByKey(
|
||||
source,
|
||||
(v) => v,
|
||||
(v$) =>
|
||||
@ -91,7 +91,7 @@ describe("partitionByKey", () => {
|
||||
it("replays the latest value for each key", () => {
|
||||
const source$ = new Subject<string>()
|
||||
const inner$ = new Subject<number>()
|
||||
const [, getInstance$] = partitionByKey(
|
||||
const [getInstance$] = partitionByKey(
|
||||
source$,
|
||||
(v) => v,
|
||||
() => inner$,
|
||||
|
||||
@ -10,17 +10,17 @@ import { collect, getGroupedObservable, split } from "./"
|
||||
* @param keySelector Function that specifies the key for each element in `stream`
|
||||
* @param streamSelector Function to apply to each resulting group
|
||||
* @returns [1, 2]
|
||||
* 1. A stream with the list of active keys
|
||||
* 2. A function that accepts a key and returns the stream for the group of that key.
|
||||
* 1. A function that accepts a key and returns the stream for the group of that key.
|
||||
* 2. A stream with the list of active keys
|
||||
*/
|
||||
export function partitionByKey<T, K, R>(
|
||||
stream: Observable<T>,
|
||||
keySelector: (value: T) => K,
|
||||
streamSelector: (grouped: Observable<T>, key: K) => Observable<R>,
|
||||
): [Observable<K[]>, (key: K) => GroupedObservable<K, R>] {
|
||||
): [(key: K) => GroupedObservable<K, R>, Observable<K[]>] {
|
||||
const source$ = stream.pipe(split(keySelector, streamSelector), collect())
|
||||
return [
|
||||
source$.pipe(map((x) => Array.from(x.keys()))),
|
||||
(key: K) => getGroupedObservable(source$, key),
|
||||
source$.pipe(map((x) => Array.from(x.keys()))),
|
||||
]
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user