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) |   return obj.hasOwnProperty(key as string) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| class BaseReactiveHandler implements ProxyHandler<Target> { | export function getRawValue( | ||||||
|   constructor( |   receiver: object, | ||||||
|     protected readonly _isReadonly = false, |   isReadonly: boolean, | ||||||
|     protected readonly _isShallow = false, |   isShallow: boolean, | ||||||
|   ) {} |   target: Target, | ||||||
| 
 | ): Target | undefined { | ||||||
|   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) { |  | ||||||
|   if ( |   if ( | ||||||
|     receiver === |     receiver === | ||||||
|       (isReadonly |       (isReadonly | ||||||
|  | @ -78,8 +68,25 @@ class BaseReactiveHandler implements ProxyHandler<Target> { | ||||||
|   ) { |   ) { | ||||||
|     return 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) |     const targetIsArray = isArray(target) | ||||||
|  |  | ||||||
|  | @ -2,10 +2,6 @@ import { | ||||||
|   type Target, |   type Target, | ||||||
|   isReadonly, |   isReadonly, | ||||||
|   isShallow, |   isShallow, | ||||||
|   reactiveMap, |  | ||||||
|   readonlyMap, |  | ||||||
|   shallowReactiveMap, |  | ||||||
|   shallowReadonlyMap, |  | ||||||
|   toRaw, |   toRaw, | ||||||
|   toReactive, |   toReactive, | ||||||
|   toReadonly, |   toReadonly, | ||||||
|  | @ -21,6 +17,7 @@ import { | ||||||
|   toRawType, |   toRawType, | ||||||
| } from '@vue/shared' | } from '@vue/shared' | ||||||
| import { warn } from './warning' | import { warn } from './warning' | ||||||
|  | import { getRawValue } from './baseHandlers' | ||||||
| 
 | 
 | ||||||
| type CollectionTypes = IterableCollections | WeakCollections | type CollectionTypes = IterableCollections | WeakCollections | ||||||
| 
 | 
 | ||||||
|  | @ -277,24 +274,7 @@ function createInstrumentationGetter(isReadonly: boolean, shallow: boolean) { | ||||||
|     } else if (key === ReactiveFlags.IS_READONLY) { |     } else if (key === ReactiveFlags.IS_READONLY) { | ||||||
|       return isReadonly |       return isReadonly | ||||||
|     } else if (key === ReactiveFlags.RAW) { |     } else if (key === ReactiveFlags.RAW) { | ||||||
|       if ( |       return getRawValue(receiver, isReadonly, shallow, target) | ||||||
|         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 Reflect.get( |     return Reflect.get( | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue