Hopefully the implementation will be PAYG and use composition and people can 
add listenOnce when needed (DAYG).

I'm hoping that you will find that we can dispatch events off the 
HTMLElement/Element and bypass goog.events entirely.  And then have some cheap, 
no bubbling, probably no-capture EventDispatcher for non-Element instances.

Got my fingers crossed,
-Alex

On 12/26/19, 1:02 PM, "Harbs" <[email protected]> wrote:

    Anyone feel a need to have something like goog’s “listenOnce” 
functionality? We’ve never had it in Flex and I didn’t really feel the need.
    
    Harbs
    
    > On Dec 26, 2019, at 9:35 PM, Harbs <[email protected]> wrote:
    > 
    > OK. Thanks.
    > 
    > I’m going to try and rework events sometime over the next few days and I 
hope to get rid of EventTarget, make it more PAYG and I’ll fix this too.
    > 
    > Stay tuned…
    > 
    > Harbs
    > 
    >> On Dec 26, 2019, at 7:56 PM, Josh Tynjala <[email protected]> 
wrote:
    >> 
    >> I seem to recall recently being surprised to learn that you can capture 
an
    >> event that doesn't bubble.
    >> 
    >> I just tried in Flash, and I can confirm that a non-bubbling event can be
    >> seen by a parent during the capture phase.
    >> 
    >> var sprite:Sprite = new Sprite();
    >> var child:Sprite = new Sprite();
    >> sprite.addChild(child);
    >> 
    >> sprite.addEventListener(Event.CHANGE, function(event:Event):void
    >> {
    >>   trace("parent (capture):", event.eventPhase);
    >> }, true);
    >> 
    >> child.dispatchEvent(new Event(Event.CHANGE, false));
    >> 
    >> 
    >> 
    >> --
    >> Josh Tynjala
    >> Bowler Hat LLC 
<https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbowlerhat.dev&amp;data=02%7C01%7Caharui%40adobe.com%7C87a28ac207434dbf856108d78a46e9db%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C637129909496673253&amp;sdata=5v5ILkdKcA2s8LiG13xvr%2BbktoSsbV0fUiq982diZL4%3D&amp;reserved=0>
    >> 
    >> 
    >> On Wed, Dec 25, 2019 at 2:25 AM Harbs <[email protected]> wrote:
    >> 
    >>> Capture phase will only work if the event.bubbles is true.
    >>> 
    >>> I think that’s correct behavior. Someone please correct me if I’m wrong.
    >>> 
    >>>> On Dec 25, 2019, at 12:23 PM, [email protected] wrote:
    >>>> 
    >>>> This is an automated email from the ASF dual-hosted git repository.
    >>>> 
    >>>> harbs pushed a commit to branch develop
    >>>> in repository 
https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgitbox.apache.org%2Frepos%2Fasf%2Froyale-asjs.git&amp;data=02%7C01%7Caharui%40adobe.com%7C87a28ac207434dbf856108d78a46e9db%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C637129909496683243&amp;sdata=ILXWpHhD236PD86ddMyUQ4SaZoyiTnsNhIaC9k5lvc0%3D&amp;reserved=0
    >>>> 
    >>>> 
    >>>> The following commit(s) were added to refs/heads/develop by this push:
    >>>>   new 2f8ef75  Fixed event bubbling
    >>>> 2f8ef75 is described below
    >>>> 
    >>>> commit 2f8ef759d700f439fa40cc2abf6aefbb04ab4bdb
    >>>> Author: Harbs <[email protected]>
    >>>> AuthorDate: Wed Dec 25 12:23:13 2019 +0200
    >>>> 
    >>>>  Fixed event bubbling
    >>>> ---
    >>>> .../org/apache/royale/events/EventDispatcher.as    | 72
    >>> ++++++----------------
    >>>> 1 file changed, 18 insertions(+), 54 deletions(-)
    >>>> 
    >>>> diff --git
    >>> 
a/frameworks/projects/Core/src/main/royale/org/apache/royale/events/EventDispatcher.as
    >>> 
b/frameworks/projects/Core/src/main/royale/org/apache/royale/events/EventDispatcher.as
    >>>> index 34871d5..510b531 100644
    >>>> ---
    >>> 
a/frameworks/projects/Core/src/main/royale/org/apache/royale/events/EventDispatcher.as
    >>>> +++
    >>> 
b/frameworks/projects/Core/src/main/royale/org/apache/royale/events/EventDispatcher.as
    >>>> @@ -90,8 +90,23 @@ package org.apache.royale.events
    >>>>                                     //console.log("assigned target to
    >>> event ",event);
    >>>>                             }
    >>>>                     } else return false;
    >>>> +                     var ancestorsTree:Array = null;
    >>>> +                     if(event1.bubbles)
    >>>> +                     {
    >>>> +                             var ancestor:Object =
    >>> this.getParentEventTarget();
    >>>> +                             if (ancestor) {
    >>>> +                     ancestorsTree = [];
    >>>> +                     var ancestorCount:int = 1;
    >>>> +                         for (; ancestor; ancestor =
    >>> ancestor.getParentEventTarget()) {
    >>>> +                             ancestorsTree.push(ancestor);
    >>>> +                     //      goog.asserts.assert(
    >>>> +          //                 (++ancestorCount <
    >>> goog.events.EventTarget.MAX_ANCESTORS_),
    >>>> +          // 'infinite loop');
    >>>> +                     }
    >>>> +                     }
    >>>> +                     }
    >>>> 
    >>>> -                     return super.dispatchEvent(event1);
    >>>> +                     return
    >>> goog.events.EventTarget.dispatchEventInternal_(_dispatcher, event1,
    >>> ancestorsTree);
    >>>>             }
    >>>>             /**
    >>>>              * @royaleignorecoercion org.apache.royale.core.IChild
    >>>> @@ -129,59 +144,8 @@ package org.apache.royale.events
    >>>>             }
    >>>> 
    >>>>             public function toString():String
    >>>> -        {
    >>>> -            return "[object Object]";
    >>>> -        }
    >>>> -             private static function installOverride():Boolean{
    >>>> -                     goog.events.EventTarget.dispatchEventInternal_ =
    >>> dispatchEventInternal;
    >>>> -                     return true;
    >>>> +             {
    >>>> +                             return "[object Object]";
    >>>>             }
    >>>> -             private static var overrideInstalled:Boolean =
    >>> installOverride();
    >>>> -             /**
    >>>> - * Dispatches the given event on the ancestorsTree.
    >>>> - *
    >>>> - * @param {!Object} target The target to dispatch on.
    >>>> - * @param {goog.events.Event|Object|string} e The event object.
    >>>> - * @param {Array<goog.events.Listenable>=} opt_ancestorsTree The
    >>> ancestors
    >>>> - *     tree of the target, in reverse order from the closest ancestor
    >>>> - *     to the root event target. May be null if the target has no
    >>> ancestor.
    >>>> - * @return {boolean} If anyone called preventDefault on the event
    >>> object (or
    >>>> - *     if any of the listeners returns false) this will also return
    >>> false.
    >>>> - * @private
    >>>> - */
    >>>> -private static function dispatchEventInternal(target:EventDispatcher,
    >>> e:org.apache.royale.events.Event, opt_ancestorsTree:Array):Boolean {
    >>>> -  /** @suppress {missingProperties} */
    >>>> -  var type:String = e.type;
    >>>> -
    >>>> -  var rv:Boolean = true, currentTarget:Object;
    >>>> -
    >>>> -  // Executes all capture listeners on the ancestors, if any.
    >>>> -  if (opt_ancestorsTree) {
    >>>> -    for (var i:int = opt_ancestorsTree.length - 1;
    >>> !e.propagationStopped_ && i >= 0;
    >>>> -         i--) {
    >>>> -      currentTarget = e.currentTarget = opt_ancestorsTree[i];
    >>>> -      rv = currentTarget.fireListeners(type, true, e) && rv;
    >>>> -    }
    >>>> -  }
    >>>> -
    >>>> -  // Executes capture and bubble listeners on the target.
    >>>> -  if (!e.propagationStopped_) {
    >>>> -    currentTarget = e.currentTarget = target;
    >>>> -    rv = currentTarget.fireListeners(type, true, e) && rv;
    >>>> -    if (!e.propagationStopped_) {
    >>>> -      rv = currentTarget.fireListeners(type, false, e) && rv;
    >>>> -    }
    >>>> -  }
    >>>> -
    >>>> -  // Executes all bubble listeners on the ancestors, if any.
    >>>> -  if (opt_ancestorsTree && e.bubbles) {
    >>>> -    for (i = 0; !e.propagationStopped_ && i < 
opt_ancestorsTree.length;
    >>> i++) {
    >>>> -      currentTarget = e.currentTarget = opt_ancestorsTree[i];
    >>>> -      rv = currentTarget.fireListeners(type, false, e) && rv;
    >>>> -    }
    >>>> -  }
    >>>> -
    >>>> -  return rv;
    >>>> -};
    >>>>     }
    >>>> }
    >>>> 
    >>> 
    >>> 
    > 
    
    

Reply via email to