import { FSA , FluxType } from "./types/fsa" ; import { makeType } from "./utils" ; /**
 * Definition for annotating type parameter
 */ export type PayloadType < T > = T extends ActionCreator < infer R > ? R : never ; export type ReturnType < T > = T extends ( ... args : any [ ] ) => infer R ? R : never ; example export interface ActionCreator < Payload = void > { type : FluxType ; namespace : string ; ( payload , options ? ) : FSA < Payload > ; namespaced ( payload , options ? ) : FSA < Payload > ; } export interface FSAOptions { namespace ? : string ; error ? : boolean ; meta ? : any ; } export interface ActionCreatorOptions { prefix ? : string ; namespace ? : string ; } param type export function actionCreator < Payload = void > ( type , creatorOptions = { } ) { const fullType = makeType ( type , creatorOptions . prefix ) ; const create = ( payload , options = { } ) : FSA < Payload > => { return { type : options . namespace ? makeType ( type , options . namespace ) : fullType , payload , error : options . error , meta : options . meta } ; } ; return Object . assign ( create , { namespaced : ( payload , options = { } ) => create ( payload , { ... options , namespace : creatorOptions . namespace } ) , type : fullType , namespace : creatorOptions . namespace } ) as ActionCreator < Payload > ; } param type export function actionCreatorFactory ( options ) { if ( typeof options === "string" ) { return ( type ) => actionCreator ( type , { namespace : options } ) ; } return ( type ) => actionCreator ( type , options ) ; }