wip: value()

This commit is contained in:
Evan You
2019-05-29 17:36:53 +08:00
parent 453cdcd600
commit 02421dbe62
6 changed files with 49 additions and 18 deletions

View File

@@ -0,0 +1,27 @@
import { track, trigger } from './effect'
import { OperationTypes } from './operations'
const knownValues = new WeakSet()
export interface Value<T> {
value: T
}
export function value<T>(raw: T): Value<T> {
const v = {
get value() {
track(v, OperationTypes.GET, '')
return raw
},
set value(newVal) {
raw = newVal
trigger(v, OperationTypes.SET, '')
}
}
knownValues.add(v)
return v
}
export function isValue(v: any): boolean {
return knownValues.has(v)
}