Skip to content

Commit 9f08043

Browse files
committed
feat(reactivity): collection iteration should inherit iterator instance methods
1 parent e8e8422 commit 9f08043

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

packages/reactivity/src/collectionHandlers.ts

+19-15
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,26 @@ function createIterableMethod(
5555
)
5656
// return a wrapped iterator which returns observed versions of the
5757
// values emitted from the real iterator
58-
return {
59-
// iterator protocol
60-
next() {
61-
const { value, done } = innerIterator.next()
62-
return done
63-
? { value, done }
64-
: {
65-
value: isPair ? [wrap(value[0]), wrap(value[1])] : wrap(value),
66-
done,
67-
}
68-
},
69-
// iterable protocol
70-
[Symbol.iterator]() {
71-
return this
58+
return extend(
59+
// inheriting all iterator properties
60+
Object.create(innerIterator),
61+
{
62+
// iterator protocol
63+
next() {
64+
const { value, done } = innerIterator.next()
65+
return done
66+
? { value, done }
67+
: {
68+
value: isPair ? [wrap(value[0]), wrap(value[1])] : wrap(value),
69+
done,
70+
}
71+
},
72+
// iterable protocol
73+
[Symbol.iterator]() {
74+
return this
75+
},
7276
},
73-
}
77+
)
7478
}
7579
}
7680

0 commit comments

Comments
 (0)