Open sheerun opened 8 years ago
Do you want to extract this to an npm module? Inspired by your previous PR I implemented something similar here because I need it in that project too. Ideally I’d prefer this be an external module I could depend on in both projects.
Isn't https://github.com/medikoo/es6-weak-map exactly what you're looking for?
var WeakMap;
if (useWeakMap) {
WeakMap = require('es6-weak-map');
} else {
WeakMap = require('es6-weak-map/polyfill');
}
I don’t really care that much about real WeakMap
semantics—it’s fine to leak memory in older browsers in development mode during hot reloading. The problem with polyfills is they sometimes have tricky edge cases or may cause weird problems in some environments. Ideally I want to:
WeakMap
when possible but otherwise I’m fine leaking memory.WeakMap
polyfill works, but in my case I’d rather avoid it to avoid issues like this. Proxies are already invasive, and putting fields on components forces us to think about weird edge cases, which I’d rather avoid.Do you wish to restrict input values to only objects? (just like WeakMap)
Yeah, so that WeakMap case works.
I think https://github.com/WebReflection/es6-collections implementation should suit you except:
I could fix both and extract code to the new module. OK?
I’d really prefer my implementation in this case. The surface area I need is very small, and putting components into “slots” by their displayName/name reduces the lookup time for the common case. I think we can benefit from having a very specific use case (map by component) here.
OK, I think I have full picture. I'll try to come up with something soon.
Have you come up with something new? Or should we just close this?
@wkwiatek Thanks for reminding.. I've created https://github.com/sheerun/component-map and update this PR to use it. ComponentMap includes lots of tests that also verify proper garbage collection. Hope you like it.
@gaearon You might want to consider using component-map it in react-hot-loader as well
Supersedes #57