Implement ObservableDict, a dict that calls listeners whenever it changes. subscribe(fn) registers a callback called as fn(event, key, old, new) where event is "set", "update" (key existed with a different value) or "delete". Setting a key to its current value fires nothing.
Changes made through d[k] = v, del d[k], d.pop(k) and d.update(...) must all notify. subscribe returns a function that unsubscribes.