Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Zone Solutions.md doesn't always delegate upward to parent zones #5

Open
domenic opened this issue Mar 29, 2016 · 3 comments
Open

Zone Solutions.md doesn't always delegate upward to parent zones #5

domenic opened this issue Mar 29, 2016 · 3 comments

Comments

@domenic
Copy link
Owner

domenic commented Mar 29, 2016

Error handling and timer counting should probably do this.

@bmeck
Copy link

bmeck commented Apr 1, 2016

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.
}

@domenic
Copy link
Owner Author

domenic commented Apr 1, 2016

Zone local storage example already delegates upward. No need for complicated proto tricks there.

@mhevery
Copy link

mhevery commented Apr 5, 2016

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants