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
In addition to the boilerplate reduction, `easyComp` comes with a bunch of additional benefits that may not be obvious at first glance.
84
84
85
-
- The state becomes a simple object, which updates synchronously. You don't have to worry about immutable state updates or the asynchronous nature of `setState`. If you are not sure about the meaning of this check out [this article](https://medium.freecodecamp.org/functional-setstate-is-the-future-of-react-374f30401b6b) about `setState`.
85
+
- The store is simple object. You don't have to worry about immutable state updates or the asynchronous nature of `setState`. If you are not sure about the meaning of this check out [this article](https://medium.freecodecamp.org/functional-setstate-is-the-future-of-react-374f30401b6b) about `setState`.
86
86
87
-
- The render method is only triggered if it is affected by the state mutations. If it doesn't use the mutated part of the state or the mutation doesn't change the state, the render method is not triggered.
87
+
- The render method is only triggered if it is affected by store mutations. If it doesn't use the mutated part of the store or the mutation doesn't change the store, the render method is not triggered.
88
88
89
89
- The render method is never executed immediately. Triggered renders are collected and executed asynchronously in one batch.
90
90
91
91
- Renders always run before the next repaint.
92
92
93
93
- Duplicates renders are removed. A render never runs twice in one batch - no matter how many times it got triggered.
94
94
95
-
- Renders may trigger others renders by mutating the state. In this case loops are automatically resolved.
95
+
- Renders may trigger others renders by mutating the store. In this case loops are automatically resolved.
96
96
97
97
- Easy State implements an optimal `shouldComponentUpdate` for your components.
98
98
99
-
As a result the state is always fresh and a stable and a fresh view is always achieved before the next repaint with the minimal number of required renders.
99
+
As a result the store is always fresh and a stable and a fresh view is always achieved before the next repaint with the minimal number of required renders.
100
100
101
101
### easyStore
102
102
103
-
`easyStore` creates global state stores, to handle data that do not fit into component state. Wrapping an object with `easyStore` has to following effects.
103
+
`easyStore` creates global state stores, to handle data that does not fit into component stores. Wrapping an object with `easyStore` has to following effects.
104
104
105
-
- It transforms the object into a reactive data store, which triggers appropriate renders on mutations.
105
+
- It transforms the object into a reactive data store, which triggers appropriate renders on mutations. This store is just a simple object.
106
106
107
-
- It binds your object's methods to the object.
107
+
- It binds your store's methods to the store.
108
108
109
109
```js
110
110
importReactfrom'react'
@@ -135,7 +135,7 @@ function Hello () {
135
135
exportdefaulteasyComp(Hello)
136
136
```
137
137
138
-
**Make sure to wrap your component with `easyComp` even if it uses global stores only and no local state.**
138
+
**Make sure to wrap your component with `easyComp` even if it uses global stores only and no local stores.**
139
139
140
140
- Global stores are simple objects and there is no limitation on what you can do with them. As an example feel free to use expando properties, arrays, deeply nested objects, ES6 collections or getters/setters in your stores.
141
141
@@ -178,11 +178,11 @@ The list of benchmarks will expand in the future.
178
178
179
179
## State management overview
180
180
181
-
Finding the right balance between local component state and global state stores is not always a trivial task. This section gives you some general guide lines when to use which.
181
+
Finding the right balance between local component stores and global state stores is not always a trivial task. This section gives you some general guide lines when to use which.
182
182
183
183
### Reusable widgets
184
184
185
-
This is an easy decision. Always use local component state for reusable components. Depending on global stores would interfere with their reusability and break them. Check out the introductory [clock example](/examples/clock/) for some code.
185
+
This is an easy decision. Always use local component stores for reusable components. Depending on global stores would interfere with their reusability and break them. Check out the introductory [clock example](/examples/clock/) for some code.
186
186
187
187
### Application state
188
188
@@ -192,9 +192,9 @@ Application state should usually be managed in global stores. It is singleton an
192
192
193
193
- User inputs, which should go into the URL or change the browser history are also great examples. These are inherently global because they affect global concepts - like the URL and browser history. Some example for these are filters, date ranges and sorting primitives.
194
194
195
-
Not everything fits in global stores though. You can find a few cases below when using the local component state makes more sense then global stores.
195
+
Not everything fits in global stores though. You can find a few cases below when using the local component store makes more sense then global stores.
196
196
197
-
- Utility and meta data should go into component state. For example you may have a component which handles recent history for an input field. It may make sense to receive the data for the input from a global store and manage the history meta data in the local state. Check out the [contacts table example](/examples/contacts/) for some code.
197
+
- Utility and meta data should go into component stores. For example you may have a component which handles recent history for an input field. It may make sense to receive the data for the input from a global store and manage the history meta data in the local store. Check out the [contacts table example](/examples/contacts/) for some code.
0 commit comments