theme-scripts
theme-scripts copied to clipboard
Allow theme cart requests to be aborted
Propsed change in #110 - allows pending requests to be aborted via an AbortController
.
So I like the idea of using AbortController to override pending requests, I'm just not a fan of how it's implemented here. I feel like adding it as its own standalone method still requires developers to be aware and knowledgable of the API and how to use it. This PR is ultimately an abstraction of the API and makes it a little easier to use in the context of the Cart API.
In addition, what's added here could just as easily be done externally from this library in the same place you're creating event handlers that initiate the Cart API requests.
Instead of a standalone method to abort requests, what if we embedded AbortController inside all existing methods in a way that produces the following behaviour:
- Call a method, e.g. addItem(), and request is initiated.
- Another call to addItem with the same product key, but a new quantity, and the first request has not yet terminated.
- Cancel the first request and create a new request with the updated values
This approach doesn't require the developer to learn anything more upfront to use this library, but it upgrades parts of underlying request management layer.
Thoughts?
Love it. Effortless and saves on requests 👌
@liamdefty do you have the bandwidth to look into this further?
@t-kelly Yep totally agree, that makes a lot more sense! 👏
@chrisberthe Yep, I can make some time over the next week or so to take a look :)