Skip to content

Commit c323af8

Browse files
committed
Updated comments.
1 parent 9c5cc53 commit c323af8

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,13 @@ sharedState.useState()
3939
`useSharedState` and `sharedState.useState` are the same one.
4040

4141
### setSharedState(state)
42+
Assign a new stateful value.
4243
#### Parameter `state`
4344
Type: `any`
4445
Required: `required`
45-
Assign a new state.
4646

4747
### useSharedState(path, initialState)
48+
Returns a stateful value, and a function to update it.
4849
#### Parameter `path`
4950
Type: `string`
5051
Required: `optional`

lib/shared-state.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ module.exports = class SharedState {
1111
}
1212

1313
setState(value) {
14+
/*
15+
Assign a new stateful value.
16+
@param value {any}
17+
*/
1418
this.state = value;
1519
this.setters.forEach(setter => {
1620
if (setter.path) {
@@ -22,6 +26,11 @@ module.exports = class SharedState {
2226
}
2327

2428
generateSetState(path) {
29+
/*
30+
Generate a function to set state.
31+
@param path {String|null}
32+
@returns {Function (value) => {}}
33+
*/
2534
return value => {
2635
if (path) {
2736
if (this.state === undefined) {
@@ -41,8 +50,8 @@ module.exports = class SharedState {
4150
setter.set(this.state);
4251
}
4352
});
44-
} else {
45-
// This set is for state root.
53+
} else { // Path is empty or null.
54+
// This setter is for state root.
4655
this.state = value;
4756
// Call all setters because the root was updated.
4857
this.setters.forEach(setter => {
@@ -58,9 +67,10 @@ module.exports = class SharedState {
5867

5968
useState(path, initialState) {
6069
/*
70+
Returns a stateful value, and a function to update it.
6171
@param path {String|null} The object path.
6272
@param initialState {any}
63-
@returns {Array<[{state: any}, {setState: function}]>}
73+
@returns {Array<[{state: any}, {setState: Function}]>}
6474
*/
6575
path = path == null ? '' : `${path}`;
6676
let sharedState = objectPath.get(this.state, path);

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
"url": "https://github.com/kelp404/react-hooks-shared-state/issues"
2020
},
2121
"homepage": "https://github.com/kelp404/react-hooks-shared-state#readme",
22+
"keywords": [
23+
"react",
24+
"react-hooks",
25+
"global-state"
26+
],
2227
"dependencies": {
2328
"object-path": "0.11.4",
2429
"react": "16.8.6"

0 commit comments

Comments
 (0)