|
19 | 19 | - [Usage](#nucleonumberassertion-usage) |
20 | 20 | - [Creating the store](#creating-the-store) |
21 | 21 | - [Dispatching and updating the store](#dispatching-and-updating-the-store) |
| 22 | +- [Update and Dispatch function signature](#Update-and-Dispatch-function-signature) |
22 | 23 | - [Get contracts in store](#get-contracts-in-store) |
23 | 24 | - [Subscribing to changes](#subscribing-to-changes) |
24 | 25 | - [Error management](#error-management) |
@@ -428,14 +429,53 @@ console.log(user); |
428 | 429 | data: { |
429 | 430 | name: { |
430 | 431 | firstName: 'Robert', |
431 | | - lastName: 'Nor' |
432 | 432 | }, |
433 | | - age: 27 |
434 | 433 | }, |
435 | 434 | } |
| 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 | +} |
436 | 449 | */ |
437 | 450 | ``` |
438 | 451 |
|
| 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 | + |
439 | 479 | ## Getting a state clone from store |
440 | 480 |
|
441 | 481 | 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