diff options
| author | Miqdad <ahmadmiqdad27@gmail.com> | 2025-05-26 20:00:17 +0700 |
|---|---|---|
| committer | Miqdad <ahmadmiqdad27@gmail.com> | 2025-05-26 20:00:17 +0700 |
| commit | 3feaad9127ff429b27f0eb69fa6ea539de2f2e8c (patch) | |
| tree | d2b65790861531e08fd9eb3e1d1cd64eb5805e15 /src-migrate/utils/cart.js | |
| parent | cca6d803fc4db729865def23004ab1c4bd279e24 (diff) | |
<miqdad> Cleaning code
Diffstat (limited to 'src-migrate/utils/cart.js')
| -rw-r--r-- | src-migrate/utils/cart.js | 40 |
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 |
