[heycam/webidl] Allow multimaps (or directly support them) (#514)

There are a few places on the platform implementing the "multi-map" pattern, where:

1. the underlying values are lists of something
2. `get()` only returns the *first* value in the list
3. `set()` becomes `set(key, ...values)`
4. `getAll(key)` is added, returning the list
5. `append(key, ...values)` is added, adding/creating to the list

This allows users of the interface to pretend that it's a normal map with only a single value per key, but also properly interact with it as containing multiple values, without having to *always* treat it like a list.  (This is currently used by [URLSearchParams](https://url.spec.whatwg.org/#urlsearchparams) and [StylePropertyMap](https://drafts.css-houdini.org/css-typed-om-1/#the-stylepropertymap).)

Problem is that `maplike<>` doesn't allow you to override `get()` to have the correct behavior.

-----

We should probably actually define multimaps officially, because right now URL and TypedOM use *slightly different* definitions - URL doesn't make `set()` or `append()` n-ary, and just uses `iterable<>` (so that it can interweave different values for a single key with values for other keys; `?one=foo&two=bar&one=baz` is important to preserve and reflect).  I think this means we'd actually need two multimap forms - one for "map of unique key->list<val>" (StylePropertyMap) and one for "list<non-unique key->val>" (URLSearchParams).

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/heycam/webidl/issues/514

Received on Monday, 29 January 2018 04:22:13 UTC