@@ -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 ) ;
0 commit comments