-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should CompositeKey have value-like equality? #2
Comments
Updated to reflect that value-like-semantics are likely to come with a requirement that at least one constituent one the key has a lifetime - like https://github.com/tc39/proposal-richer-keys So The reason for this is that otherwise CompositeKeys could make it too easy to create memory leaks. And while |
Note that Bradley's proposal was to have two different kinds of keys: Value-like semantics, no analogue to compositeSymbol
Value-like semantics on CompositeKey, non-value semantics on CompositeSymbol
|
An option could be to throw not when creating a primitives-only composite key, but when trying to use it in a weakmap. |
That seems like a much better choice. |
That would be very surprising, if even Web compatible, to have IMO, this constraint really leads to the unique object semantics. It's unfortunate to require user code explicitly use a new equality predicate, but I don't see how we can do otherwise if we want to use an object. There is still the possibility of overloading symbols I guess, since those are not universally acceptable as unique keys. But the mental overload of having even more kinds of symbols might be too high for authors as well. |
@mhofman that's already the case with |
I don't understand. Today all type |
Regarding web compatibility, no website currently uses |
Given how composable the ecosystem is, I don't think that's a fair assessment. There are definitely libraries out there that will assume an object they are passed as argument can be used as a WeakMap key. We've had the same discussion regarding R&T |
And exactly as it was for R&T, that problem increases adoption friction but doesn't break existing websites. There is no library today that would stop working (breaking some app/website) if browsers implement a CompositeKey that cannot be used as a weakmap key. However, developers of those website cannot start using CompositeKey with those libraries until they implement support for it. |
Making Is the global intern table that bad? I've done it in userland. If the concern is side-channels, we could instead expose a
Say more about why? Is it just so that you can garbage-collect |
The pollyfill in this repo uses an intern-trie. It's not a problem to implement - can be done in userland. For an API like I completely agree that |
Should CompositeKey have value-like equality?
Yes:
This would look something like this:
No:
This would look something like this:
Pros/Cons
Value like semantics
Map
s andSet
s don't need to beware of CompositeKey and treat it differently from other objectsnull
prototype.===
can add overhead to every===
call.CompositeKey(1, 2)
throws).new
Unique Object
new CompositeKey(1, 2)
allowed)Map
andSet
with akeyby
function.new
The text was updated successfully, but these errors were encountered: