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.
- package/README.md +19 -12
- 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,
|
|
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: {
|
|
158
|
-
<p>Triple: {
|
|
163
|
+
<p>Double: {state.double}</p>
|
|
164
|
+
<p>Triple: {state.triple}</p>
|
|
159
165
|
|
|
160
|
-
<button onClick={() =>
|
|
161
|
-
<button onClick={() =>
|
|
162
|
-
<button onClick={() =>
|
|
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,
|
|
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: {
|
|
197
|
-
<p>Triple: {
|
|
203
|
+
<p>Double: {state.double}</p>
|
|
204
|
+
<p>Triple: {state.triple}</p>
|
|
198
205
|
|
|
199
|
-
<button onClick={() =>
|
|
200
|
-
<button onClick={() =>
|
|
201
|
-
<button onClick={() =>
|
|
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>
|