@mapples/action 1.1.0 → 1.1.1
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActionProvider.d.ts","sourceRoot":"","sources":["../src/ActionProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,iBAAiB,
|
|
1
|
+
{"version":3,"file":"ActionProvider.d.ts","sourceRoot":"","sources":["../src/ActionProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,iBAAiB,EAAuB,MAAM,OAAO,CAAC;AAMnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAE9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,QAAA,MAAM,cAAc,EAAE,EAAE,CAAC,iBAAiB,CAAC,mBAAmB,CAAC,CAoB9D,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
package/dist/ActionProvider.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useEffect,
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
2
|
import { Subject } from 'rxjs';
|
|
3
3
|
import { ActionContextProvider } from './context';
|
|
4
4
|
/**
|
|
@@ -32,14 +32,16 @@ import { ActionContextProvider } from './context';
|
|
|
32
32
|
* ```
|
|
33
33
|
*/
|
|
34
34
|
const ActionProvider = ({ children, onAction, }) => {
|
|
35
|
-
|
|
35
|
+
// Lazy state init creates the Subject exactly once and keeps the same
|
|
36
|
+
// instance for the provider's lifetime, without reading a ref during render.
|
|
37
|
+
const [actionStore] = useState(() => new Subject());
|
|
36
38
|
useEffect(() => {
|
|
37
|
-
const subscription =
|
|
39
|
+
const subscription = actionStore.subscribe(onAction);
|
|
38
40
|
return () => {
|
|
39
41
|
return subscription.unsubscribe();
|
|
40
42
|
};
|
|
41
|
-
}, [onAction]);
|
|
42
|
-
return (<ActionContextProvider value={{ actionStore
|
|
43
|
+
}, [actionStore, onAction]);
|
|
44
|
+
return (<ActionContextProvider value={{ actionStore }}>
|
|
43
45
|
{children}
|
|
44
46
|
</ActionContextProvider>);
|
|
45
47
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActionProvider.js","sourceRoot":"","sources":["../src/ActionProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAyB,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"ActionProvider.js","sourceRoot":"","sources":["../src/ActionProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAyB,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAGnE,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAE/B,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAGlD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,cAAc,GAA+C,CAAC,EAClE,QAAQ,EACR,QAAQ,GACT,EAAE,EAAE;IACH,sEAAsE;IACtE,6EAA6E;IAC7E,MAAM,CAAC,WAAW,CAAC,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC,IAAI,OAAO,EAAU,CAAC,CAAC;IAE5D,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,YAAY,GAAG,WAAW,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;QACrD,OAAO,GAAG,EAAE;YACV,OAAO,YAAY,CAAC,WAAW,EAAE,CAAC;QACpC,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC,CAAC;IAE5B,OAAO,CACL,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,CAC5C;MAAA,CAAC,QAAQ,CACX;IAAA,EAAE,qBAAqB,CAAC,CACzB,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
* - Subscribe to actions using `actionStore.subscribe(callback)`
|
|
7
7
|
* - Access the RxJS Subject for advanced reactive operations
|
|
8
8
|
*
|
|
9
|
-
* @returns
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
* @returns The RxJS Subject that manages action emissions and subscriptions.
|
|
10
|
+
* When used outside of an `ActionProvider`, returns the default context Subject (a bare
|
|
11
|
+
* `new Subject()` with no active subscriptions).
|
|
12
12
|
*
|
|
13
13
|
* @example
|
|
14
14
|
* ```tsx
|
|
@@ -8,9 +8,9 @@ import ActionContext from '../context';
|
|
|
8
8
|
* - Subscribe to actions using `actionStore.subscribe(callback)`
|
|
9
9
|
* - Access the RxJS Subject for advanced reactive operations
|
|
10
10
|
*
|
|
11
|
-
* @returns
|
|
12
|
-
*
|
|
13
|
-
*
|
|
11
|
+
* @returns The RxJS Subject that manages action emissions and subscriptions.
|
|
12
|
+
* When used outside of an `ActionProvider`, returns the default context Subject (a bare
|
|
13
|
+
* `new Subject()` with no active subscriptions).
|
|
14
14
|
*
|
|
15
15
|
* @example
|
|
16
16
|
* ```tsx
|