javascript - lodash flow and multiple arguments -
i have 2 functions add in lodash flow:
function normalizedformfields(fields) { // needs 1 argument return _.mapvalues( fields, function( value ) { return { 'content': value }; } ); } function mergedmodelandformfieldss(model, normalizedformfields) { return _.merge( {}, model, normalizedformfields ) } const execution = _.flow( normalizedformfields, mergedmodelandformfieldss ) const errormessagebag = function( fields, model ) { return execution( fields, model ) // initiate flow 2 arguments }
as can see first function normalizedformfields takes 1 argument. second 1 needs 2: value returned previous function (which normal behavior of flow), , one: model.
but in errormessagebag invocation, launch flow process 2 arguments. how have second argument, available second function in addition returned product of first function ? see problem first function in flow takes , need 1 argument. kind of situation "curry" should come play ? please illustrate.
try this, should work:
function normalizedformfields(fields) { return _.mapvalues( fields, function( value ) { return { 'content': value }; }); } function mergedmodelandformfieldss(model, normalizedformfields) { return _.merge( {}, model, normalizedformfields ) } const errormessagebag = function( fields, model ) { return _.flow( normalizedformfields, mergedmodelandformfieldss.bind(this, model) )(fields) }
Comments
Post a Comment