Announcement

Collapse
No announcement yet.

[CLOSED] [#3107] [16.3] Event handler removal interferes with other handler methods

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    [CLOSED] [#3107] [16.3] Event handler removal interferes with other handler methods

    Consider the following example: https://deck.net/69d832ef112571a2c8c21564707a7b88

    The behavior to expect ist that the console outputs "handler 1" and then "handler 2".

    The actual behavior is: The console only outputs "handler 1", because handler 2 gets skipped. This is due to the fact that handler 1 removes itself from the listener collection, which causes the caller loop in Bridge to skip the other listener. Perhaps you need to reverse your for-loop so that it counts from (list.length-1) down to 0:

                $build: function (handlers) {
                    var fn = function () {
                        var list = fn.$invocationList,
                            result = null,
                            i,
                            handler;
    
     for (i = 0; i < list.length; i++) {
                            handler = list[i];
                            result = handler.apply(null, arguments);
                        }
    
                        return result;
                    };
    
                    fn.$invocationList = handlers ? Array.prototype.slice.call(handlers, 0) : [];
    
                    if (fn.$invocationList.length === 0) {
                        return null;
                    }
    
                    return fn;
                }

    #2
    PS: This is a somewhat urgent bug for me because it breaks my entire application. I often have scenarios where event handlers only need to be called once and then disconnect themselves to avoid browser memory leaks (Example. ViewClosed event handler only gets called once, so every subscriber unsubscribes during event handling).

    Since there seems to be no workaround, this is a blocking problem.

    Thanks!
    Marco

    Comment


      #3
      Thanks for the report, we will try to fix that issue ASAP
      Git issue: https://github.com/bridgedotnet/Bridge/issues/3107

      Comment


        #4
        Fix for issue #3107 merged into v16.3 branch and will be included in the next Bridge.NET release.

        Comment

        Working...
        X