theme-scripts icon indicating copy to clipboard operation
theme-scripts copied to clipboard

Allow theme cart requests to be aborted

Open liamdefty opened this issue 4 years ago • 4 comments

Propsed change in #110 - allows pending requests to be aborted via an AbortController.

liamdefty avatar Oct 17 '19 23:10 liamdefty

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:

  1. Call a method, e.g. addItem(), and request is initiated.
  2. Another call to addItem with the same product key, but a new quantity, and the first request has not yet terminated.
  3. 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?

t-kelly avatar Jun 15 '20 14:06 t-kelly

Love it. Effortless and saves on requests 👌

Cam avatar Jun 15 '20 23:06 Cam

@liamdefty do you have the bandwidth to look into this further?

bertiful avatar Jun 23 '20 20:06 bertiful

@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 :)

liamdefty avatar Jun 24 '20 08:06 liamdefty