summaryrefslogtreecommitdiff
path: root/src-migrate/utils/cart.js
diff options
context:
space:
mode:
Diffstat (limited to 'src-migrate/utils/cart.js')
-rw-r--r--src-migrate/utils/cart.js40
1 files changed, 40 insertions, 0 deletions
diff --git a/src-migrate/utils/cart.js b/src-migrate/utils/cart.js
index ebd771e5..4bdee49a 100644
--- a/src-migrate/utils/cart.js
+++ b/src-migrate/utils/cart.js
@@ -413,3 +413,43 @@ export const removeSelectedItemsFromCookie = (productIds) => {
return {};
}
};
+
+class QuantityUpdateState {
+ constructor() {
+ this.updateItems = new Set();
+ this.listeners = new Set();
+ }
+
+ startUpdate(itemId) {
+ this.updateItems.add(itemId);
+ this.notifyListeners();
+ }
+
+ endUpdate(itemId) {
+ this.updateItems.delete(itemId);
+ this.notifyListeners();
+ }
+
+ isAnyQuantityUpdating() {
+ return this.updateItems.size > 0;
+ }
+
+ isItemUpdating(itemId) {
+ return this.updateItems.has(itemId);
+ }
+
+ addListener(callback) {
+ this.listeners.add(callback);
+ }
+
+ removeListener(callback) {
+ this.listeners.delete(callback);
+ }
+
+ notifyListeners() {
+ const isUpdating = this.isAnyQuantityUpdating();
+ this.listeners.forEach(callback => callback(isUpdating));
+ }
+}
+
+export const quantityUpdateState = new QuantityUpdateState(); \ No newline at end of file