tc39 / proposal-readonly-collections

Proposal: snapshot,diverge,readOnlyView methods for all collections
Apache License 2.0
35 stars 3 forks source link

Why not WeakMap/WeakSet? #2

Open ljharb opened 4 years ago

ljharb commented 4 years ago

I want to be able to pass around say, a WeakSet, without granting the ability to add things to it, or remove things from it. Why can't I?

erights commented 4 years ago

Interesting! Yes, WeakMap and WeakSet could support readOnlyView(). We could easily extend the shim to shim these as well.

erights commented 4 years ago

It actually makes sense for all of snapshot/diverge/readOnlyView to apply to weak collections. snapshot and diverge are sufficiently hard to emulate in userland that I don't expect anyone to shim these. The open question is: For a platform using the transposed representation of weak collections, could snapshot and diverge be provided without undue implementation burden? If not, I'd consider that a show stopper.

But readOnlyView should still be provided regardless.

erights commented 4 years ago

See https://github.com/tc39/proposal-setmap-offrom/issues/26

zloirock commented 4 years ago

I'm for .readOnlyView only - the explanation by the link above.