redux-sacala 0.3.0 → 0.3.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.
Files changed (2) hide show
  1. package/README.md +35 -0
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -79,6 +79,41 @@ const rootBlock = ReduxBlock.composition("root")
79
79
  // rootBlock.actions.logAndIncrement()
80
80
  ```
81
81
 
82
+ ### Context Mapping
83
+
84
+ You can change the context shape of a block using `ReduxBlock.mapContext`. This is useful when you want to adapt a block to a different environment or use a more convenient context structure.
85
+
86
+ ```typescript
87
+ interface OldContext {
88
+ log: {
89
+ error: (msg: string) => void;
90
+ info: (msg: string) => void;
91
+ };
92
+ }
93
+
94
+ const block = ReduxBlock.builder("test", { message: "" })
95
+ .effects((ctx: OldContext) => ({
96
+ logError: (msg: string) => ctx.log.error(msg),
97
+ }))
98
+ .build();
99
+
100
+ interface NewContext {
101
+ log: (level: "error" | "info", msg: string) => void;
102
+ }
103
+
104
+ const mappedBlock = ReduxBlock.mapContext(
105
+ block,
106
+ (ctx: NewContext): OldContext => ({
107
+ log: {
108
+ error: (msg) => ctx.log("error", msg),
109
+ info: (msg) => ctx.log("info", msg),
110
+ },
111
+ }),
112
+ );
113
+
114
+ // Now mappedBlock expects NewContext
115
+ ```
116
+
82
117
  ### Minimal Redux Toolkit Example
83
118
 
84
119
  ```typescript
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "redux-sacala",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "type": "module",
5
5
  "author": {
6
6
  "name": "Andrey Monkin",