From 3e412c10e031c1845a4f20ecdd8740894d04c4cd Mon Sep 17 00:00:00 2001 From: Zardddddd60 Date: Tue, 21 Jul 2020 22:33:09 +0800 Subject: [PATCH] refactor(reactive): reduce code size by assigning to a local variable (#1634) --- packages/reactivity/src/reactive.ts | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/packages/reactivity/src/reactive.ts b/packages/reactivity/src/reactive.ts index 38370152..8e333fc8 100644 --- a/packages/reactivity/src/reactive.ts +++ b/packages/reactivity/src/reactive.ts @@ -141,12 +141,11 @@ function createReactiveObject( return target } // target already has corresponding Proxy - if ( - hasOwn(target, isReadonly ? ReactiveFlags.READONLY : ReactiveFlags.REACTIVE) - ) { - return isReadonly - ? target[ReactiveFlags.READONLY] - : target[ReactiveFlags.REACTIVE] + const reactiveFlag = isReadonly + ? ReactiveFlags.READONLY + : ReactiveFlags.REACTIVE + if (hasOwn(target, reactiveFlag)) { + return target[reactiveFlag] } // only a whitelist of value types can be observed. if (!canObserve(target)) { @@ -156,11 +155,7 @@ function createReactiveObject( target, collectionTypes.has(target.constructor) ? collectionHandlers : baseHandlers ) - def( - target, - isReadonly ? ReactiveFlags.READONLY : ReactiveFlags.REACTIVE, - observed - ) + def(target, reactiveFlag, observed) return observed }