Skip to content

Commit 6166b27

Browse files
author
Matheus Marsiglio
committed
docs(Update & Dispatch): functions signatures
Add function signature documentation for update and dispatch functions
1 parent 3d3ea60 commit 6166b27

File tree

2 files changed

+84
-6
lines changed

2 files changed

+84
-6
lines changed

API_DOCUMENTATION.md

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- [Usage](#nucleonumberassertion-usage)
2020
- [Creating the store](#creating-the-store)
2121
- [Dispatching and updating the store](#dispatching-and-updating-the-store)
22+
- [Update and Dispatch function signature](#Update-and-Dispatch-function-signature)
2223
- [Get contracts in store](#get-contracts-in-store)
2324
- [Subscribing to changes](#subscribing-to-changes)
2425
- [Error management](#error-management)
@@ -428,14 +429,53 @@ console.log(user);
428429
data: {
429430
name: {
430431
firstName: 'Robert',
431-
lastName: 'Nor'
432432
},
433-
age: 27
434433
},
435434
}
435+
436+
It'll return the data you asked to save. To receive the new store, you will have to clone this state or subscribe to Nucleo changes through subscribe function
437+
Check documentation for cloneState in the next section
438+
*/
439+
const newUser = cloneState('user');
440+
console.log(newUser);
441+
/*
442+
{
443+
name: {
444+
firstName: 'Robert',
445+
lastName: 'Nor',
446+
},
447+
age: 27,
448+
}
436449
*/
437450
```
438451

452+
#### Update and Dispatch function signature
453+
454+
`update` and `dispatch` functions have the same signature albeit a discrete behavioral difference (you can find this difference in .
455+
456+
**Both are curried functions:**
457+
458+
- `update(<contract_name>)(<data_to_save_in_contract>)`;
459+
- `dispatch(<contract_name>)(<data_to_save_in_contract>)`.
460+
461+
`<contract_name>`: a `string` for the contract name you want to update or dispatch. It's the `name` field for every new `NucleoObject` in the contracts definition. Those must be unique. You can find more information about contracts in API_DOCUMENTATION.md.
462+
463+
`<data_to_save_in_contract>`: must follow its contract model. For understanding how to use `update` and `dispatch` for saving data, check API_DOCUMENTATION.md in "Dispatching and updating the store" section.
464+
465+
**Both return the same object interface:**
466+
467+
```javascript
468+
{
469+
status: 'OK' | 'NOK', // a string return 'OK' for success cases and 'NOK' for errors
470+
errors: [], // in case of errors, it will return the list of errors
471+
data: { ... } // the data you just tried to save in store
472+
}
473+
```
474+
475+
- `status`: a string return 'OK' for success cases and 'NOK' for errors;
476+
- `errors`: a list of objects containing the errors in this operation. Usually related to contract violations. You can find more details in API_DOCUMENTATION.md at "Error management" area.
477+
- `data`: This is the exactly same object you tried to save at store for comparison reasons in cases of errors.
478+
439479
## Getting a state clone from store
440480

441481
The `cloneState` function receives one argument which is the contract name in store, performs a deep clone using the contracts data model as a map to predict the key/values of that contract and be able to return it with great performance.

README.md

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
Nucleo creates and manages a strongly typed and predictable state container.
44

5-
> Important note: This project is still under development. It's not recommended for production use yet, despite its basic functionalities are checked as done.
6-
5+
> Important note: This project is still under development. It's not recommended for production use yet, despite its basic functionalities are checked as done.
76
## Roadmap
87

98
It's in this project milestones https://github.com/mtmr0x/nucleo/milestones;
@@ -171,14 +170,53 @@ console.log(user);
171170
data: {
172171
name: {
173172
firstName: 'Robert',
174-
lastName: 'Nor'
175173
},
176-
age: 27
177174
},
178175
}
176+
177+
It'll return the data you asked to save. To receive the new store, you will have to clone this state or subscribe to Nucleo changes through subscribe function
178+
Check documentation for cloneState in the next section
179+
*/
180+
const newUser = cloneState('user');
181+
console.log(newUser);
182+
/*
183+
{
184+
name: {
185+
firstName: 'Robert',
186+
lastName: 'Nor',
187+
},
188+
age: 27,
189+
}
179190
*/
180191
```
181192

193+
#### Update and Dispatch function signature
194+
195+
`update` and `dispatch` functions have the same signature albeit a discrete behavioral difference (you can find this difference in .
196+
197+
**Both are curried functions:**
198+
199+
- `update(<contract_name>)(<data_to_save_in_contract>)`;
200+
- `dispatch(<contract_name>)(<data_to_save_in_contract>)`.
201+
202+
`<contract_name>`: a `string` for the contract name you want to update or dispatch. It's the `name` field for every new `NucleoObject` in the contracts definition. Those must be unique. You can find more information about contracts in API_DOCUMENTATION.md.
203+
204+
`<data_to_save_in_contract>`: must follow its contract model. For understanding how to use `update` and `dispatch` for saving data, check API_DOCUMENTATION.md in "Dispatching and updating the store" section.
205+
206+
**Both return the same object interface:**
207+
208+
```javascript
209+
{
210+
status: 'OK' | 'NOK', // a string return 'OK' for success cases and 'NOK' for errors
211+
errors: [], // in case of errors, it will return the list of errors
212+
data: { ... } // the data you just tried to save in store
213+
}
214+
```
215+
216+
- `status`: a string return 'OK' for success cases and 'NOK' for errors;
217+
- `errors`: a list of objects containing the errors in this operation. Usually related to contract violations. You can find more details in API_DOCUMENTATION.md at "Error management" area.
218+
- `data`: This is the exactly same object you tried to save at store for comparison reasons in cases of errors.
219+
182220
### Getting a state clone from store
183221

184222
The `cloneState` function receives one argument which is the contract name in store, performs a deep clone using the contracts data model as a map to predict the key/values of that contract and be able to return it with great performance.

0 commit comments

Comments
 (0)