import { identity } from '../../helpers/identity/identity' ; import { uniqify } from '../../helpers/uniqueId/uniqify' ; import { createEpic } from '../createEpic/createEpic' ; import { Epic } from '../createApp/createApp.h' ; import { AnyEventCreator , AnyPayloadTransformer , EmptyEventCreator , Event , EventCreator0 , EventCreator1 , EventCreator2 , EventCreator3 , PayloadTransformer0 , PayloadTransformer1 , PayloadTransformer2 , PayloadTransformer3 } from './createEvent.h' ; private const isError = ( a ) : a is Error => a instanceof Error ; param description export function createEvent ( description ? ) ; typeparam typeparam param description export function createEvent < Payload > ( description ? ) ; typeparam typeparam param description param payloadCreator param metaCreator export function createEvent < Payload , Meta = void > ( description , payloadCreator , metaCreator ? ) ; typeparam typeparam typeparam param description param payloadCreator param metaCreator export function createEvent < A1 , Payload , Meta = void > ( description , payloadCreator , metaCreator ? ) ; typeparam typeparam typeparam typeparam param description param payloadCreator param metaCreator export function createEvent < A1 , A2 , Payload , Meta = void > ( description , payloadCreator , metaCreator ? ) ; typeparam typeparam typeparam typeparam typeparam param description param payloadCreator param metaCreator export function createEvent < A1 , A2 , A3 , Payload , Meta = void > ( description , payloadCreator , metaCreator ? ) ; export function createEvent ( description ? , payloadCreator = identity , metaCreator ? ) { const type = uniqify ( description ) ; const eventCreator = ( ... args ) => { const event = { type } ; try { event . payload = isError ( args [ 0 ] ) ? args [ 0 ] : ( payloadCreator as any ) ( ... args ) ; } catch ( error ) { event . payload = error ; } event . error = isError ( event . payload ) ; if ( metaCreator ) { event . meta = ( metaCreator as any ) ( ... args ) ; } return event ; } ; eventCreator . getType = ( ) => type ; eventCreator . is = ( event ) => event . type === type ; eventCreator . epic = < State > ( fn ) : Epic < State > => createEpic ( eventCreator , fn ) ; return eventCreator ; }