import { Store , Strategy , StreamAction , Middleware , RequestedOrder } from '../types' ; import { ORDER_REQUESTED , ORDER_CANCEL } from '../constants' ; private param { Strategy } strategy return { Middleware } export function createStrategy ( strategy ) { return ( store ) => ( next ) => ( action ) => { strategy ( { state : ( ) => store . getState ( ) , order : ( order ) => store . dispatch ( { type : ORDER_REQUESTED , payload : { timestamp : action . payload . timestamp , ... order } } ) , cancel : ( id ) => store . dispatch ( { type : ORDER_CANCEL , payload : { timestamp : action . payload . timestamp , id } } ) } , action ) ; return next ( action ) ; } ; }