Skip to content

Commit fda213c

Browse files
committed
#7094 adding the API code snippet back in
1 parent 2b21e37 commit fda213c

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

learn/blog/v10-deep-dive-state-provider.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,30 @@ it lives—and builds a precise dependency graph in real-time.
4444
The result is an API that is not only more powerful but also simpler and more intuitive, especially when it comes to
4545
changing state. The provider does what you would expect, automatically handling complex scenarios like deep merging.
4646

47+
Where the magic truly begins is in how you *change* that data. Thanks to the new deep, proxy-based reactivity system,
48+
you can modify state with plain JavaScript assignments. It's as simple as it gets:
49+
50+
```javascript readonly
51+
// Get the provider and change the data directly
52+
const provider = myComponent.getStateProvider();
53+
54+
// This one line is all it takes to trigger a reactive update.
55+
provider.data.user.firstname = 'Max';
56+
57+
// Does not overwrite the lastname
58+
provider.setData({user: {firstname: 'Robert'}})
59+
60+
// You can update multiple properties at once. Thanks to automatic batching,
61+
// this results in only a single UI update cycle.
62+
provider.setData({user: {firstname: 'John', lastname: 'Doe'}})
63+
64+
// Alternative Syntax:
65+
provider.setData({
66+
'user.firstname': 'John',
67+
'user.lastname' : 'Doe'
68+
});
69+
```
70+
4771
```javascript live-preview
4872
import Button from 'neo.mjs/src/button/Base.mjs';
4973
import Container from 'neo.mjs/src/container/Base.mjs';

0 commit comments

Comments
 (0)