Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/gen/js/genReduxActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import * as ${name} from '../${name}'${ST}
function renderReduxActionBlock(spec: ApiSpec, op: ApiOperation, options: ClientOptions): string {
const lines = []
const isTs = options.language === 'ts'
let hasOptions=''
const actionStart = camelToUppercase(op.id) + '_START'
const actionComplete = camelToUppercase(op.id)
const infoParam = isTs ? 'info?: any' : 'info'
Expand All @@ -45,6 +46,7 @@ function renderReduxActionBlock(spec: ApiSpec, op: ApiOperation, options: Client
const required = op.parameters.filter(param => param.required)
let params = required.map(param => param.name).join(', ')
if (required.length < op.parameters.length) {
hasOptions=', options'
if (required.length) params += ', options'
else params = 'options'
}
Expand All @@ -58,15 +60,15 @@ ${isTs ? `export type ${actionComplete} = ${returnType}${ST}`: ''}

export function ${op.id}(${paramSignature})${isTs? ': any' : ''} {
return dispatch => {
dispatch({ type: ${actionStart}, meta: { info } })${ST}
dispatch({ type: ${actionStart}, meta: { info${hasOptions} } })${ST}
return ${op.group}.${op.id}(${params})
.then(response => dispatch({
type: ${actionComplete},
payload: response.data,
error: response.error,
meta: {
res: response.raw,
info
info${hasOptions}
}
}))${ST}
}${ST}
Expand Down