[webcomponents] [Shadow]: Make event retargeting optional (bugzilla: 28444) (#89)

Title: [Shadow]: Make event retargeting optional (bugzilla: 28444)

Migrated from: https://www.w3.org/Bugs/Public/show_bug.cgi?id=28444

----
comment: 0
comment_url: https://www.w3.org/Bugs/Public/show_bug.cgi?id=28444#c0
*Dimitri Glazkov* wrote on 2015-04-08 16:00:41 +0000.

>From https://lists.w3.org/Archives/Public/public-webapps/2015AprJun/0052.html

Annevk: "I think opt-in (or only
with isolated) would be better and perhaps if the API needs to change
anyway we can do that, but we could probably live with opt-out as
well. When you use shadow DOM to compose, global reasoning about state
and events is a fairly established pattern that we should enable."

----

comment: 1
comment_url: https://www.w3.org/Bugs/Public/show_bug.cgi?id=28444#c1
*Dimitri Glazkov* wrote on 2015-04-08 18:27:59 +0000.

As far as I understand, the event.path is the mechanism to enable global reasoning about events. Optional event retargeting seems to be only complicating already complex algos. Consider a scenario where you have a mix of trees with and without retargeting.

----

comment: 2
comment_url: https://www.w3.org/Bugs/Public/show_bug.cgi?id=28444#c2
*Anne* wrote on 2015-04-13 09:32:36 +0000.

Yeah, which is why perhaps we should only do retargeting if the tree is explicitly closed. (Isolated would also have to do it of course.)

That seems like a much more logical model and allows for event.path and event.target to be consistent. The current approach seems a lot like the originalTarget approach from XBL.

----

comment: 3
comment_url: https://www.w3.org/Bugs/Public/show_bug.cgi?id=28444#c3
*Dimitri Glazkov* wrote on 2015-04-13 17:42:47 +0000.

(In reply to Anne from comment #2)
> Yeah, which is why perhaps we should only do retargeting if the tree is
> explicitly closed. (Isolated would also have to do it of course.)

This suggestion is interesting, but it is orthogonal to the complexity concern. I would still need extra branch points in the retargeting algos in order to account for nested trees that interleave the setting with and without retargeting (whether or not coupled to the closed/open setting), plus the extra transitive complexity of managing insertion points.

 
> That seems like a much more logical model and allows for event.path and
> event.target to be consistent. The current approach seems a lot like the
> originalTarget approach from XBL.

Can you explain a bit more why event.path seems bad? As far as I can tell, it works well for consumers with event delegation needs.

----

comment: 4
comment_url: https://www.w3.org/Bugs/Public/show_bug.cgi?id=28444#c4
*Dimitri Glazkov* wrote on 2015-04-13 18:01:23 +0000.

+dfreedm to comment on the coupling of closed/open and retargeting opt-in idea.

----

comment: 5
comment_url: https://www.w3.org/Bugs/Public/show_bug.cgi?id=28444#c5
*Daniel Freedman* wrote on 2015-04-13 22:17:16 +0000.

I think retargeting events for "open" shadowroots is still the right paradigm.

When composing elements with ShadowRoots together, it is far more useful to think of those elements as one whole, rather than their constituent pieces.
With retargeting, a developer can use very simple event delegation in their own scope with event.target for discrete composition points, rather than some more complicated ancestry checking.

For example:

If I have a fancy tab bar that controls content

  <tab-bar>
    #shadow-root
      <t-ab id="one">
        #shadow-root
          <fancy-ripple-effect></fancy-ripple-effect>
          Tab One!
      </t-ab>
      <t-ab id="two">
        (..snip..)
        Tab Two!
      </t-ab>
  </tab-bar>

and click on the first tab, with retargeting I can just check event.target === #one to show the associated content.

With event retargeting, each composition boundary can have this simple event delegation construct and be very intuitive for development.

I see event.path as more useful for a global event delegation mechanism, such as for determining desired scrolling behavior with touch events:

  for (var i = 0, el; el = touchEvent.path[i]; i++)
    if (el._shouldStopScrolling)
      touchEvent.preventDefault();

----

comment: 6
comment_url: https://www.w3.org/Bugs/Public/show_bug.cgi?id=28444#c6
*Hayato Ito* wrote on 2015-04-27 03:17:25 +0000.

Let me move this bug to v2 since it is not a blocker for v1.

---
Reply to this email directly or view it on GitHub:
https://github.com/w3c/webcomponents/issues/89

Received on Monday, 25 May 2015 08:51:14 UTC