Correct me if I'm wrong, but my understanding is that this
function transformer(transformationFn, value) {
return (transformationFn || angular.identity)(value);
};
could be "un-refactored" to this
function transformer(transformationFn, value) {
if (transformationFn) {
return transformationFn(value);
} else {
return angular.identity(value);
}
};
which would be functionally equivalent to this identity
-less version:
function transformer(transformationFn, value) {
if (transformationFn) {
return transformationFn(value);
} else {
return value;
}
};
So I guess the use case would be when you want to apply a certain transformation to a value when you're supplied with something that may or may not actually exist.
I wanted to better explain the identity
function (as I understand it), although as I review my answer I don't think I really answered your question. Leaving my answer here anyway in case it's helpful.
angular.identity()
function (when transformationFn is undefined) and what it does on calling. – Guiscard