logic-runtime-react-z 3.1.3 → 3.1.4

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 +19 -12
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -90,6 +90,11 @@ const counterLogic = createLogic({
90
90
  })
91
91
  })
92
92
  },
93
+ actions: {
94
+ add({ emit }) {
95
+ return (n: number) => emit("add", n)
96
+ }
97
+ },
93
98
  })
94
99
 
95
100
  async function main() {
@@ -150,16 +155,18 @@ import { counterLogic } from "./counter.logic"
150
155
  type CounterInjected =
151
156
  LogicViewProps<typeof counterLogic>
152
157
 
153
- const CounterView = ({ state, computed, intent }: LogicViewProps) => {
158
+ const CounterView = ({ state, actions, emit }: LogicViewProps) => {
159
+ // actions and emit => same emit
154
160
  return (
155
161
  <div>
156
162
  <h2>Count: {state.count}</h2>
157
- <p>Double: {computed.double}</p>
158
- <p>Triple: {computed.triple}</p>
163
+ <p>Double: {state.double}</p>
164
+ <p>Triple: {state.triple}</p>
159
165
 
160
- <button onClick={() => intent("inc")}>+</button>
161
- <button onClick={() => intent("dec")}>-</button>
162
- <button onClick={() => intent("asyncInc")}>
166
+ <button onClick={() => emit("inc")}>+</button>
167
+ <button onClick={() => emit("dec")}>-</button>
168
+ <button onClick={() => actions.add(10)}>+10 (action)</button>
169
+ <button onClick={() => emit("asyncInc")}>
163
170
  {state.loading ? "Loading..." : "Async +"}
164
171
  </button>
165
172
  </div>
@@ -188,17 +195,17 @@ import { useLogic } from "logic-runtime-react-z"
188
195
  import { counterLogic } from "./counter.logic"
189
196
 
190
197
  export function Counter() {
191
- const { state, computed, intent } = useLogic(counterLogic)
198
+ const { state, actions, emit } = useLogic(counterLogic)
192
199
 
193
200
  return (
194
201
  <div>
195
202
  <h2>Count: {state.count}</h2>
196
- <p>Double: {computed.double}</p>
197
- <p>Triple: {computed.triple}</p>
203
+ <p>Double: {state.double}</p>
204
+ <p>Triple: {state.triple}</p>
198
205
 
199
- <button onClick={() => intent("inc")}>+</button>
200
- <button onClick={() => intent("dec")}>-</button>
201
- <button onClick={() => intent("asyncInc")}>
206
+ <button onClick={() => emit("inc")}>+</button>
207
+ <button onClick={() => emit("dec")}>-</button>
208
+ <button onClick={() => emit("asyncInc")}>
202
209
  {state.loading ? "Loading..." : "Async +"}
203
210
  </button>
204
211
  </div>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "logic-runtime-react-z",
3
- "version": "3.1.3",
3
+ "version": "3.1.4",
4
4
  "description": "Intent-first business logic runtime. Deterministic, headless, and framework-agnostic.",
5
5
  "license": "MIT",
6
6
  "author": "Delpi.Kye",