Replies: 1 comment
-
After giving this some thought and putting these options before a group of developers and discussing the options at length I've decided to go with option 2, adding an I'll be releasing Boutique 2.1 with a deprecation notice for those using |
Beta Was this translation helpful? Give feedback.
-
To start, let's look at a small snippet of code.
This code looks perfectly reasonable until you get to the last line, where the
removeTagFromAllLinks()
method calls calladd()
on theStore
to add links that already exist in theStore
. If you were trying to explain this to another developer you wouldn't say you're adding the new links, you'd say that you're updating the old links with updated links.Due to uniqueness requirements of items in a
Store
(based on the Store'scacheIdentifier
KeyPath parameter) theadd
method onStore
does two things.cacheIdentifier
does not exist, a new item will be added to the underlyingStore
.cacheIdentifier
does exist, it replaces that item with a new item.This is the desired behavior for how the Store should work, but not the behavior you would expect with a method named
add
. In practice I've found myself updating items quite frequently, as much if not more as adding new items, and callingself.$links.add(link)
to update items is unexpected unless you understand the semantics.To remedy this I'm considering two options.
update
function that aliases toadd
. This would create a clearer API, but one that doesn't provide much of a meaningful distinction. The upside of this approach is thatstore.update
is the most straightforward and communicative name, it would be the most obvious choice for searching through methods in documentation or autocomplete. The downside is thatadd
andupdate
would become interchangeable, so you'd be able to callupdate
when you should calladd
, oradd
whenupdate
is more appropriate.insert
function and deprecateadd
. This would be a more accurate match the Store'sSet
-like semantics, though would involve deprecatingadd
. I could do this gradually since it's not urgent, but I'm always hesitant to make big changes without consideration.Personally I'm leaning towards option 2, but wanted to post this publicly to get the feedback of others.
Beta Was this translation helpful? Give feedback.
All reactions