You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -66,7 +64,7 @@ import React, { Fragment } from "react";
66
64
functionApp() {
67
65
return (
68
66
<Fragment>
69
-
{
67
+
{
70
68
// Your application here
71
69
}
72
70
</Fragment>
@@ -86,10 +84,9 @@ module.exports = {
86
84
};
87
85
```
88
86
89
-
90
87
## Definition of concepts
91
88
92
-
**GX** comes with some new concepts like `signal`, `action` and `store`.
89
+
**GX** comes with some new concepts like `signal`, `action`, and `store`.
93
90
94
91
### 1. Signal
95
92
@@ -100,7 +97,7 @@ For handle it, there is a special `createSignal` function for this case.
100
97
101
98
### 2. Action
102
99
103
-
**Actions** represent functions that act to the state and make it changing over the time.
100
+
**Actions** represent functions that act to the state and make it changing over the time.
104
101
105
102
Your have to specify these `actions` when you create yours `signals`.
106
103
@@ -121,7 +118,6 @@ For structuring your code very well you have to follow these steps.
121
118
- Inside the signals directory you will create files that will contains your state declaration with actions that act to this state. (**ie: counter.js**)
122
119
- Inside the store directory, just create an index.js file. We will see how to fill it.
Note that the `useSignal` hook takes the name of the signal as a parameter and return the state contained inside that signal.
212
+
Note that the `useSignal` hook takes the name of the signal as a parameter and return the state contained inside that signal.
218
213
219
214
The `useAction` hook takes the name of the signal too and returns an object that contains all the actions of this signal.
220
215
221
216
Actually, if you click on the increment button, the counter will increase by one and if you click on the decrement button, the counter will decrease by one.
222
217
218
+
### Sixth step: Adding operations to your signals.
219
+
220
+
This feature comes with the version `1.3.0` of `gx`. It allows you to add operations to your signals.
221
+
**Operations** are functions that use your current state and apply some filters on it. They return the result of the operation without changing the state.
222
+
223
+
For example, if you want to know if the counter is even or odd, you can create an operation called `isEven` like follow.
224
+
225
+
```js
226
+
import { createSignal } from"@dilane3/gx";
227
+
228
+
constcounterSignal=createSignal({
229
+
name:"counter",
230
+
state:0,
231
+
actions: {
232
+
increment: (state, payload) => {
233
+
return state + payload;
234
+
},
235
+
236
+
decrement: (state, payload) => {
237
+
return state - payload;
238
+
},
239
+
},
240
+
241
+
// Operations section
242
+
operations: {
243
+
isEven: (state) => {
244
+
return state %2===0;
245
+
},
246
+
},
247
+
});
248
+
249
+
exportdefaultcounterSignal;
250
+
```
251
+
252
+
Then, you can use it inside your component like follow.
0 commit comments