redux-saga-final-form
Advanced tools
Comparing version 1.1.2 to 1.2.0
@@ -1,2 +0,2 @@ | ||
export declare function useListener(startActionType: string, resolveActionType: string, rejectActionType: string): (payload: any) => Promise<unknown>; | ||
export declare function useListener(startActionType: string, resolveActionType: string, rejectActionType: string, setPayload?: (payload: any) => Object): (payload: any) => Promise<unknown>; | ||
export declare function finalFormSaga(): Generator<import("redux-saga/effects").ForkEffect<never>, void, unknown>; |
@@ -7,5 +7,9 @@ "use strict"; | ||
const pendingCallbacks = new Map(); | ||
function useListener(startActionType, resolveActionType, rejectActionType) { | ||
function useListener(startActionType, resolveActionType, rejectActionType, setPayload) { | ||
const dispatch = react_redux_1.useDispatch(); | ||
return (payload) => { | ||
const action = { | ||
type: startActionType, | ||
payload: setPayload?.(payload) ?? payload | ||
}; | ||
return new Promise((resolve, reject) => { | ||
@@ -20,6 +24,3 @@ pendingCallbacks.set(resolveActionType, { | ||
}); | ||
dispatch({ | ||
type: startActionType, | ||
payload | ||
}); | ||
dispatch(action); | ||
}); | ||
@@ -26,0 +27,0 @@ }; |
{ | ||
"name": "redux-saga-final-form", | ||
"version": "1.1.2", | ||
"version": "1.2.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -0,0 +0,0 @@ redux-saga-final-form |
@@ -6,5 +6,9 @@ import { useDispatch } from 'react-redux'; | ||
export function useListener(startActionType: string, resolveActionType: string, rejectActionType: string) { | ||
export function useListener(startActionType: string, resolveActionType: string, rejectActionType: string, setPayload?: (payload: any) => Object) { | ||
const dispatch = useDispatch(); | ||
return (payload: any) => { | ||
const action = { | ||
type: startActionType, | ||
payload: setPayload?.(payload) ?? payload | ||
}; | ||
return new Promise((resolve, reject) => { | ||
@@ -19,6 +23,3 @@ pendingCallbacks.set(resolveActionType, { | ||
}); | ||
dispatch({ | ||
type: startActionType, | ||
payload | ||
}); | ||
dispatch(action); | ||
}) | ||
@@ -25,0 +26,0 @@ }; |
@@ -0,0 +0,0 @@ { |
132
11030
6