-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
chore(mapDispatchToProps): port to typescript #1760
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
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,28 @@ | ||
import { ActionCreator, ActionCreatorsMapObject, Dispatch } from 'redux' | ||
import bindActionCreators from '../utils/bindActionCreators' | ||
import { wrapMapToPropsConstant, wrapMapToPropsFunc } from './wrapMapToProps' | ||
|
||
export function whenMapDispatchToPropsIsFunction(mapDispatchToProps) { | ||
export function whenMapDispatchToPropsIsFunction( | ||
mapDispatchToProps: ActionCreatorsMapObject | ActionCreator<any> | ||
) { | ||
return typeof mapDispatchToProps === 'function' | ||
? wrapMapToPropsFunc(mapDispatchToProps, 'mapDispatchToProps') | ||
: undefined | ||
} | ||
|
||
export function whenMapDispatchToPropsIsMissing(mapDispatchToProps) { | ||
export function whenMapDispatchToPropsIsMissing( | ||
mapDispatchToProps: ActionCreatorsMapObject | ActionCreator<any> | ||
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. ✋ Here, it's probably just 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. Shoul I let the |
||
) { | ||
return !mapDispatchToProps | ||
? wrapMapToPropsConstant((dispatch) => ({ dispatch })) | ||
: undefined | ||
} | ||
|
||
export function whenMapDispatchToPropsIsObject(mapDispatchToProps) { | ||
export function whenMapDispatchToPropsIsObject( | ||
mapDispatchToProps: ActionCreatorsMapObject | ActionCreator<any> | ||
tony-go marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) { | ||
return mapDispatchToProps && typeof mapDispatchToProps === 'object' | ||
? wrapMapToPropsConstant((dispatch) => | ||
? wrapMapToPropsConstant((dispatch: Dispatch) => | ||
bindActionCreators(mapDispatchToProps, dispatch) | ||
) | ||
: undefined | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { Dispatch } from 'redux' | ||
import { ActionCreatorsMapObject, Dispatch, ActionCreator } from 'redux' | ||
|
||
import { FixTypeLater } from '../types' | ||
import verifyPlainObject from '../utils/verifyPlainObject' | ||
|
@@ -20,7 +20,13 @@ export function wrapMapToPropsConstant( | |
// could be a dispatch function in some cases (ex: whenMapDispatchToPropsIsMissing) | ||
// and a state object in some others (ex: whenMapStateToPropsIsMissing) | ||
// eslint-disable-next-line no-unused-vars | ||
getConstant: (dispatch: Dispatch) => { dispatch?: Dispatch } | ||
getConstant: (dispatch: Dispatch) => | ||
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. ✋ This should probably be reworked to be more generic and flexible - maybe like:
In other words, whatever you pass in, it returns a function that returns that thing. 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. It doesn't match with the usage of wrapMapToPropsConstant((dispatch: Dispatch) => ({
dispatch,
})) 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. Good point, it's not just a passthrough |
||
| { | ||
dispatch?: Dispatch | ||
dependsOnOwnProps?: boolean | ||
} | ||
| ActionCreatorsMapObject | ||
| ActionCreator<any> | ||
) { | ||
return function initConstantSelector(dispatch: Dispatch) { | ||
const constant = getConstant(dispatch) | ||
|
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.
✋ It won't ever be a single action creator. It's either an object with action creators inside, a function that accepts
dispatch
and returns the bound action creators object, or nothing.You might be able to use the types I pasted into
selectorFactory.ts
in this file.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 put a
FixTypeLater
, I'll try to crack it today.