@okyrychenko-dev/react-action-guard 1.0.1 → 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/README.md +1 -3
- package/dist/index.cjs +36 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -14
- package/dist/index.d.ts +6 -14
- package/dist/index.js +37 -22
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -434,8 +434,6 @@ Provides an isolated store instance for SSR, testing, or micro-frontends. Withou
|
|
|
434
434
|
**Props:**
|
|
435
435
|
|
|
436
436
|
- `children: ReactNode` - Child components
|
|
437
|
-
- `enableDevtools?: boolean` - Enable Redux DevTools (default: true in development)
|
|
438
|
-
- `devtoolsName?: string` - Name for DevTools (default: "UIBlocking")
|
|
439
437
|
- `middlewares?: Middleware[]` - Initial middlewares to register
|
|
440
438
|
|
|
441
439
|
**Example:**
|
|
@@ -462,7 +460,7 @@ function renderWithProvider(ui) {
|
|
|
462
460
|
// Micro-frontends - each app has its own blocking state
|
|
463
461
|
function MicroFrontend() {
|
|
464
462
|
return (
|
|
465
|
-
<UIBlockingProvider
|
|
463
|
+
<UIBlockingProvider>
|
|
466
464
|
<MicroApp />
|
|
467
465
|
</UIBlockingProvider>
|
|
468
466
|
);
|
package/dist/index.cjs
CHANGED
|
@@ -463,8 +463,6 @@ function useUIBlockingStoreFromContext(selector, equalityFn) {
|
|
|
463
463
|
}
|
|
464
464
|
function UIBlockingProvider({
|
|
465
465
|
children,
|
|
466
|
-
enableDevtools = process.env.NODE_ENV === "development",
|
|
467
|
-
devtoolsName = "UIBlocking",
|
|
468
466
|
middlewares = []
|
|
469
467
|
}) {
|
|
470
468
|
const handleStoreInit = (store) => {
|
|
@@ -472,15 +470,7 @@ function UIBlockingProvider({
|
|
|
472
470
|
store.getState().registerMiddleware(`provider-middleware-${index.toString()}`, mw);
|
|
473
471
|
});
|
|
474
472
|
};
|
|
475
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
476
|
-
BaseUIBlockingProvider,
|
|
477
|
-
{
|
|
478
|
-
enableDevtools,
|
|
479
|
-
devtoolsName,
|
|
480
|
-
onStoreInit: handleStoreInit,
|
|
481
|
-
children
|
|
482
|
-
}
|
|
483
|
-
);
|
|
473
|
+
return /* @__PURE__ */ jsxRuntime.jsx(BaseUIBlockingProvider, { onStoreInit: handleStoreInit, children });
|
|
484
474
|
}
|
|
485
475
|
|
|
486
476
|
// src/store/uiBlockingStore.config.ts
|
|
@@ -540,6 +530,40 @@ function useAsyncAction(actionId, scope, options) {
|
|
|
540
530
|
);
|
|
541
531
|
return executeWithBlocking;
|
|
542
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
|
|
543
567
|
function useBlocker(blockerId, config, isActive = true) {
|
|
544
568
|
const { addBlocker, removeBlocker, updateBlocker } = useResolvedValue((state) => ({
|
|
545
569
|
addBlocker: state.addBlocker,
|
|
@@ -562,22 +586,13 @@ function useBlocker(blockerId, config, isActive = true) {
|
|
|
562
586
|
if (!isActive || !blockerId) {
|
|
563
587
|
return;
|
|
564
588
|
}
|
|
565
|
-
if (lastConfigRef.current
|
|
589
|
+
if (lastConfigRef.current !== null && areBlockerConfigsEqual(lastConfigRef.current, config)) {
|
|
566
590
|
return;
|
|
567
591
|
}
|
|
568
592
|
updateBlocker(blockerId, config);
|
|
569
593
|
lastConfigRef.current = config;
|
|
570
594
|
}, [blockerId, config, isActive, updateBlocker]);
|
|
571
595
|
}
|
|
572
|
-
|
|
573
|
-
// src/hooks/useBlocker/useBlocker.utils.ts
|
|
574
|
-
function createBlockerConfig(config) {
|
|
575
|
-
return {
|
|
576
|
-
scope: config.scope,
|
|
577
|
-
reason: config.reason,
|
|
578
|
-
priority: config.priority
|
|
579
|
-
};
|
|
580
|
-
}
|
|
581
596
|
function useBlockingInfo(scope = DEFAULT_SCOPE) {
|
|
582
597
|
const store = useResolvedStoreApi();
|
|
583
598
|
const activeBlockers = zustand.useStore(store, (state) => state.activeBlockers);
|