-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Converts a few hooks & helpers to Typescript (#1743)
- Loading branch information
Showing
12 changed files
with
33 additions
and
18 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
This file contains 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 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,12 +1,12 @@ | ||
// Default to a dummy "batch" implementation that just runs the callback | ||
function defaultNoopBatch(callback) { | ||
function defaultNoopBatch(callback: () => void) { | ||
callback() | ||
} | ||
|
||
let batch = defaultNoopBatch | ||
|
||
// Allow injecting another batching function later | ||
export const setBatch = (newBatch) => (batch = newBatch) | ||
export const setBatch = (newBatch: (callback: () => void) => void) => (batch = newBatch) | ||
|
||
// Supply a getter just to skip dealing with ESM bindings | ||
export const getBatch = () => batch |
This file was deleted.
Oops, something went wrong.
This file contains 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,25 @@ | ||
import { ActionCreator, ActionCreatorsMapObject, AnyAction, Dispatch } from "redux" | ||
|
||
function bindActionCreator<A extends AnyAction = AnyAction>( | ||
actionCreator: ActionCreator<A>, | ||
dispatch: Dispatch | ||
) { | ||
return function (this: any, ...args: any[]) { | ||
return dispatch(actionCreator.apply(this, args)) | ||
} | ||
} | ||
|
||
export default function bindActionCreators(actionCreators: ActionCreator<any> | ActionCreatorsMapObject, dispatch: Dispatch) { | ||
if (typeof actionCreators === 'function') { | ||
return bindActionCreator(actionCreators, dispatch) | ||
} | ||
|
||
const boundActionCreators: ActionCreatorsMapObject = {} | ||
for (const key in actionCreators) { | ||
const actionCreator = actionCreators[key] | ||
if (typeof actionCreator === 'function') { | ||
boundActionCreators[key] = (...args) => dispatch(actionCreator(...args)) | ||
} | ||
} | ||
return boundActionCreators | ||
} |
This file contains 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 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
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
src/utils/verifyPlainObject.js → src/utils/verifyPlainObject.ts
This file contains 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 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