Function wrapping always returns undefined. #228
Description
As selectOverlap could receive a function from the scope, the wrapper is managing it to execute it on the next digest.
That's fine, but when fullCalendar is working with the result of that method, then it receives undefined -of course, because the wrapper is not returning anything and is calling a $promise that will be resolved on the next digest..
Because of that, a method like selectOverlap can never trust in the return of the wrapper method.
// {overlap} here is the wrapper method
// evaluate overlap for the given range and short-circuit if necessary
if (overlap === false) {
return false;
}
else if (typeof overlap === 'function' && !overlap(otherEvent, event)) {
return false;
}
You can reproduce it in this plunker:
As you can see, I've set the property to return a simple function that always returns true.
selectOverlap: function(){return true},
But that function is wrapped, by wrapFunctionWithScopeApply
wrapFunctionWithScopeApply = function (functionToWrap) {
var wrapper;
if (functionToWrap) {
wrapper = function () {
// This happens outside of angular context so we need to wrap it in a timeout which has an implied apply.
// In this way the function will be safely executed on the next digest.
var args = arguments;
var _this = this;
$timeout(function () {
functionToWrap.apply(_this, args);
});
};
}
return wrapper;
};
So It will always returns wrapper, that is a function without return, executing a promise calling $timeout, so fullcalendar always check it as undefined.
I think this explains also PR 122 wrapFunctionWithScopeApply breaks eventDataTransform