Skip to content

Add has and delete methods to WeakMap#12

Merged
stefanpenner merged 4 commits intostefanpenner:weak-mapfrom
thoov:hasDeleteWeakMap
Sep 16, 2015
Merged

Add has and delete methods to WeakMap#12
stefanpenner merged 4 commits intostefanpenner:weak-mapfrom
thoov:hasDeleteWeakMap

Conversation

@thoov
Copy link

@thoov thoov commented Sep 15, 2015

No description provided.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the value being stored is false or 0

I think the trick will be to do this.get(obj) !== 'undefined' an dif someone tries to set undefined we insert a sentinel value.

Example of such a sentinel: https://github.com/emberjs/ember.js/blob/master/packages/ember-metal/lib/cache.js#L13

https://github.com/emberjs/ember.js/blob/master/packages/ember-metal/lib/cache.js#L13

this prevents a potentially costly in check...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thoov
Copy link
Author

thoov commented Sep 15, 2015

Also added check for keys that are not objects when setting

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value === undefined is what we want here. (perfs)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch. I updated

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets do function UNDEFINED() {} that way it is named nicely in most modern debuggers.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call. updated

stefanpenner added a commit that referenced this pull request Sep 16, 2015
Add has and delete methods to WeakMap
@stefanpenner stefanpenner merged commit 77a97ed into stefanpenner:weak-map Sep 16, 2015
@stefanpenner
Copy link
Owner

thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants