Open leobalter opened 2 weeks ago
The most common use case in my experience is upsert - ie, both.
The most common use case in my experience is upsert - ie, both.
Do you have examples of this? To me it seems like the most common use case is "insert if missing" by providing a default.
It looks like the last time this was discussed in committee, there was a strong desire to split this into two separate methods: https://github.com/tc39/proposal-upsert/issues/31, so I've been assuming any new design work here would involve separating the "insert if missing" from the "update if present" use cases.
Imagine an object representing a database row as a value in a Map; upsert would be “insert if missing, else update the modified_at timestamp and any updated properties”
My ask is to add a readme piece why this proposal does not consider adding separate methods for
update
andinsert
into Map.prototype.I guess there is already discussions over this topic and I understand there might be a desire to avoid observable points that could affect performance, although the current design smells a bit on getting object methods to call before adding a value:
It also currently throws a conditional TypeError because
update
is not callable if the key exists in the map, otherwise a TypeError if the key doesn't exist andinsert
is not present. It's equivalent to running a.get
before.I'm unaware why this can't propose other methods analogue to
.add
such asinsert
andupdate
.