mirror of
https://github.com/re-rxjs/react-rxjs.git
synced 2025-12-08 18:01:51 +00:00
fix(utils): combineKeys allow for reentrant keys
This commit is contained in:
parent
c6b4010cd0
commit
d3fb725015
@ -166,4 +166,32 @@ describe("combineKeys", () => {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it("accounts for reentrant keys", () => {
|
||||
scheduler().run(({ expectObservable, cold }) => {
|
||||
const activeKeys = {
|
||||
a: ["a"],
|
||||
b: ["a", "b"],
|
||||
z: [],
|
||||
}
|
||||
|
||||
const keys = cold(" abzab", activeKeys)
|
||||
const a = cold(" 1----")
|
||||
const b = cold(" 2---")
|
||||
const expectedStr = "efgef"
|
||||
|
||||
const innerStreams = { a, b }
|
||||
|
||||
const result = combineKeys(
|
||||
keys,
|
||||
(v): Observable<string> => innerStreams[v],
|
||||
).pipe(map((x) => Object.fromEntries(x.entries())))
|
||||
|
||||
expectObservable(result).toBe(expectedStr, {
|
||||
e: { a: "1" },
|
||||
f: { a: "1", b: "2" },
|
||||
g: {},
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@ -27,6 +27,7 @@ export const combineKeys = <K, T>(
|
||||
innerSubscriptions.forEach((sub, key) => {
|
||||
if (!nextKeys.has(key)) {
|
||||
sub.unsubscribe()
|
||||
innerSubscriptions.delete(key)
|
||||
if (currentValue.has(key)) {
|
||||
changes = true
|
||||
currentValue.delete(key)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user