MCPcopy
hub / github.com/vuejs/core / createIterableMethod

Function createIterableMethod

packages/reactivity/src/collectionHandlers.ts:33–75  ·  view source on GitHub ↗
(
  method: string | symbol,
  isReadonly: boolean,
  isShallow: boolean,
)

Source from the content-addressed store, hash-verified

31 Reflect.getPrototypeOf(v)
32
33function createIterableMethod(
34 method: string | symbol,
35 isReadonly: boolean,
36 isShallow: boolean,
37) {
38 return function (
39 this: IterableCollections,
40 ...args: unknown[]
41 ): Iterable<unknown> & Iterator<unknown> {
42 const target = this[ReactiveFlags.RAW]
43 const rawTarget = toRaw(target)
44 const targetIsMap = isMap(rawTarget)
45 const isPair =
46 method === 'entries' || (method === Symbol.iterator && targetIsMap)
47 const isKeyOnly = method === 'keys' && targetIsMap
48 const innerIterator = target[method](...args)
49 const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive
50 !isReadonly &&
51 track(
52 rawTarget,
53 TrackOpTypes.ITERATE,
54 isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY,
55 )
56 // return a wrapped iterator which returns observed versions of the
57 // values emitted from the real iterator
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 },
73 )
74 }
75}
76
77function createReadonlyMethod(type: TriggerOpTypes): Function {
78 return function (this: CollectionTypes, ...args: unknown[]) {

Callers 1

createInstrumentationsFunction · 0.85

Calls 3

toRawFunction · 0.90
isMapFunction · 0.90
trackFunction · 0.90

Tested by

no test coverage detected