@okyrychenko-dev/react-action-guard 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -530,6 +530,40 @@ function useAsyncAction(actionId, scope, options) {
530
530
  );
531
531
  return executeWithBlocking;
532
532
  }
533
+ function createBlockerConfig(config) {
534
+ return {
535
+ scope: config.scope,
536
+ reason: config.reason,
537
+ priority: config.priority
538
+ };
539
+ }
540
+ function normalizeScopeSnapshot(scope) {
541
+ if (scope === void 0) {
542
+ return [DEFAULT_SCOPE];
543
+ }
544
+ if (typeof scope === "string") {
545
+ return [scope];
546
+ }
547
+ return scope;
548
+ }
549
+ function getScopeSnapshotKey(scope) {
550
+ return JSON.stringify(normalizeScopeSnapshot(scope));
551
+ }
552
+ function toBlockerConfigSnapshot(config) {
553
+ return [
554
+ getScopeSnapshotKey(config.scope),
555
+ config.reason,
556
+ config.priority,
557
+ config.timestamp,
558
+ config.timeout,
559
+ config.onTimeout
560
+ ];
561
+ }
562
+ function areBlockerConfigsEqual(first, second) {
563
+ return shallow.shallow(toBlockerConfigSnapshot(first), toBlockerConfigSnapshot(second));
564
+ }
565
+
566
+ // src/hooks/useBlocker/useBlocker.ts
533
567
  function useBlocker(blockerId, config, isActive = true) {
534
568
  const { addBlocker, removeBlocker, updateBlocker } = useResolvedValue((state) => ({
535
569
  addBlocker: state.addBlocker,
@@ -552,22 +586,13 @@ function useBlocker(blockerId, config, isActive = true) {
552
586
  if (!isActive || !blockerId) {
553
587
  return;
554
588
  }
555
- if (lastConfigRef.current === config) {
589
+ if (lastConfigRef.current !== null && areBlockerConfigsEqual(lastConfigRef.current, config)) {
556
590
  return;
557
591
  }
558
592
  updateBlocker(blockerId, config);
559
593
  lastConfigRef.current = config;
560
594
  }, [blockerId, config, isActive, updateBlocker]);
561
595
  }
562
-
563
- // src/hooks/useBlocker/useBlocker.utils.ts
564
- function createBlockerConfig(config) {
565
- return {
566
- scope: config.scope,
567
- reason: config.reason,
568
- priority: config.priority
569
- };
570
- }
571
596
  function useBlockingInfo(scope = DEFAULT_SCOPE) {
572
597
  const store = useResolvedStoreApi();
573
598
  const activeBlockers = zustand.useStore(store, (state) => state.activeBlockers);