refactor(reactive): remove unnecessary args handling in reactiveEffect (#1593)

This commit is contained in:
Zardddddd60 2020-07-16 11:19:15 +08:00 committed by GitHub
parent 22973b418b
commit ecf872fc95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,7 +10,7 @@ type KeyToDepMap = Map<any, Dep>
const targetMap = new WeakMap<any, KeyToDepMap>() const targetMap = new WeakMap<any, KeyToDepMap>()
export interface ReactiveEffect<T = any> { export interface ReactiveEffect<T = any> {
(...args: any[]): T (): T
_isEffect: true _isEffect: true
id: number id: number
active: boolean active: boolean
@ -77,12 +77,12 @@ export function stop(effect: ReactiveEffect) {
let uid = 0 let uid = 0
function createReactiveEffect<T = any>( function createReactiveEffect<T = any>(
fn: (...args: any[]) => T, fn: () => T,
options: ReactiveEffectOptions options: ReactiveEffectOptions
): ReactiveEffect<T> { ): ReactiveEffect<T> {
const effect = function reactiveEffect(...args: unknown[]): unknown { const effect = function reactiveEffect(): unknown {
if (!effect.active) { if (!effect.active) {
return options.scheduler ? undefined : fn(...args) return options.scheduler ? undefined : fn()
} }
if (!effectStack.includes(effect)) { if (!effectStack.includes(effect)) {
cleanup(effect) cleanup(effect)
@ -90,7 +90,7 @@ function createReactiveEffect<T = any>(
enableTracking() enableTracking()
effectStack.push(effect) effectStack.push(effect)
activeEffect = effect activeEffect = effect
return fn(...args) return fn()
} finally { } finally {
effectStack.pop() effectStack.pop()
resetTracking() resetTracking()