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.
Uh oh!
There was an error while loading. Please reload this page.
-
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 theStoreto 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'scacheIdentifierKeyPath parameter) theaddmethod onStoredoes two things.cacheIdentifierdoes not exist, a new item will be added to the underlyingStore.cacheIdentifierdoes 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.
updatefunction 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.updateis the most straightforward and communicative name, it would be the most obvious choice for searching through methods in documentation or autocomplete. The downside is thataddandupdatewould become interchangeable, so you'd be able to callupdatewhen you should calladd, oraddwhenupdateis more appropriate.insertfunction 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