refactor: use more efficient useComputed() implementation

This commit is contained in:
Evan You
2018-10-30 01:10:03 -04:00
parent f9e3e38fdb
commit 8602b61efb
4 changed files with 18 additions and 15 deletions

View File

@@ -1,12 +1,15 @@
import { autorun } from './index'
import { Autorun, activeAutorunStack } from './autorun'
export interface ComputedGetter {
(): any
export interface ComputedGetter<T = any> {
(): T
runner: Autorun
}
export function computed(getter: Function, context?: any): ComputedGetter {
export function computed<T, C = null>(
getter: (this: C, ctx: C) => T,
context?: C
): ComputedGetter<T> {
let dirty: boolean = true
let value: any = undefined
const runner = autorun(() => getter.call(context, context), {