You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Introduce built-in 'composite values' with well defined equality.
68
68
69
+
> [!IMPORTANT]
70
+
> Expect changes. The design below is a starting point to evolve from as discussion continues.
71
+
69
72
```js
70
73
constpos1=Composite({ x:1, y:4 });
71
74
constpos2=Composite({ x:1, y:4 });
@@ -314,12 +317,7 @@ No. A composite is an object. It's `typeof` is `"object"`.
314
317
315
318
### Can composites be compared with `===` or `Object.is`?
316
319
317
-
There is no special behavior for composites with regards to `===` and `Object.is`.
318
-
Like all objects they are only equal if they are compared to themselves.
319
-
320
-
While this means that composite equality is not universally triggered across the entire language it makes them significantly easier to implement in existing engines.
321
-
322
-
There is also performance expectations that `===` is fast, close to `O(1)` when composites have linear equality `O(n)`.
320
+
Discussion continues in [issue 15](https://github.com/tc39/proposal-composites/issues/15).
323
321
324
322
### Why modify existing `Map` and `Set` semantics
325
323
@@ -339,11 +337,11 @@ Let's discuss in [#4](https://github.com/acutmore/proposal-composites/issues/4).
339
337
340
338
### Why not a new protocol?
341
339
342
-
Why limit equality to only these composites values rather than let any object implement a new symbol protocol? The reason is reliability. To be able to participate as a `Map` key the equality must be pure, stable, and reliable, these guarantees would not come from a protocol that can execute arbitrary code. For example an object could have the symbol protocol added to it while it's in the map.
340
+
Why limit equality to only these composites values rather than let any object implement a new symbol protocol? The reason is reliability. To be able to participate as a `Map` key the equality must be pure, stable, and reliable, these guarantees would not come from a protocol that can execute arbitrary code. For example: an object having the symbol protocol added to it while it's in the map.
343
341
344
342
### Syntax?
345
343
346
-
There could be syntax to make creating composites more ergonomic and cleaner to read.
344
+
There could be syntax to make creating composites more ergonomic and cleaner to read. This would most likely be a separate, follow-on, proposal - after the Composites API has had time on its own in the ecosystem.
347
345
348
346
```js
349
347
#{ x:1 };
@@ -371,11 +369,13 @@ c[0]; // 1
371
369
c[1]; // 4
372
370
```
373
371
374
-
We instead encourage the components of the composite to be named to make the code easier to follow and avoid bugs where the indices are mixed up. We can see that this is how JavaScript is most commonly written today - code passes around objects with named properties rather than indexed lists.
372
+
We instead encourage the constituents of the composite to be named to make the code easier to follow and avoid bugs where the indices are mixed up. We can see that this is how JavaScript is most commonly written today - code passes around objects with named properties rather than indexed lists.
375
373
376
374
### Why implement natively in the language?
377
375
378
-
Engines will have an advantage when it comes to implementing composites compared to user-land. Engines can access the existing hash value of objects and strings, and they can access the internals of `Map` and `Set`.
376
+
Being able to create multi-value `Map` and `Set` keys is a common need across many application domains.
377
+
378
+
Additionally, engines will have an advantage when it comes to implementing composites compared to user-land. Engines can access the existing hash value of objects and strings, and they can access the internals of `Map` and `Set`.
379
379
380
380
### How does this compare to [proposal-richer-keys](https://github.com/tc39/proposal-richer-keys)?
0 commit comments