Comments (12)
I presume you know of Gonzola's implementation
from es6-shim.
yep, I've looked at it. seems to be OK.
from es6-shim.
I think it'd be best not to have this, so people just use Map
s and realize what they're getting into, instead of using WeakMap
s under the perhaps-mistaken impression that the shim could be weak.
from es6-shim.
@DomenicDenicola the shim can be weak. Look at Gonzola's implementation, it adhere's to the weak garbage collection semantics
from es6-shim.
I've tested WeakMap in node.js, it does proper GC. I've created 100000 objects (and weak map with them) and counted ram usage of node process. Then i've deleted objects and RAM usage has dropped to expected level.
from es6-shim.
I admit to not spending the necessary time to entirely understanding Gonzola's implementation, but it looks similar in spirit to Mark Miller's, which according to the comments has the flaw that
However, the values associated with a key in some map are retained so long as that key is retained and those associations are not overridden.
from es6-shim.
https://gist.github.com/1638059
I re-implemented my own flavour using gonzola's implementation as a base.
@DomenicDenicola I don't quite understand what's wrong with that. The values are retained as long as the key is retained. And as soon as the key is gone the values are gone too. That's the desired behaviour, right?
from es6-shim.
@Raynos no, the desired behavior is that neither keys nor values are held strongly. See the membrane example in Miller's comments.
from es6-shim.
So guys what do you finally think -- should es6-shim use @Raynos implementation of WeakMap even when it hold values strongly?
from es6-shim.
I vote no: people should use Map
s.
The main use case for including it would be for situations where freeing the memory would be nice, if possible, but not necessary. In those cases people should do global.WeakMap = global.Map
, knowing full well what they're getting into, or use a separate library. (@Raynos, perhaps you should publish a WeaklyKeyedMap
repo we can refer people to?)
from es6-shim.
@dominic, pd.Name
is a subset of weaklykeyedmap. It's more efficient and abstractions can be build on top of it. I don't intent to use a WeakMap because a Name is better.
from es6-shim.
I agree -- we should provide only 100% working shims. Mimicking API isn't good. I'll add a note to readme on weakmaps.
Thanks everyone.
from es6-shim.
Related Issues (20)
- Support for Promise.prototype.finally HOT 2
- Symbol.split polyfill poor performance HOT 1
- Question: Template literals supported? HOT 4
- Possible to only use needed components? HOT 1
- Function.prototype.name getter brokes function name getter HOT 2
- native Promise broken in node 10.0 and 10.1 HOT 1
- Unneeded argument for overrideNative HOT 2
- Promise 'then' incorrect? HOT 10
- For statement doesn't loop? HOT 4
- Shimmed Symbol.iterator is not recognized HOT 10
- TypeError: Object doesn't support property or method 'next' in IE browser HOT 10
- Does the array `of` shim apply to `for...of`? HOT 3
- WhiteSource warning - jQuery Vulnerability CVE-2020-11022 HOT 3
- babel-polyfill and es6-shim HOT 8
- Allowed iterator on empty object HOT 2
- Promise shim missing finally method HOT 1
- This software has new code recently, but no new version has been released. Will there be a new version released recently? HOT 4
- [spam]
- About update a new release HOT 3
- Documentation Icon Errors and typos HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from es6-shim.