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.

Addition to tutorial: Calling a function in an "each" block

See original GitHub issue

The tutorial/documentation should have an example of calling a function inside an each block to do some additional processing. This is non-intuitive so putting it in the tutorial would be very helpful.

e.g.

<script>
function dosomething(item) {
  var dict = {};

   // Put original object into the dictionary
    dict.item = item;

  // Do some processing and put various results in the dictionary to be used in the loop.
  dict.result = "success";
  dict.count = 12;

  return dict;
}
</script>


{#each list as item}
  {#each [dosomething(item)] as val}
   <div>{val.result} {val.item} {val.count}</div>
  {/each}
{/each}

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
dimfeldcommented, Nov 12, 2019

Is there a reason to do it that way instead of just

{#each list.map(dosomething) as val}
  <div>{val.result} {val.item} {val.count}</div>
{/each}

Here’s a REPL example of this style: https://svelte.dev/repl/3d071e514c7641c580980c48dd1b6665?version=3.14.0

1reaction
rlaferlacommented, Jan 23, 2020

Sure but it’s not in the TUTORIAL.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Functions — reusable blocks of code - Learn web development
This function draws 100 random circles inside a <canvas> element. Every time we want to do that, we can just invoke the function...
Read more >
TwinCAT 3 Tutorial: Writing your own Functions and ...
A program is like a function block (it has internal state), but there is only one global copy of each program, so you...
Read more >
How to Define and Call a Function in PHP
Functions reduces the repetition of code within a program — Function allows you to extract commonly used block of code into a single...
Read more >
Functions
In the example above, main begins by declaring the variable z of type int , and right after that, it performs the first...
Read more >
How To Define and Call Functions in Go
A function is a section of code that, once defined, can be reused. Functions are used to make your code easier to understand...
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