Skip to content

Commit 6af001f

Browse files
authored
Merge pull request #163 from ctoth/doc-cleanup
First pass of minor grammar cleanup for documentation
2 parents 222e366 + 0f7c82a commit 6af001f

File tree

4 files changed

+52
-52
lines changed

4 files changed

+52
-52
lines changed

docs/index/docs/01-getting-started.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ sidebar_label: Getting started
66

77
## Preface
88

9-
We know you will learn Hookstate library API very quickly without reading much (if any) of the documentation. The following will help you to get started in minutes:
9+
We know you will learn the Hookstate library API very quickly without reading much (if any) of the documentation. The following will help you get started in minutes:
1010

11-
* **Intuitive API**. Most of the things will be self-explanatory. More in depth description will be always there.
11+
* **Intuitive API**. Most things will be self-explanatory. More in depth description will always be there.
1212
* **Code samples** in each section are self-contained, complete and interactive. So, jump to the relevant section, copy-paste a sample to your app and extend it as needed.
13-
* **Intellisense by IDE.** If your project is in Typescript, you will benefit a lot as type inference of the API functions supports any complexity of data structures of your states. Of course, you can also use it from a plain javascript.
14-
* **Complete demo application**. There is a *Todo-list-like* complete [demo application](https://github.com/avkonst/hookstate/tree/master/docs/demos/todolist) built with Hookstate. It uses and demonstrates most of the core features of Hookstate. It gives an example how to organise your project. You may follow the example or use any other module-composition structure. Here it is running in `iframe`:
13+
* **Intellisense by IDE.** If your project is in Typescript, you will benefit a lot as type inference of the API functions supports any complexity of data structures of your states. Of course, you can also use it from plain javascript.
14+
* **Complete demo application**. There is a *Todo-list-like* complete [demo application](https://github.com/avkonst/hookstate/tree/master/docs/demos/todolist) built with Hookstate. It uses and demonstrates most of the core features of Hookstate. It gives an example of how to organise your project. You may follow the example or use any other module-composition structure. Here it is running in an `iframe`:
1515

1616
<iframe src="https://hookstate.js.org/demo-todolist" width="100%" height="700px"></iframe>
1717

@@ -29,18 +29,18 @@ Or:
2929
yarn add @hookstate/core
3030
```
3131

32-
Hookstate consists of the core package `@hookstate/core` and optional plugins `@hookstate/*`, which you may include when needed. We have got the goal to keep the core library as small as possible but still feature-rich to address most of problems in state management and provide with good foundation for plugins. Plugins extend the library and address more specific needs. You can also write your own plugins: it is easy and gives a lot of power.
32+
Hookstate consists of the core package `@hookstate/core` and optional plugins `@hookstate/*`, which you may include when needed. We have a goal of keeping the core library as small as possible but still feature-rich to address most of problems in state management and provide a good foundation for plugins. Plugins extend the library and address more specific needs. You can also write your own plugins: it is easy and gives a lot of power.
3333

3434
## Browser support
3535

36-
It supports all recent browsers and works where React works, including mobile applications and server side rendering.
36+
Hookstate supports all recent browsers and works where React works, including mobile applications and server side rendering.
3737

3838
### IE11 support
3939

40-
The library supports IE11 with a few exceptions for mutations of a nested state, which have got alternative working methods.
40+
The library supports IE11 with a few exceptions for mutations of nested state, which has alternative working methods.
4141
The [nested state](./nested-state) section notes these exceptions.
4242

43-
If you need to polyfill, for example for IE11, you need to make sure the following is supported by the target environment. You may checkout existing [IE11 demo project](https://github.com/avkonst/hookstate/tree/master/docs/demos/ie11).
44-
- ES5, `Map` and `Set` (All are available long time ago, including IE11)
43+
If you need to polyfill, for example for IE11, you need to make sure the following is supported by the target environment. You may checkout the existing [IE11 demo project](https://github.com/avkonst/hookstate/tree/master/docs/demos/ie11).
44+
- ES5, `Map` and `Set` (All are available a long time ago, including for IE11)
4545
- `Symbol` (You likely already have got one from the [`react-app-polyfill`](https://www.npmjs.com/package/react-app-polyfill). If you do not import [`react-app-polyfill`](https://www.npmjs.com/package/react-app-polyfill), you can get the standalone [`es6-symbol`](https://www.npmjs.com/package/es6-symbol))
4646
- `Number.isInteger` (Polyfill is available from [`core-js/features/number/is-integer`](https://www.npmjs.com/package/core-js))

docs/index/docs/03-local-state.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { PreviewSample } from '../src/PreviewSample'
1111
When a state is used by only one component, and maybe it's children,
1212
it is recommended to use *local* state instead of [*global* state](global-state).
1313
In this case [useState](typedoc-hookstate-core#usestate) behaves similarly to `React.useState`, but the
14-
returned instance of [State](typedoc-hookstate-core#state) has got more features.
14+
returned instance of [State](typedoc-hookstate-core#state) has more features.
1515

1616
<PreviewSample example="local-getting-started" />
1717

docs/index/docs/04-nested-state.md

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ sidebar_label: Nested state
66

77
import { PreviewSample } from '../src/PreviewSample'
88

9-
[Local state](./local-state) and [Global state](./global-state) sections show examples, where state data is a primitive value. Next, we will have a look into one of the most powerful features of the Hookstate - the interface to a nested state of a complex object state. The interface is the same for local and global states and works equally well for both cases.
9+
The [Local state](./local-state) and [Global state](./global-state) sections show examples where state data is a primitive value. Next, we will have a look into one of the most powerful features of Hookstate - the interface to a nested state of a complex object state. The interface is the same for local and global states and works equally well for both cases.
1010

1111
## Accessing and mutating nested state
1212

13-
Let's consider the following example where a state value is an array of objects. It demonstrates how to dive into nested state of the array and deep nested state of an element
13+
Let's consider the following example where a state value is an array of objects. It demonstrates how to dive into the nested state of the array and deeply-nested state of an element
1414
of the array. The state of an element is passed to a child component as a property. The child component gets and sets the deep nested state.
1515

1616
<PreviewSample example="local-complex-from-documentation" />
@@ -28,18 +28,18 @@ we append new element to the state of tasks, using `merge` method: `state.merge(
2828

2929
## `nested` state method
3030

31-
You may noticed, that a state object mixes properties from the state value object (eg. `name` property from
31+
You may have noticed that a state object mixes properties from the state value object (eg. `name` property from
3232
`taskState` state) and state methods (eg. `merge` property from [StateMethods](typedoc-hookstate-core#interfacesstatemethodsmd) interface). It is very likely that names of properties from your state objects will not collide with names of state methods.
3333
In other words, your objects are unlikely to have properties named, like `merge`, `set`, `get`, etc.
3434
Although, it is more likely your objects may have properties with names like `value` or `error`, which also
3535
exist in state methods.
3636

3737
If the collision happens for whatever property name, properties
3838
from state methods take priority and "hide" access to nested states via `.` syntax. However,
39-
there is a `nested` state method, which allows to access nested state by name. For example
39+
there is a `nested` state method, which allows accessing nested state by name. For example
4040
`taskState.nested("name")` would give access to the same nested state as `taskState.name` in the example above.
41-
So, if it ever happens
42-
your `state` object has got a property with name, for example `set`, which collides with the corresponding
41+
So, if it ever happens that
42+
your `state` object has got a property with the name, for example `set`, which collides with the corresponding
4343
state method, you would be able to obtain the nested state behind the `set` property using nested method: `state.nested("set")`.
4444

4545
It is also necessary to use `nested` method instead of property access by index syntax,
@@ -54,7 +54,7 @@ function NestedStateByName(props: { stateKey: string }) {
5454
}
5555
```
5656

57-
you are required to use `nested` method:
57+
you are required to use the `nested` method:
5858

5959
```tsx
6060
state.nested(props.stateKey).value
@@ -66,7 +66,7 @@ as the following would not be allowed by the typescript compiler:
6666
state[props.stateKey].value
6767
```
6868

69-
However, if your dynamic property name is from a set of names, which are known at compile time
69+
However, if your dynamic property name is from a set of names which are known at compile time
7070
and do not collide with state methods, you would be able to use property access by index syntax. For example:
7171

7272
```tsx
@@ -88,19 +88,19 @@ Below, you will find more about available methods for managing nested states.
8888

8989
### Setting new state value
9090

91-
Let's consider we have got the following state:
91+
Let's consider the following state:
9292

9393
```tsx
9494
const state = useState({ a: 1, b: 2 })
9595
```
9696

97-
One of the state methods is `set`, which is used to set new state value.
97+
One of the state methods is `set`, which is used to set the new state value.
9898

9999
```tsx
100100
state.set({ a: 2, b: 3 })
101101
```
102102

103-
New state value can be also a function, which returns new value taking the previous one:
103+
New state value can be also a function, which returns new value and accepts the previous one:
104104

105105
```tsx
106106
state.set(p => { a: p.a + 1, b: p.b - 1 })
@@ -110,7 +110,7 @@ Learn more about [StateMethods.set](typedoc-hookstate-core.md#set) in the API re
110110

111111
### Getting names of existing properties
112112

113-
Let's consider we have got the following state:
113+
Let's consider the following state:
114114

115115
```tsx
116116
const state = useState({ a: 1, b: 2 })
@@ -132,41 +132,41 @@ For a given state:
132132
const state = useState({ a: 1, b: 2 })
133133
```
134134

135-
The most efficient and recommended methods to update nested property are the following:
135+
The most efficient and recommended methods to update a nested property are the following:
136136
```tsx
137137
state.a.set(p => p + 1) // increments value of property a
138138
// or
139139
state['a'].set(p => p + 1)
140140
// or
141141
state.merge(p => ({ a: p.a + 1 }))
142142
```
143-
It sets only property `a`, so it will rerender every component where property `a` is used.
143+
These set only property `a`, so it will rerender every component where property `a` is used.
144144

145145
#### Avoid the following:
146146

147-
There are alternative less efficient methods, but resulting in the same mutation and data state. The following sets the entire object state to the new value (although, only `a` property is changed), so it will rerender every component where **any** property of the state is used.
147+
There are alternative, less efficient methods, resulting in the same mutation and data state. The following sets the entire object state to the new value (although only `a` property is changed), so it will rerender every component where **any** property of the state is used.
148148

149149
```tsx
150150
state.set(p => ({ ...p, a: p.a + 1 }))
151151
```
152152

153-
The following sets only property `a` but uses the current property value via the [StateMethods.value](typedoc-hookstate-core.md#readonly-value), which marks the property `a` as used by a component even if it was not used during the last rendering. In other words using nested property state in rendering or in action dispatch
154-
has got the same effect: a component is rerendered on property update.
153+
The following sets only the property `a` but uses the current property value via the [StateMethods.value](typedoc-hookstate-core.md#readonly-value), which marks the property `a` as used by a component even if it was not used during the last rendering. In other words using nested property state in rendering or in action dispatch
154+
has the same effect: a component is rerendered on property update.
155155
```tsx
156156
state['a'].set(state.a.value + 1) // increments value of property a
157157
```
158158

159159
Learn more about [StateMethods.set](typedoc-hookstate-core.md#set) and [StateMethods.merge](typedoc-hookstate-core.md#merge) in the API reference.
160160

161-
### Adding new property
161+
### Adding a new property
162162

163163
For a given state:
164164

165165
```tsx
166166
const state = useState<{ a: number, b?: number }>({ a: 1 }) // notice b property is optional
167167
```
168168

169-
The recommended methods to add new nested property are the following:
169+
The recommended methods to add a new nested property are the following:
170170
```tsx
171171
state.b.set(2)
172172
// or
@@ -178,10 +178,10 @@ state.merge({ b: 2 })
178178
Notice the `state` object has got **any** property defined (it is not the case in IE11),
179179
although not every property might pass Typescript compiler check.
180180
We accessed non existing property `b` and set it's state.
181-
It represents the fact the state of `undefined` property is actually defined state object,
181+
It represents the fact the state of `undefined` property is actually a defined state object,
182182
which can be used to set `undefined` property to a new value.
183183

184-
It allows to add new properties to the state using the same method as for updating a property.
184+
It allows to add new properties to the state using the same method as is used for updating a property.
185185

186186
#### Avoid the following
187187

@@ -195,7 +195,7 @@ But this is the only available method for IE11.
195195

196196
Learn more about [StateMethods.set](typedoc-hookstate-core.md#set) and [StateMethods.merge](typedoc-hookstate-core.md#merge) in the API reference.
197197

198-
### Deleting existing property
198+
### Deleting an existing property
199199

200200
For a given state:
201201

@@ -257,7 +257,7 @@ Learn more about [StateMethods.set](typedoc-hookstate-core.md#set) and [StateMet
257257

258258
### Partial updates and deletions
259259

260-
You may noticed the usage of [StateMethods.merge](typedoc-hookstate-core.md#merge) above. This does partial update to the state and can insert, update and delete properties all in one call:
260+
You may have noticed the usage of [StateMethods.merge](typedoc-hookstate-core.md#merge) above. This does a partial update to the state and can insert, update and delete properties all in one call:
261261

262262
```tsx
263263
const state = useState<Record<string, number>>({
@@ -275,9 +275,9 @@ Learn more about [StateMethods.set](typedoc-hookstate-core.md#set) and [StateMet
275275

276276
## Advanced mutations for an array state
277277

278-
### Setting new state value
278+
### Setting a new state value
279279

280-
Let's consider we have got the following state:
280+
Let's consider the following state:
281281

282282
```tsx
283283
const state = useState([1, 2])
@@ -299,7 +299,7 @@ Learn more about [StateMethods.set](typedoc-hookstate-core.md#set) in the API re
299299

300300
### Getting indexes of existing elements
301301

302-
Let's consider we have got the following state:
302+
Let's consider the following state:
303303

304304
```tsx
305305
const state = useState([1, 2])
@@ -321,7 +321,7 @@ For a given state:
321321
const state = useState([1, 2])
322322
```
323323

324-
The most efficient and recommended methods to update nested element are the following:
324+
The most efficient and recommended methods to update a nested element are the following:
325325
```tsx
326326
state[0].set(p => p + 1) // increments value of an element at 0 position
327327
// or
@@ -331,7 +331,7 @@ It sets only element at `0`, so it will rerender every component where this elem
331331

332332
#### Avoid the following:
333333

334-
There are alternative less efficient methods, but resulting in the same mutation and data state. The following sets the entire array state to the new value (although, only `0` index is changed), so it will rerender every component where **any** property of the state is used.
334+
There are alternative less efficient methods resulting in the same mutation and data state. The following sets the entire array state to the new value (although, only `0` index is changed), so it will rerender every component where **any** property of the state is used.
335335

336336
```tsx
337337
state.set(p => ([p[0] + 1].concat(p.slice(1))))
@@ -346,9 +346,9 @@ state[0].set(state[0].value + 1) // increments value of an element at 0
346346

347347
Learn more about [StateMethods.set](typedoc-hookstate-core.md#set) and [StateMethods.merge](typedoc-hookstate-core.md#merge) in the API reference.
348348

349-
### Appending new element
349+
### Appending a new element
350350

351-
For a given state:
351+
To a given state:
352352

353353
```tsx
354354
const state = useState([1000])
@@ -372,13 +372,13 @@ as it can be potentially less efficient than the above recommended methods:
372372
state.set(p => p.concat([2000]))
373373
```
374374

375-
But this is the only method available for IE11 environment.
375+
But this is the only method available for IE11.
376376

377377
Learn more about [StateMethods.set](typedoc-hookstate-core.md#set) and [StateMethods.merge](typedoc-hookstate-core.md#merge) in the API reference.
378378

379-
### Deleting existing element
379+
### Deleting an existing element
380380

381-
For a given state:
381+
From a given state:
382382

383383
```tsx
384384
const state = useState([1000, 2000, 3000])
@@ -451,7 +451,7 @@ Learn more about [StateMethods.set](typedoc-hookstate-core.md#set) and [StateMet
451451

452452
### Splicing elements
453453

454-
Use `Array.prototype.splice` function to remove, replace or delete elements. In particular, this can be used to prepend new elements to an array value:
454+
Use the `Array.prototype.splice` function to remove, replace or delete elements. In particular, this can be used to prepend new elements to an array value:
455455

456456
```tsx
457457
const state = useState([3000, 4000])
@@ -463,7 +463,7 @@ state.set(p => {
463463

464464
### Partial updates and deletions
465465

466-
You may noticed the usage of [StateMethods.merge](typedoc-hookstate-core.md#merge) above. This does partial update to the state and can insert, update and delete array elements all in one call:
466+
You may have noticed the usage of [StateMethods.merge](typedoc-hookstate-core.md#merge) above. This does a partial update to the state and can insert, update and delete array elements all in one call:
467467

468468
```tsx
469469
const state = useStateLink([1000, 2000, 3000])
@@ -497,7 +497,7 @@ Learn more about [StateMethods.set](typedoc-hookstate-core.md#set) and [StateMet
497497

498498
## Limitations for state values
499499

500-
There are few limitations for state values, which are typical for any state management library for Javascript environment.
500+
There are a few limitations for state values, which are typical for any state management library for Javascript environment.
501501

502-
* State value should be a JS primitive, like string/number/etc., or `null`/`undefined` or a JS object/array containing other JS primitive properties, objects or arrays. In other words, state values with Maps, Sets, Dates will not work properly.
503-
* Cyclic and cross-referrences with the state value will not work properly.
502+
* A state value should be a JS primitive, like string/number/etc., or `null`/`undefined` or a JS object/array containing other JS primitive properties, objects or arrays. In other words, state values with Maps, Sets, Dates will not work properly.
503+
* Cyclic and cross-references with the state value will not work properly.

0 commit comments

Comments
 (0)