question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Describe the bug This is really more of a suggestion then a bug, but I think it’s worth considering for dev ux sake… Use Case: You want to use Svelte DOM event forwarding syntax which is nice and minimal (as opposed to wiring up event dispatchers needlessly).

To Reproduce Steps to reproduce the behavior:

  1. Create a component that leverages Svelte’s DOM event forwarding syntax
  2. Create a story using actions and look at docs for how to wire those up Result

You will likely land on the Svelte tutorial and possibly the kitchen sink examples

From these, you will believe you must wire up an event dispatcher to get actions to work when using Storybook <–> Svelte.

Expected behavior I think the docs and tutorials should be updated to either mention that you can and should leverage DOM event forwarding, and perhaps also show how you can intercept and use the dispatcher. Really, it’s an unnecessary layer of indirection if you’re just trying to bubble events back to parent.

Code snippets Here’s an example input component with just the svelte template part and simplified for brevity:

    <input
      id={uniqueId}
      on:blur
      on:change
      on:input
      on:click
      on:focus
 />

With that, any consumer / parent can just listen for those events…no dispatch wiring up needed.

It turns out, you can nicely do the same with storybook but you have to omit the on: part:

import { action } from '@storybook/addon-actions';

const actionsData = {
  'click': action('click'),
  'blur': action('blur'),
  'change': action('change'),
  'input': action('input'),
  'focus': action('focus'),
}

Then you just spread actionsData exactly as your Svelte tutorial suggests. Works great and is much more idiomatic for such use case in Svelte. It took me a bit to figure this out hence the recommendation to document it.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jonniebigodescommented, Jan 2, 2021

@roblevintennis no worries. I’ve primed the tutorial for svelte and it should be up shortly. Take care of what needs to be taken care of and when you have time we’ll circle back to this and work on it.

Stay safe

1reaction
shilmancommented, Oct 15, 2020

nice one! cc @jonniebigodes

Read more comments on GitHub >

github_iconTop Results From Across the Web

Docs • Svelte
This page contains detailed API reference documentation. It's intended to be a resource for people who already have some familiarity with Svelte.
Read more >
Introduction / Basics • Svelte Tutorial
Svelte is a tool for building fast web applications. It is similar to JavaScript frameworks such as React and Vue, which share a...
Read more >
Introduction • Docs • SvelteKit
Building an app with all the modern best practices is fiendishly complicated.
Read more >
Svelte • Cybernetically enhanced web apps
The Svelte compiler packaging up your component code ... Svelte compiles your code to tiny, framework-less vanilla JS — your app starts fast...
Read more >
Configuration • Docs • SvelteKit
An object containing zero or more aliases used to replace values in import ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found