import Watcher from './watcher' ; export default class Dep { static target : Watcher | null ; subs : Watcher [ ] ; constructor ( ) { this . subs = [ ] ; } addSub ( sub ) { this . subs . push ( sub ) ; } depend ( ) { if ( Dep . target ) { Dep . target . addDep ( this ) ; } } notify ( ) { this . subs . forEach ( ( sub ) => { sub . update ( ) ; } ) ; } } Dep . target = null ; export function setTarget ( target ) { Dep . target = target ; } export function clearTarget ( ) { Dep . target = null ; }