@@ -18,7 +18,12 @@ import {
1818 createProxy ,
1919 ArchType ,
2020 ImmerScope ,
21- handleCrossReference
21+ handleCrossReference ,
22+ WRITABLE ,
23+ CONFIGURABLE ,
24+ ENUMERABLE ,
25+ VALUE ,
26+ isArray
2227} from "../internal"
2328
2429interface ProxyBaseState extends ImmerBaseState {
@@ -51,9 +56,9 @@ export function createProxyProxy<T extends Objectish>(
5156 base : T ,
5257 parent ?: ImmerState
5358) : [ Drafted < T , ProxyState > , ProxyState ] {
54- const isArray = Array . isArray ( base )
59+ const baseIsArray = isArray ( base )
5560 const state : ProxyState = {
56- type_ : isArray ? ArchType . Array : ( ArchType . Object as any ) ,
61+ type_ : baseIsArray ? ArchType . Array : ( ArchType . Object as any ) ,
5762 // Track which produce call this is associated with.
5863 scope_ : parent ? parent . scope_ : getCurrentScope ( ) ! ,
5964 // True for both shallow and deep changes.
@@ -86,7 +91,7 @@ export function createProxyProxy<T extends Objectish>(
8691 // Note that in the case of an array, we put the state in an array to have better Reflect defaults ootb
8792 let target : T = state as any
8893 let traps : ProxyHandler < object | Array < any > > = objectTraps
89- if ( isArray ) {
94+ if ( baseIsArray ) {
9095 target = [ state ] as any
9196 traps = arrayTraps
9297 }
@@ -201,10 +206,10 @@ export const objectTraps: ProxyHandler<ProxyState> = {
201206 const desc = Reflect . getOwnPropertyDescriptor ( owner , prop )
202207 if ( ! desc ) return desc
203208 return {
204- writable : true ,
205- configurable : state . type_ !== ArchType . Array || prop !== "length" ,
206- enumerable : desc . enumerable ,
207- value : owner [ prop ]
209+ [ WRITABLE ] : true ,
210+ [ CONFIGURABLE ] : state . type_ !== ArchType . Array || prop !== "length" ,
211+ [ ENUMERABLE ] : desc [ ENUMERABLE ] ,
212+ [ VALUE ] : owner [ prop ]
208213 }
209214 } ,
210215 defineProperty ( ) {
@@ -226,8 +231,9 @@ const arrayTraps: ProxyHandler<[ProxyArrayState]> = {}
226231each ( objectTraps , ( key , fn ) => {
227232 // @ts -ignore
228233 arrayTraps [ key ] = function ( ) {
229- arguments [ 0 ] = arguments [ 0 ] [ 0 ]
230- return fn . apply ( this , arguments )
234+ const args = arguments
235+ args [ 0 ] = args [ 0 ] [ 0 ]
236+ return fn . apply ( this , args )
231237 }
232238} )
233239arrayTraps . deleteProperty = function ( state , prop ) {
@@ -256,8 +262,8 @@ function peek(draft: Drafted, prop: PropertyKey) {
256262function readPropFromProto ( state : ImmerState , source : any , prop : PropertyKey ) {
257263 const desc = getDescriptorFromProto ( source , prop )
258264 return desc
259- ? `value` in desc
260- ? desc . value
265+ ? VALUE in desc
266+ ? desc [ VALUE ]
261267 : // This is a very special case, if the prop is a getter defined by the
262268 // prototype, we should invoke it with the draft as context!
263269 desc . get ?. call ( state . draft_ )
0 commit comments