Skip to content

Commit 70f2436

Browse files
committed
Use actual WeakMap in example per @littledan's feedback
1 parent 92a646a commit 70f2436

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Zone Solutions.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,19 @@ A more structured version of zone-local storage tries to impose these two proper
9090
To accomplish this, we build a subclass of `Zone` that takes care of these details for us:
9191

9292
```js
93+
const zoneProps = new WeakMap();
94+
9395
class ZoneWithStorage extends Zone {
9496
constructor(options, props = Object.create(null)) {
9597
super(options);
96-
this._props = Object.assign({}, props); // or: use WeakMaps for integrity
98+
zoneProps.set(this, Object.assign({}, props));
9799
}
98100

99101
get(key) {
100-
if (key in this._props) {
101-
return this._props[key];
102+
const props = zoneProps.get(this);
103+
104+
if (key in props) {
105+
return props[key];
102106
}
103107

104108
if (this.parent instanceof ZoneWithStorage) {

0 commit comments

Comments
 (0)