Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

on:* #3349

Closed
wants to merge 15 commits into from
Closed

on:* #3349

wants to merge 15 commits into from

Conversation

matyunya
Copy link

@matyunya matyunya commented Aug 4, 2019

#2837

This is first iteration of on:* to enable forwarding arbitrary events for components.

@@ -17,7 +17,7 @@ export default class EventHandler extends Node {
constructor(component: Component, parent, template_scope, info) {
super(component, parent, template_scope, info);

this.name = info.name;
this.name = info.name !== '*' ? info.name : 'any';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would give on:any a different meaning than it already has, which we don't want to do. It's possible that someone has code where they are bubbling an event called any, and this would break it. I think elsewhere should just be looking for handler.name === '*' directly.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renaming to $$any helped. Is it ok way this way?

@@ -43,6 +43,16 @@ export function mount_component(component, target, anchor) {
run_all(new_on_destroy);
}
component.$$.on_mount = [];

if (fragment.bbl) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless I'm mistaken, this mechanism won't forward events with handlers attached after the component has been mounted.

@matyunya
Copy link
Author

matyunya commented Aug 5, 2019

Demo is available here: https://public-mo2fyuk8g.now.sh/.

I couldn't find another way but to write block specific code (so far each and if) to push up elements with on:*. I know that this is missing disposing of listeners, also no need to generate any_handler. Anything else I'm overlooking here?

@matyunya
Copy link
Author

matyunya commented Aug 5, 2019

Here's component I'm testing on:

<script>
  import { createEventDispatcher } from "svelte";
  export let value = null;

  const dispatch = createEventDispatcher();

  const arr = [1,2,3];

  function handleClick() {
    value = !value;

    dispatch('any');
  }
</script>

<button on:* on:click={handleClick}><slot /></button>
 
<div on:*></div>
<div on:*></div>
{#if value}
  <button on:*>another button</button>
  {#each arr as k}
    <button on:*>{k}</button>
  {/each}
{/if}

What other cases should I consider besides else and await?

@matyunya
Copy link
Author

matyunya commented Aug 5, 2019

One more thing. listen is tree shaken if there are only on:* event handlers. What can I do to force keep it?

@codecov-io
Copy link

codecov-io commented Sep 8, 2019

Codecov Report

Merging #3349 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #3349   +/-   ##
=======================================
  Coverage   50.25%   50.25%           
=======================================
  Files           1        1           
  Lines         197      197           
=======================================
  Hits           99       99           
  Misses         98       98

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e686216...7c953a8. Read the comment docs.

@matyunya
Copy link
Author

Anything I can do to stop being ignored?

@jerriclynsjohn
Copy link

jerriclynsjohn commented Sep 27, 2019

@matyunya I was able to compile your specific package locally and tried an event forwarding with the example given at https://svelte.dev/tutorial/event-forwarding, and instead of using on:message in Outer.svelte I tried using on:* and couldn't get the event to be forwarded. Am I missing something here or is it not working?

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this something that is still desired?

The code needs to be rewritten since this was done before code-red and ast stuff was merged.

I'd recommend also branching for PR instead of submitting from master. It makes rework and rebasing much easier.

@matyunya
Copy link
Author

I made the first step here and wanted to hear feedback if my direction is right. Will make another round now.

@ghost
Copy link

ghost commented Jan 17, 2020

@matyunya,

You really should do a branch since there's now commit pollution on this PR from your other strict-order PR. I tend to never work on my own fork master and instead just fast-forward to the upstream and then rebase my branches off of that (instead of merge commits).

When I first looked at the notification email for this PR, it said there were 200+ commits added, which is pretty good sign that the workflow is a off somewhere.

See if you can untangle this from the other PRs so it can get a proper review.
There's been some talk of this feature on Discord so I'm pretty sure it will be a welcomed addition, provided that the merge isn't messy.

@matyunya
Copy link
Author

My bad.

I will recreate my fork and put the two features in different branches. But given the diff with master, I'll have to do my work on on:* from scratch, maybe find a leaner solution along the way.

@matyunya matyunya closed this Jan 18, 2020
@PaulMaly
Copy link
Contributor

@matyunya Any news here? Seems it's the most wanted feature at the current moment.

@kkarpeev
Copy link

kkarpeev commented Oct 20, 2020

Yeah. Ability to forward all events not only from a DOM-node but also through components is really REALLY necessary.

@Leonidaz
Copy link

Leonidaz commented Nov 4, 2020

I believe this is the PR that was considered last for this feature, pending a review from another core team member: #4599

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

Successfully merging this pull request may close these issues.

8 participants