@squide/msw 2.0.6 → 2.0.7

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/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @squide/msw
2
2
 
3
+ ## 2.0.7
4
+
5
+ ### Patch Changes
6
+
7
+ - [#128](https://github.com/gsoft-inc/wl-squide/pull/128) [`4c3b6f1`](https://github.com/gsoft-inc/wl-squide/commit/4c3b6f1929364844dda6c1190fc45c3b037e8df9) Thanks [@patricklafrance](https://github.com/patricklafrance)! - Internally changed the usage of `setInterval` for `useSyncExternalStore`.
8
+
9
+ - Updated dependencies [[`4c3b6f1`](https://github.com/gsoft-inc/wl-squide/commit/4c3b6f1929364844dda6c1190fc45c3b037e8df9)]:
10
+ - @squide/core@3.1.1
11
+
3
12
  ## 2.0.6
4
13
 
5
14
  ### Patch Changes
@@ -0,0 +1,44 @@
1
+ // src/mswState.ts
2
+ var MswState = class {
3
+ #isStarted = false;
4
+ #stateChangedListeners = /* @__PURE__ */ new Set();
5
+ addStateChangedListener(callback) {
6
+ this.#stateChangedListeners.add(callback);
7
+ }
8
+ removeStateChangedListener(callback) {
9
+ this.#stateChangedListeners.delete(callback);
10
+ }
11
+ setAsStarted() {
12
+ if (!this.#isStarted) {
13
+ this.#isStarted = true;
14
+ this.#stateChangedListeners.forEach((x) => {
15
+ x();
16
+ });
17
+ }
18
+ }
19
+ get isStarted() {
20
+ return this.#isStarted;
21
+ }
22
+ // Strictly for Jest tests, this is NOT ideal.
23
+ _reset() {
24
+ this.#isStarted = false;
25
+ }
26
+ };
27
+ var mswState = new MswState();
28
+ function setMswAsStarted() {
29
+ mswState.setAsStarted();
30
+ }
31
+ function isMswStarted() {
32
+ return mswState.isStarted;
33
+ }
34
+ function addMswStateChangedListener(callback) {
35
+ mswState.addStateChangedListener(callback);
36
+ }
37
+ function removeMswStateChangedListener(callback) {
38
+ mswState.removeStateChangedListener(callback);
39
+ }
40
+ function __resetMswStatus() {
41
+ mswState._reset();
42
+ }
43
+
44
+ export { MswState, __resetMswStatus, addMswStateChangedListener, isMswStarted, removeMswStateChangedListener, setMswAsStarted };
@@ -1,4 +1,4 @@
1
- import { RequestHandlerRegistry } from './chunk-2J7GQPWR.js';
1
+ import { RequestHandlerRegistry } from './chunk-UJ4YM7IF.js';
2
2
  import { Plugin, isNil } from '@squide/core';
3
3
 
4
4
  var MswPlugin = class _MswPlugin extends Plugin {
@@ -0,0 +1,20 @@
1
+ import { isMswStarted, addMswStateChangedListener, removeMswStateChangedListener } from './chunk-4FYK3XXP.js';
2
+ import { useLogger } from '@squide/core';
3
+ import { useSyncExternalStore, useEffect } from 'react';
4
+
5
+ function subscribe(callback) {
6
+ addMswStateChangedListener(callback);
7
+ return () => removeMswStateChangedListener(callback);
8
+ }
9
+ function useIsMswStarted(enabled) {
10
+ const isStarted = useSyncExternalStore(subscribe, isMswStarted);
11
+ const logger = useLogger();
12
+ useEffect(() => {
13
+ if (isStarted) {
14
+ logger.debug("[squide] %cMSW is ready%c.", "color: white; background-color: green;", "");
15
+ }
16
+ }, [isStarted, logger]);
17
+ return isStarted || !enabled;
18
+ }
19
+
20
+ export { useIsMswStarted };
@@ -1,4 +1,4 @@
1
- import { isMswStarted } from './chunk-JLS7DBDX.js';
1
+ import { isMswStarted } from './chunk-4FYK3XXP.js';
2
2
 
3
3
  // src/requestHandlerRegistry.ts
4
4
  var RequestHandlerRegistry = class {
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { MswPlugin, getMswPlugin } from './mswPlugin.js';
2
+ export { MswState, MswStateChangedListener, __resetMswStatus, addMswStateChangedListener, isMswStarted, removeMswStateChangedListener, setMswAsStarted } from './mswState.js';
2
3
  export { RequestHandlerRegistry } from './requestHandlerRegistry.js';
3
- export { __resetMswStatus, isMswStarted, setMswAsStarted } from './setMswAsStarted.js';
4
- export { UseIsMswStartedOptions, useIsMswStarted } from './useIsMswStarted.js';
4
+ export { useIsMswStarted } from './useIsMswStarted.js';
5
5
  import '@squide/core';
6
6
  import 'msw';
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { MswPlugin, getMswPlugin } from './chunk-OKIK46QG.js';
2
- export { RequestHandlerRegistry } from './chunk-2J7GQPWR.js';
3
- export { useIsMswStarted } from './chunk-WLTQXA6A.js';
4
- export { __resetMswStatus, isMswStarted, setMswAsStarted } from './chunk-JLS7DBDX.js';
1
+ export { MswPlugin, getMswPlugin } from './chunk-BH5GURQ4.js';
2
+ export { RequestHandlerRegistry } from './chunk-UJ4YM7IF.js';
3
+ export { useIsMswStarted } from './chunk-ETD3TDL4.js';
4
+ export { MswState, __resetMswStatus, addMswStateChangedListener, isMswStarted, removeMswStateChangedListener, setMswAsStarted } from './chunk-4FYK3XXP.js';
package/dist/mswPlugin.js CHANGED
@@ -1,3 +1,3 @@
1
- export { MswPlugin, getMswPlugin } from './chunk-OKIK46QG.js';
2
- import './chunk-2J7GQPWR.js';
3
- import './chunk-JLS7DBDX.js';
1
+ export { MswPlugin, getMswPlugin } from './chunk-BH5GURQ4.js';
2
+ import './chunk-UJ4YM7IF.js';
3
+ import './chunk-4FYK3XXP.js';
@@ -0,0 +1,16 @@
1
+ type MswStateChangedListener = () => void;
2
+ declare class MswState {
3
+ #private;
4
+ addStateChangedListener(callback: MswStateChangedListener): void;
5
+ removeStateChangedListener(callback: MswStateChangedListener): void;
6
+ setAsStarted(): void;
7
+ get isStarted(): boolean;
8
+ _reset(): void;
9
+ }
10
+ declare function setMswAsStarted(): void;
11
+ declare function isMswStarted(): boolean;
12
+ declare function addMswStateChangedListener(callback: MswStateChangedListener): void;
13
+ declare function removeMswStateChangedListener(callback: MswStateChangedListener): void;
14
+ declare function __resetMswStatus(): void;
15
+
16
+ export { MswState, type MswStateChangedListener, __resetMswStatus, addMswStateChangedListener, isMswStarted, removeMswStateChangedListener, setMswAsStarted };
@@ -0,0 +1 @@
1
+ export { MswState, __resetMswStatus, addMswStateChangedListener, isMswStarted, removeMswStateChangedListener, setMswAsStarted } from './chunk-4FYK3XXP.js';
@@ -1,2 +1,2 @@
1
- export { RequestHandlerRegistry } from './chunk-2J7GQPWR.js';
2
- import './chunk-JLS7DBDX.js';
1
+ export { RequestHandlerRegistry } from './chunk-UJ4YM7IF.js';
2
+ import './chunk-4FYK3XXP.js';
@@ -1,6 +1,3 @@
1
- interface UseIsMswStartedOptions {
2
- interval?: number;
3
- }
4
- declare function useIsMswStarted(enabled: boolean, { interval }?: UseIsMswStartedOptions): boolean;
1
+ declare function useIsMswStarted(enabled: boolean): boolean;
5
2
 
6
- export { type UseIsMswStartedOptions, useIsMswStarted };
3
+ export { useIsMswStarted };
@@ -1,2 +1,2 @@
1
- export { useIsMswStarted } from './chunk-WLTQXA6A.js';
2
- import './chunk-JLS7DBDX.js';
1
+ export { useIsMswStarted } from './chunk-ETD3TDL4.js';
2
+ import './chunk-4FYK3XXP.js';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@squide/msw",
3
3
  "author": "Workleap",
4
- "version": "2.0.6",
4
+ "version": "2.0.7",
5
5
  "description": "Add support for MSW to @squide federated application shell.",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
@@ -49,7 +49,7 @@
49
49
  "typescript": "5.2.2"
50
50
  },
51
51
  "dependencies": {
52
- "@squide/core": "3.1.0"
52
+ "@squide/core": "3.1.1"
53
53
  },
54
54
  "sideEffects": false,
55
55
  "engines": {
@@ -1,13 +0,0 @@
1
- // src/setMswAsStarted.ts
2
- var isStarted = false;
3
- function setMswAsStarted() {
4
- isStarted = true;
5
- }
6
- function isMswStarted() {
7
- return isStarted;
8
- }
9
- function __resetMswStatus() {
10
- isStarted = false;
11
- }
12
-
13
- export { __resetMswStatus, isMswStarted, setMswAsStarted };
@@ -1,27 +0,0 @@
1
- import { isMswStarted } from './chunk-JLS7DBDX.js';
2
- import { useLogger } from '@squide/core';
3
- import { useState, useEffect } from 'react';
4
-
5
- function useIsMswStarted(enabled, { interval = 10 } = {}) {
6
- const logger = useLogger();
7
- const [value, setIsStarted] = useState(!enabled);
8
- useEffect(() => {
9
- if (enabled) {
10
- const intervalId = setInterval(() => {
11
- if (isMswStarted()) {
12
- logger.debug("[squide] %cMSW is ready%c.", "color: white; background-color: green;", "");
13
- clearInterval(intervalId);
14
- setIsStarted(true);
15
- }
16
- }, interval);
17
- return () => {
18
- if (intervalId) {
19
- clearInterval(intervalId);
20
- }
21
- };
22
- }
23
- }, [enabled, interval, logger]);
24
- return value;
25
- }
26
-
27
- export { useIsMswStarted };
@@ -1,5 +0,0 @@
1
- declare function setMswAsStarted(): void;
2
- declare function isMswStarted(): boolean;
3
- declare function __resetMswStatus(): void;
4
-
5
- export { __resetMswStatus, isMswStarted, setMswAsStarted };
@@ -1 +0,0 @@
1
- export { __resetMswStatus, isMswStarted, setMswAsStarted } from './chunk-JLS7DBDX.js';