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

Commit 26e07a0

Browse files
committed
improving jsdoc
1 parent c2af89a commit 26e07a0

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.`;
@@ -61,14 +56,9 @@ function getStoreByIdentifier(identifier) {
6156
* Creates a new store
6257
* @param {String} name - The store namespace.
6358
* @param {*} state [{}] - The store initial state. It can be of any type.
64-
* @callback reducer [null]
59+
* @param {(state:any, action:any) => any} reducer [null] - The reducer handler. Optional
6560
* @returns {StoreInterface} The store instance.
6661
*/
67-
68-
/**
69-
*
70-
* @param {reducer} prevState, action - The reducer handler. Optional.
71-
*/
7262
export function createStore(name, state = {}, reducer=defaultReducer) {
7363
if (typeof name !== 'string') {
7464
throw 'Store name must be a string';
@@ -126,10 +116,9 @@ export function createStore(name, state = {}, reducer=defaultReducer) {
126116

127117
/**
128118
* Returns a store instance based on its name
129-
* @callback {String} name - The name of the wanted store
119+
* @name {String} name - The name of the wanted store
130120
* @returns {StoreInterface} the store instance
131121
*/
132-
133122
export function getStoreByName(name) {
134123
try {
135124
return stores[name].public;
@@ -141,14 +130,9 @@ export function getStoreByName(name) {
141130
/**
142131
* Returns a [ state, setState ] pair for the selected store. Can only be called within React Components
143132
* @param {String|StoreInterface} identifier - The identifier for the wanted store
144-
* @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.
133+
* @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.
145134
* @returns {Array} the [state, setState] pair.
146135
*/
147-
148-
/**
149-
*
150-
* @param {memoFn} state
151-
*/
152136
export function useStore(identifier, memoFn=defaultMemoFn) {
153137
const store = getStoreByIdentifier(identifier);
154138
if (!store) {

0 commit comments

Comments
 (0)