Open domenic opened 8 years ago
Would linking the props at construction and using prototypes be a valid workflow for this?
const zoneProps = new WeakMap();
class ZoneWithStorage extends Zone {
constructor(options, props = Object.create(null)) {
super(options);
// object we will be assigning props to
let base = null;
let parent = this.parent;
while (parent !== null) {
if (parent instanceof ZoneWithStorage) {
base = Object.create(zoneProps.get(parent));
break;
}
}
if (base === null) {
base = {};
}
zoneProps.set(this, Object.assign(base, props));
}
get(key) {
const props = zoneProps.get(this);
if (key in props) {
return props[key];
}
// undefined
}
// maybe implement has(key) too if you want.
}
Zone local storage example already delegates upward. No need for complicated proto tricks there.
Our first implementation of https://github.com/angular/zone.js#deprecated-zonejs-pre-v0515 did exactly that (prototype tricks) and it was a mistake.
1.) slow 2.) can't handle proper bubbling of events. You need ZoneDelegate for proper bubbling/interception.
Error handling and timer counting should probably do this.