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

Function wrapping always returns undefined. #228

Open
M0nter0 opened this issue Feb 16, 2015 · 4 comments
Open

Function wrapping always returns undefined. #228

M0nter0 opened this issue Feb 16, 2015 · 4 comments

Comments

@M0nter0
Copy link

M0nter0 commented Feb 16, 2015

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

@M0nter0 M0nter0 changed the title selectOverlap function wrapping never allows to overlap Function wrapping always return undefined. Feb 16, 2015
@M0nter0 M0nter0 changed the title Function wrapping always return undefined. Function wrapping always returns undefined. Feb 16, 2015
@joshkurz
Copy link
Contributor

I'm not sure we should even be doing this anyways. It causes so many issues in the first place.

But I was trying to debug the issue and I commented out the wrapFunction completely, so in this plunker the selectOverlap function does not fire at all. I may be doing something wrong, but it seems odd, that it does not work, even if we bypass the wrapFunction all together.

http://plnkr.co/edit/ra3I0OygIRzGZ2Dxcz9t?p=preview

@M0nter0
Copy link
Author

M0nter0 commented Feb 16, 2015

Hi @joshkurz,
I'm running your plunkr and for me is working. I can see the log of (event) and the forbidden icon that comes from returning false.

selectOverlap: function(event) {
            console.log(event)
            return false;
        }, 

I think it's the same problem with $timeout that was commented in Issue 123 : #123

@joshkurz
Copy link
Contributor

ok I see, but for some reason the selectOverlap is still not working for me. But nevertheless, here is a proposed solution for the issue.

http://plnkr.co/edit/gdQtxBLH0LJaHc7Yam9X?p=preview

This solves #123 and this issue, by allowing the user to specify which functions to ignore. This is done in the plunker on line 12 of calendarController.js

uiCalendarConfig.functionIgnores = ['eventDataTransform', 'eventClick', 'selectOverlap'];

What do you think about this solution?

@laander
Copy link
Contributor

laander commented May 28, 2015

Any updates on this issue? I would love to be able to use selectOverlap and eventOverlap with functions, as that enables for more granular control

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants