locked
WinJS.Application.queueEvent breaks when listeners remove them-self during invocation

    Question

  • Assume you have listeners, that remove themself when they are invoked (onetime listeners). They work well with EventMixin based classes, because EventMixin copies the list of listeners before it calls each listener to protect against removal of those listeners during call. However, WinJS.Application does for whatever reasons not use EventMixin but its own listener implementation and handling. Forgetting to protected against this reasonable behaviour of listeners.

    listener = function() {

      WinJS.Application.removeListener("type", listener);

    }

    WinJS.Application.addEventListener("type", listener);

    WinJS.Application.addEventListener("type", listener);

    WinJS.Application.addEventListener("type", listener);

    when you now call:

    WinJS.Application.queueEvent({type:"type"});

    Only 2 listeners are called. The first added will never be called.

    The only way to solve this, is to use the universal "setImmediate" to postpone the removel to the next script execution frame.

    Questions:

    Why is the event.setPromise not in EventMixin, its very helpful.

    Why does WinJS.Application not use EventMixin and hides the queueing of events in the background. I tried to call Application.dispatchEvent cause I thought it uses EventMixin.

    Friday, May 10, 2013 9:25 AM

All replies

  • Why does WinJS.Application not use EventMixin and hides the queueing of events in the background.

    I think it's by design
    Tuesday, May 14, 2013 8:43 AM
  • I'd like to have a quote on that from MSFT... by design pffff. Its broken by design :)
    Wednesday, May 15, 2013 8:22 AM