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
- add update spec file
- improve update method to do not try to update when state is not dispatched yet
- add script for single tests run and all tests
- fix bugs in NucleoList dispatch
- change version in package.json
- improve README documentation
- Add commented functionality for custom primitive types
- finish and polish update functionality
- Add licence file
- Fixes in README documentation
- Create index file with all Nucleo library methods
// it'll update only the user first name and only if this item has been already created in the store before
100
100
```
101
101
@@ -115,9 +115,7 @@ listener({ contractName }); // This way you can understand better what was updat
115
115
116
116
## Error management
117
117
118
-
Considering Nucleo is strongly typed and is designed to run in a client side environment, errors might be tricky to handle in how your user is inputting data and Nucleo is also designed to make sure your rules will work out and your user can make mistakes.
119
-
120
-
`dispatch` and `update` methods return an object containing the following structure:
118
+
Nucleo makes error management easy by type checking every level of contracts and returning an Object human and machine readable. The `update` and `dispatch` methods return an object with the following structure:
121
119
122
120
```javascript
123
121
{
@@ -133,29 +131,30 @@ Considering Nucleo is strongly typed and is designed to run in a client side env
133
131
}
134
132
```
135
133
136
-
Let's go deep into an example using a Nucleo custom primitive type with an inferred rule:
134
+
Code example:
137
135
138
136
```javascript
139
137
import {
140
138
NucleoString,
141
139
NucleoObject
142
140
} from'nucleo-js';
143
141
144
-
constageRule= (value) => {
145
-
return value <100; // you defined here that age can not be higher than 100
146
-
}
147
-
148
142
constuserType=newNucleoObject({
149
143
name:'user',
150
144
fields: {
151
-
name:NucleoString(),
152
-
age:NucleoString(ageRule)
145
+
name: NucleoString,
153
146
}
154
147
});
155
148
156
-
constdispatcher=update('user', { age:140 });
149
+
constcontracts= {
150
+
user: userType
151
+
};
152
+
153
+
const { update } =createStore(contracts); // send contracts to create the store
154
+
155
+
constuser=update('user')({ age:140 });
157
156
158
-
console.log(dispatcher.error); // here you'll find the error below:
157
+
console.log(user.errors); // here you'll find the error below:
`Fata error: In dispatch, the dispatched data and the contract must match in every level. For changing just few values from ${contractName} contract, use update() method.`
70
+
`Fatal error: In dispatch, the dispatched data and the contract must match in every level. For changing just few values from ${contractName} contract, use update() method.`
30
71
);
31
72
}
32
73
33
-
// loop checking object values comparison
74
+
// loop object values comparison
34
75
for(leti=0;dataKeys.length>i;i++){
35
76
constcurrentDataKey=data[dataKeys[i]];
36
-
// recursion to call itself when is NucleoObject instance
0 commit comments