mirror of https://github.com/vuejs/core.git
				
				
				
			refactor: extract getRawValue
This commit is contained in:
		
							parent
							
								
									a089d70993
								
							
						
					
					
						commit
						38f995763a
					
				|  | @ -46,22 +46,12 @@ function hasOwnProperty(this: object, key: unknown) { | |||
|   return obj.hasOwnProperty(key as string) | ||||
| } | ||||
| 
 | ||||
| class BaseReactiveHandler implements ProxyHandler<Target> { | ||||
|   constructor( | ||||
|     protected readonly _isReadonly = false, | ||||
|     protected readonly _isShallow = false, | ||||
|   ) {} | ||||
| 
 | ||||
|   get(target: Target, key: string | symbol, receiver: object): any { | ||||
|     const isReadonly = this._isReadonly, | ||||
|       isShallow = this._isShallow | ||||
|     if (key === ReactiveFlags.IS_REACTIVE) { | ||||
|       return !isReadonly | ||||
|     } else if (key === ReactiveFlags.IS_READONLY) { | ||||
|       return isReadonly | ||||
|     } else if (key === ReactiveFlags.IS_SHALLOW) { | ||||
|       return isShallow | ||||
|     } else if (key === ReactiveFlags.RAW) { | ||||
| export function getRawValue( | ||||
|   receiver: object, | ||||
|   isReadonly: boolean, | ||||
|   isShallow: boolean, | ||||
|   target: Target, | ||||
| ): Target | undefined { | ||||
|   if ( | ||||
|     receiver === | ||||
|       (isReadonly | ||||
|  | @ -78,8 +68,25 @@ class BaseReactiveHandler implements ProxyHandler<Target> { | |||
|   ) { | ||||
|     return target | ||||
|   } | ||||
|       // early return undefined
 | ||||
|       return | ||||
| } | ||||
| 
 | ||||
| class BaseReactiveHandler implements ProxyHandler<Target> { | ||||
|   constructor( | ||||
|     protected readonly _isReadonly = false, | ||||
|     protected readonly _isShallow = false, | ||||
|   ) {} | ||||
| 
 | ||||
|   get(target: Target, key: string | symbol, receiver: object): any { | ||||
|     const isReadonly = this._isReadonly, | ||||
|       isShallow = this._isShallow | ||||
|     if (key === ReactiveFlags.IS_REACTIVE) { | ||||
|       return !isReadonly | ||||
|     } else if (key === ReactiveFlags.IS_READONLY) { | ||||
|       return isReadonly | ||||
|     } else if (key === ReactiveFlags.IS_SHALLOW) { | ||||
|       return isShallow | ||||
|     } else if (key === ReactiveFlags.RAW) { | ||||
|       return getRawValue(receiver, isReadonly, isShallow, target) | ||||
|     } | ||||
| 
 | ||||
|     const targetIsArray = isArray(target) | ||||
|  |  | |||
|  | @ -2,10 +2,6 @@ import { | |||
|   type Target, | ||||
|   isReadonly, | ||||
|   isShallow, | ||||
|   reactiveMap, | ||||
|   readonlyMap, | ||||
|   shallowReactiveMap, | ||||
|   shallowReadonlyMap, | ||||
|   toRaw, | ||||
|   toReactive, | ||||
|   toReadonly, | ||||
|  | @ -21,6 +17,7 @@ import { | |||
|   toRawType, | ||||
| } from '@vue/shared' | ||||
| import { warn } from './warning' | ||||
| import { getRawValue } from './baseHandlers' | ||||
| 
 | ||||
| type CollectionTypes = IterableCollections | WeakCollections | ||||
| 
 | ||||
|  | @ -277,24 +274,7 @@ function createInstrumentationGetter(isReadonly: boolean, shallow: boolean) { | |||
|     } else if (key === ReactiveFlags.IS_READONLY) { | ||||
|       return isReadonly | ||||
|     } else if (key === ReactiveFlags.RAW) { | ||||
|       if ( | ||||
|         receiver === | ||||
|           (isReadonly | ||||
|             ? shallow | ||||
|               ? shallowReadonlyMap | ||||
|               : readonlyMap | ||||
|             : shallow | ||||
|               ? shallowReactiveMap | ||||
|               : reactiveMap | ||||
|           ).get(target as Target) || | ||||
|         // receiver is not the reactive proxy, but has the same prototype
 | ||||
|         // this means the reciever is a user proxy of the reactive proxy
 | ||||
|         Object.getPrototypeOf(target) === Object.getPrototypeOf(receiver) | ||||
|       ) { | ||||
|         return target | ||||
|       } | ||||
|       // early return undefined
 | ||||
|       return | ||||
|       return getRawValue(receiver, isReadonly, shallow, target) | ||||
|     } | ||||
| 
 | ||||
|     return Reflect.get( | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue