Last active
December 23, 2015 13:39
-
-
Save BlessYAHU/6644051 to your computer and use it in GitHub Desktop.
Code has been changed to pseudocode, but intent is still there.
Original code is using Underscore, fmap from drboolean's typeclasses library and autocurry from wu.js. Original code gets a list of filter commands and a list of products. Filter views are rendered only if products have properties matching filtercommand field names.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var lookupExecute = function( products, processCommands) { | |
this.commandArray = processCommands; | |
this.lookupArray = products; | |
}; | |
// unwrapped values in functor, apply given function over each command object that has lookup items that meet the condition | |
lookupExecute.prototype.fmap = function(fn) { | |
var self = this, | |
mappedResults = map(this.commandArray, function(command) { | |
var matchedItems = self.lookupArray.filter(function(item) { | |
return item.has(command.FieldName); | |
}); | |
return isEmpty(matchedItems) ? command : fn(command); | |
}); | |
// wrap the values back up. | |
return new lookupExecute(this.lookupArray, this.commandArray); | |
}; | |
// array is needed in the method | |
var executeCommand = function(arry, command) { | |
//code that executes command | |
return command; | |
}.autoCurry(); | |
// possible use: render a view using items in collection, only if fieldname of command matches some items | |
fmap(executeCommand(prodTypeCollection), new lookupExecute(prodTypeCollection, filterViewCmdArray)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment