wip: computed

This commit is contained in:
Evan You
2019-05-29 18:44:50 +08:00
parent 02421dbe62
commit cf86e32575
4 changed files with 31 additions and 22 deletions

View File

@@ -1,20 +1,25 @@
import { track, trigger } from './effect'
import { OperationTypes } from './operations'
import { isObject } from '@vue/shared'
import { observable } from './index'
const knownValues = new WeakSet()
export const knownValues = new WeakSet()
export interface Value<T> {
value: T
}
const convert = (val: any): any => (isObject(val) ? observable(val) : val)
export function value<T>(raw: T): Value<T> {
raw = convert(raw)
const v = {
get value() {
track(v, OperationTypes.GET, '')
return raw
},
set value(newVal) {
raw = newVal
raw = convert(newVal)
trigger(v, OperationTypes.SET, '')
}
}