vue3-yuanma/packages/observer/src/state.ts

21 lines
961 B
TypeScript
Raw Normal View History

2018-11-14 00:03:35 +08:00
import { ReactiveEffect } from './effect'
2018-09-19 23:35:38 +08:00
// The main WeakMap that stores {target -> key -> dep} connections.
// Conceptually, it's easier to think of a dependency as a Dep class
// which maintains a Set of subscribers, but we simply store them as
// raw Sets to reduce memory overhead.
2018-11-14 00:03:35 +08:00
export type Dep = Set<ReactiveEffect>
2018-09-19 23:35:38 +08:00
export type KeyToDepMap = Map<string | symbol, Dep>
export const targetMap: WeakMap<any, KeyToDepMap> = new WeakMap()
// WeakMaps that store {raw <-> observed} pairs.
export const rawToObserved: WeakMap<any, any> = new WeakMap()
export const observedToRaw: WeakMap<any, any> = new WeakMap()
export const rawToImmutable: WeakMap<any, any> = new WeakMap()
export const immutableToRaw: WeakMap<any, any> = new WeakMap()
// WeakSets for values that are marked immutable or non-reactive during
// observable creation.
export const immutableValues: WeakSet<any> = new WeakSet()
export const nonReactiveValues: WeakSet<any> = new WeakSet()