Skip to content
This repository was archived by the owner on May 20, 2022. It is now read-only.

Commit c374921

Browse files
committed
improving jsdoc
1 parent 7419122 commit c374921

File tree

2 files changed

+5
-21
lines changed

2 files changed

+5
-21
lines changed

example/basic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const defaultStyles = {
88
const mapStateToProps = (state) => state.number;
99

1010
// Creating a nameless store, do that if you do not wish to have multiple stores in your app
11-
createStore('clickCounter', { number: 0 }, (state, number) => {
11+
const store = createStore('clickCounter', { number: 0 }, (state, number) => {
1212
return { number }
1313
});
1414

src/index.js

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,9 @@ class StoreInterface {
1818

1919
/**
2020
* Subscribe to store changes
21-
* @callback callback - The function to be invoked everytime the store is updated
21+
* @param {(state:any, action:any) => void} callback - The function to be invoked everytime the store is updated
2222
* @return {Function} - Call the function returned by the method to cancel the subscription
2323
*/
24-
25-
/**
26-
*
27-
* @param {callback} state, action
28-
*/
2924
subscribe(callback) {
3025
if (!callback || typeof callback !== 'function') {
3126
throw `store.subscribe callback argument must be a function. got '${typeof callback}' instead.`;
@@ -58,14 +53,9 @@ function getStoreByIdentifier(identifier) {
5853
* Creates a new store
5954
* @param {String} name - The store namespace.
6055
* @param {*} state [{}] - The store initial state. It can be of any type.
61-
* @callback reducer [null]
56+
* @param {(state:any, action:any) => any} reducer [null] - The reducer handler. Optional
6257
* @returns {StoreInterface} The store instance.
6358
*/
64-
65-
/**
66-
*
67-
* @param {reducer} prevState, action - The reducer handler. Optional.
68-
*/
6959
export function createStore(name, state = {}, reducer=defaultReducer) {
7060
if (typeof name !== 'string') {
7161
throw 'store name must be a string';
@@ -123,10 +113,9 @@ export function createStore(name, state = {}, reducer=defaultReducer) {
123113

124114
/**
125115
* Returns a store instance based on its name
126-
* @callback {String} name - The name of the wanted store
116+
* @name {String} name - The name of the wanted store
127117
* @returns {StoreInterface} the store instance
128118
*/
129-
130119
export function getStoreByName(name) {
131120
try {
132121
return stores[name].public;
@@ -138,14 +127,9 @@ export function getStoreByName(name) {
138127
/**
139128
* Returns a [ state, setState ] pair for the selected store. Can only be called within React Components
140129
* @param {String|StoreInterface} identifier - The identifier for the wanted store
141-
* @callback memoFn [state => state] - A memoization function to optimize component rerender. Receive the store state and return a subset of it. The component will only rerender when the subset changes.
130+
* @param {(state:any) => any} memoFn [state => state] - A memoization function to optimize component rerender. Receive the store state and return a subset of it. The component will only rerender when the subset changes.
142131
* @returns {Array} the [state, setState] pair.
143132
*/
144-
145-
/**
146-
*
147-
* @param {memoFn} state
148-
*/
149133
export function useStore(identifier, memoFn=defaultMemoFn) {
150134
const store = getStoreByIdentifier(identifier);
151135
if (!store) {

0 commit comments

Comments
 (0)