-
Notifications
You must be signed in to change notification settings - Fork 0
Add types via JSDoc #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
chawes13
wants to merge
1
commit into
master
Choose a base branch
from
spike/add-types-via-jsdoc
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export selectorForSlice from './selectorForSlice' | ||
export setState from './setState' | ||
export unsetState from './unsetState' | ||
export { default as selectorForSlice } from './selectorForSlice' | ||
export { default as setState } from './setState' | ||
export { default as unsetState } from './unsetState' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,20 +3,20 @@ import { set, get } from 'lodash/fp' | |
|
||
/** | ||
* | ||
* A helper function for creating simple "setter" reducers. | ||
* A helper function for creating simple "setter" reducers. | ||
* Given a path, it sets the state at that path to the payload of an action. | ||
* | ||
* @name setState | ||
* @type Function | ||
* @param {String} path - Path to the part of the state that will be set | ||
* @param {Function} transform - A function with arguments `(action, state, slice)` that can be used to transform the value that will be set. `slice` is the data, if any, that already exists in the state at `path`. The default transform function simply returns the action's payload. To set the state to a constant value, simply pass the value in place of the transform function. | ||
* @returns {Function} - A function that can be used in a reducer to handle an action. | ||
* @type {Function} | ||
* @param {string} path - Path to the part of the state that will be set | ||
* @param {StateTransform} [transform=] - A function with arguments `(action, state, slice)` that can be used to transform the value that will be set. `slice` is the data, if any, that already exists in the state at `path`. The default transform function simply returns the action's payload. To set the state to a constant value, simply pass the value in place of the transform function. | ||
* @returns {(state:any, action:Action) => any } A function that can be used in a reducer to handle an action. | ||
* | ||
* @example | ||
* | ||
* import { setState } from 'lp-redux-utils' | ||
* import { createAction, handleActions } from 'redux-actions' | ||
* | ||
* | ||
* const setCount = createAction('SET_COUNT') | ||
* const setCountInverse = createAction('SET_COUNT_INVERSE') | ||
* const doubleExistingCount = createAction('DOUBLE_EXISTING_COUNT') | ||
|
@@ -28,12 +28,7 @@ import { set, get } from 'lodash/fp' | |
* [resetCount]: setState('count', 0) | ||
* }) | ||
* | ||
**/ | ||
|
||
function defaultTransform (action) { | ||
return get('payload', action) | ||
} | ||
|
||
*/ | ||
function setState (path, transform=defaultTransform) { | ||
return function reducer (state, action) { | ||
const slice = get(path, state) | ||
|
@@ -42,4 +37,24 @@ function setState (path, transform=defaultTransform) { | |
} | ||
} | ||
|
||
function defaultTransform (action) { | ||
return get('payload', action) | ||
} | ||
|
||
/** | ||
* @ignore | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
* @callback StateTransform | ||
* @param {Action} action - The action dispatched to the store | ||
* @param {any} state - The current Redux store state | ||
* @param {any} slice - The data, if any, that already exists in the state at `path` | ||
* @returns {any} The value to set in the path | ||
*/ | ||
|
||
/** | ||
* @ignore | ||
* @typedef Action | ||
* @property {string} type - The action type | ||
* @property {any=} payload - Additional data provided with the action | ||
*/ | ||
|
||
export default setState |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"include": ["src"], | ||
"exclude": ["lib", "node_modules"], | ||
"compilerOptions": { | ||
"declaration": true, | ||
"emitDeclarationOnly": true, | ||
"allowJs": true, | ||
"outDir": "lib/types", | ||
"declarationMap": true, | ||
"skipLibCheck": true | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand the difference between using a
@callback
tag vs a@typedef
. Are both valid options forSliceSelector
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typdef doesn't work for functions 😭 .
Refer to https://github.com/LaunchPadLab/client-template/pull/436 for more details. It's a little over my head 😆 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. I just re-read the docs.
I thought they were using
@typedef
to type functions, but it was actually the function params being typed with@typedef
. Functions should use@callback
.