Created
June 30, 2015 22:04
-
-
Save kwijibo/f38953bea0b25744e569 to your computer and use it in GitHub Desktop.
Some code I wrote using ramda.js
This file contains hidden or 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
//getFieldDefinition :: key -> [a] -> a | |
var getFieldDefinition = r.useWith( | |
r.find, // #final function :: Relation -> [a] -> a | |
r.propEq(1), //takes `key` where [1]==key #function for 1st param | |
r.identity //#placeholder func for 2nd param | |
) | |
// getFieldSpec :: String -> Object | |
// getFieldSpec('duration') | |
// > {type:'number', max:60, min: 1} | |
var getFieldSpec = r.memoize( | |
r.compose(r.defaultTo({}), r.prop(2), r.defaultTo([]), getFieldDefinition(r.__, textFields)) | |
) | |
//getFieldLabel :: fieldName -> fieldLabel | |
var getFieldLabel = r.memoize(r.compose(r.head, getFieldDefinition(r.__,textFields))) | |
// fieldInvalid :: Object -> Array -> String -> Boolean | |
var fieldInvalid = r.curry(function(model,fieldDefinitions, key){ | |
// modelKeyValue :: Model {someKey: { value: someValue }} -> String someValue | |
var modelKeyValue = r.pipe(r.prop(key), r.prop('value')) | |
var fieldDef = getFieldDefinition(key, fieldDefinitions) | |
if(!fieldDef) return false | |
var attrs = fieldDef[2] || {} | |
var value = modelKeyValue(model) | |
return isValid(value, attrs)===false | |
}) | |
//invalidFields :: model -> Array | |
function invalidFields(model){ | |
var fieldnames = getModelPropKeys(model) | |
return r.filter(fieldInvalid(model, textFields), fieldnames) | |
} | |
//wrapItem :: item -> ReactDomNode | |
var wrapItem = (i)=>{ return (<li>{i}</li>) } | |
var itemizeFieldLabel = r.compose(wrapItem, getFieldLabel) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
not all that recognisable as javascript. It's 25% comments, I'm the one that wrote it, and it still looks foreign.