Last active
August 29, 2015 14:16
-
-
Save wildermuthn/d18a8bbe1cc27ff6d51b to your computer and use it in GitHub Desktop.
New Ramda Switch
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
<input ng-model="filter.search" type="text" /> | |
<select ng-model="filter.category" ng-options="c for c in categories" /> |
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
R.fnSwitch = function(fnList) { | |
return R.mapObjIndexed((val, key) => fnList[key](val)); | |
}; |
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 fnList = { | |
'search': function(search) { | |
// Filter by search string | |
}, | |
'category': function(category) { | |
// Filter by category | |
}, | |
} | |
var mySwitch = R.fnSwitch(fnList); | |
$scope.$watchCollection('filter', function(filter) { | |
mySwitch(filter); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment