mirror of https://github.com/vuejs/core.git
feat(reactivity): collection iteration should inherit iterator instance methods
This commit is contained in:
parent
e8e842241a
commit
9f08043780
|
@ -55,22 +55,26 @@ function createIterableMethod(
|
||||||
)
|
)
|
||||||
// return a wrapped iterator which returns observed versions of the
|
// return a wrapped iterator which returns observed versions of the
|
||||||
// values emitted from the real iterator
|
// values emitted from the real iterator
|
||||||
return {
|
return extend(
|
||||||
// iterator protocol
|
// inheriting all iterator properties
|
||||||
next() {
|
Object.create(innerIterator),
|
||||||
const { value, done } = innerIterator.next()
|
{
|
||||||
return done
|
// iterator protocol
|
||||||
? { value, done }
|
next() {
|
||||||
: {
|
const { value, done } = innerIterator.next()
|
||||||
value: isPair ? [wrap(value[0]), wrap(value[1])] : wrap(value),
|
return done
|
||||||
done,
|
? { value, done }
|
||||||
}
|
: {
|
||||||
|
value: isPair ? [wrap(value[0]), wrap(value[1])] : wrap(value),
|
||||||
|
done,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// iterable protocol
|
||||||
|
[Symbol.iterator]() {
|
||||||
|
return this
|
||||||
|
},
|
||||||
},
|
},
|
||||||
// iterable protocol
|
)
|
||||||
[Symbol.iterator]() {
|
|
||||||
return this
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue