Skip to content
This repository was archived by the owner on Sep 8, 2020. It is now read-only.
This repository was archived by the owner on Sep 8, 2020. It is now read-only.

Function wrapping always returns undefined. #228

Open
@M0nter0

Description

@M0nter0

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions