MCPcopy Index your code
hub / github.com/immerjs/immer / enableArrayMethods

Function enableArrayMethods

src/plugins/arrayMethods.ts:100–440  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

98 * @see https://immerjs.github.io/immer/array-methods
99 */
100export function enableArrayMethods() {
101 const SHIFTING_METHODS = new Set<MutatingArrayMethod>(["shift", "unshift"])
102
103 const QUEUE_METHODS = new Set<MutatingArrayMethod>(["push", "pop"])
104
105 const RESULT_RETURNING_METHODS = new Set<MutatingArrayMethod>([
106 ...QUEUE_METHODS,
107 ...SHIFTING_METHODS
108 ])
109
110 const REORDERING_METHODS = new Set<MutatingArrayMethod>(["reverse", "sort"])
111
112 // Optimized method detection using array-based lookup
113 const MUTATING_METHODS = new Set<MutatingArrayMethod>([
114 ...RESULT_RETURNING_METHODS,
115 ...REORDERING_METHODS,
116 "splice"
117 ])
118
119 const FIND_METHODS = new Set<NonMutatingArrayMethod>(["find", "findLast"])
120
121 const NON_MUTATING_METHODS = new Set<NonMutatingArrayMethod>([
122 "filter",
123 "slice",
124 "concat",
125 "flat",
126 ...FIND_METHODS,
127 "findIndex",
128 "findLastIndex",
129 "some",
130 "every",
131 "indexOf",
132 "lastIndexOf",
133 "includes",
134 "join",
135 "toString",
136 "toLocaleString"
137 ])
138
139 // Type guard for method detection
140 function isMutatingArrayMethod(
141 method: string
142 ): method is MutatingArrayMethod {
143 return MUTATING_METHODS.has(method as any)
144 }
145
146 function isNonMutatingArrayMethod(
147 method: string
148 ): method is NonMutatingArrayMethod {
149 return NON_MUTATING_METHODS.has(method as any)
150 }
151
152 function isArrayOperationMethod(
153 method: string
154 ): method is ArrayOperationMethod {
155 return isMutatingArrayMethod(method) || isNonMutatingArrayMethod(method)
156 }
157

Callers 2

runBaseTestFunction · 0.85

Calls 1

loadPluginFunction · 0.85

Tested by 1

runBaseTestFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…