summaryrefslogtreecommitdiff
path: root/src-migrate/utils
diff options
context:
space:
mode:
authorMiqdad <ahmadmiqdad27@gmail.com>2025-05-23 10:31:38 +0700
committerMiqdad <ahmadmiqdad27@gmail.com>2025-05-23 10:31:38 +0700
commit582f00294ba924b105c789b43e6e92beaf99260f (patch)
treee6f3aeab57357ed79b3ee4103197137c90b103f3 /src-migrate/utils
parenta2c424ebb371ce2716d7fc55bb70807303c2e0e0 (diff)
<miqdad> remove checkboxstate utils
Diffstat (limited to 'src-migrate/utils')
-rw-r--r--src-migrate/utils/checkBoxState.js89
1 files changed, 0 insertions, 89 deletions
diff --git a/src-migrate/utils/checkBoxState.js b/src-migrate/utils/checkBoxState.js
deleted file mode 100644
index 0c58321f..00000000
--- a/src-migrate/utils/checkBoxState.js
+++ /dev/null
@@ -1,89 +0,0 @@
-// ~/modules/cart/utils/checkboxUpdateState.js
-
-/**
- * Enhanced state manager for checkbox updates
- * Tracks both global update state and individual checkbox update states
- */
-
-// Track the number of ongoing updates
-let updateCount = 0;
-let listeners = [];
-
-// Track which checkboxes are currently updating by ID
-let updatingCheckboxIds = new Set();
-
-const checkboxUpdateState = {
- // Check if any checkboxes are currently updating (for buttons)
- isUpdating: () => updateCount > 0,
-
- // Check if a specific checkbox is updating (for disabling just that checkbox)
- isCheckboxUpdating: (itemId) => updatingCheckboxIds.has(itemId.toString()),
-
- // Start an update for a specific checkbox
- startUpdate: (itemId = null) => {
- updateCount++;
-
- // If an item ID is provided, mark it as updating
- if (itemId !== null) {
- updatingCheckboxIds.add(itemId.toString());
- }
-
- notifyListeners();
- return updateCount;
- },
-
- // End an update for a specific checkbox
- endUpdate: (itemId = null) => {
- updateCount = Math.max(0, updateCount - 1);
-
- // If an item ID is provided, remove it from updating set
- if (itemId !== null) {
- updatingCheckboxIds.delete(itemId.toString());
- }
-
- notifyListeners();
- return updateCount;
- },
-
- // Reset the update counter and clear all updating checkboxes
- reset: () => {
- updateCount = 0;
- updatingCheckboxIds.clear();
- notifyListeners();
- },
-
- // Get IDs of all checkboxes currently updating (for debugging)
- getUpdatingCheckboxIds: () => [...updatingCheckboxIds],
-
- // Add a listener function to be called when update state changes
- addListener: (callback) => {
- if (typeof callback === 'function') {
- listeners.push(callback);
-
- // Immediately call with current state
- callback(updateCount > 0);
- }
- },
-
- // Remove a listener
- removeListener: (callback) => {
- listeners = listeners.filter((listener) => listener !== callback);
- },
-
- // Get current counter (for debugging)
- getUpdateCount: () => updateCount,
-};
-
-// Private function to notify all listeners of state changes
-function notifyListeners() {
- const isUpdating = updateCount > 0;
- listeners.forEach((listener) => {
- try {
- listener(isUpdating);
- } catch (error) {
- console.error('Error in checkbox update state listener:', error);
- }
- });
-}
-
-export default checkboxUpdateState;