Skip to content

Commit f00ba1c

Browse files
authored
Fix zip/combine for...in iterating inherited properties (#177)
1 parent 70815c2 commit f00ba1c

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

.changeset/twenty-paws-cry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'wonka': patch
3+
---
4+
5+
Replace for...in with for...of Object.keys() to avoid iterating inherited properties

src/combine.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ function zip<T>(sources: Source<T>[] | Record<string, Source<T>>): Source<T[] |
6161
let ended = false;
6262
let endCount = 0;
6363

64-
for (const key in sources) {
64+
const keys = Object.keys(sources);
65+
for (const key of keys) {
6566
(sources[key] as Source<T>)(signal => {
6667
if (signal === SignalKind.End) {
6768
if (endCount >= size - 1) {
@@ -77,7 +78,7 @@ function zip<T>(sources: Source<T>[] | Record<string, Source<T>>): Source<T[] |
7778
filled.add(key);
7879
if (!gotBuffer && filled.size < size) {
7980
if (!gotSignal) {
80-
for (const key in sources)
81+
for (const key of keys)
8182
if (!filled.has(key)) (talkbacks[key] || talkbackPlaceholder)(TalkbackKind.Pull);
8283
} else {
8384
gotSignal = false;
@@ -96,10 +97,10 @@ function zip<T>(sources: Source<T>[] | Record<string, Source<T>>): Source<T[] |
9697
/*noop*/
9798
} else if (signal === TalkbackKind.Close) {
9899
ended = true;
99-
for (const key in talkbacks) talkbacks[key](TalkbackKind.Close);
100+
for (const key of Object.keys(talkbacks)) talkbacks[key](TalkbackKind.Close);
100101
} else if (!gotSignal) {
101102
gotSignal = true;
102-
for (const key in talkbacks) talkbacks[key](TalkbackKind.Pull);
103+
for (const key of Object.keys(talkbacks)) talkbacks[key](TalkbackKind.Pull);
103104
}
104105
})
105106
);

0 commit comments

Comments
 (0)