Svelte: multiple method calls with different argument sequence

Created on 11 Apr 2017  Â·  2Comments  Â·  Source: sveltejs/svelte

Iterating through a matrix with nested loops (i, j), the same method gets called twice with the arguments swapped depending on their relative values REPL. Extract below.

{{#each triangularMatrix as ri, i}}
<tr>
  {{#each triangularMatrix as rj, j}}
    {{#if i > j}}
      <td><input type="number" value={{ri[j]}} on:click='lowerThan(j, i)'></td>
    {{elseif i === j}}
      <td>1</td>
    {{else}}
      <td><input type="number" value={{rj[i]}} on:click='lowerThan(i, j)'></td>
    {{/if}}
  {{/each}}
</tr>
{{/each}}

the lowerThan function is called twice with the arguments swapped:

  • if i < j, <td ... on:click='lowerThan(i, j) //correct
  • if i > j, <td ... on:click='lowerThan(j, i) //always fails

In the generated code, a single change handler is registered and the arguments get swapped on the second call (ie the second assertion always fails).

The indices in the view are fine, the problem is only with the event handlers

bug

Most helpful comment

This is fixed in 1.14 — thanks

All 2 comments

I think I know what's going on here — two event handlers are being created, but they're both being given the name click_handler rather than click_handler and click_handler_1. Fairly sure I know how to fix that... on it

This is fixed in 1.14 — thanks

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ricardobeat picture ricardobeat  Â·  3Comments

1u0n picture 1u0n  Â·  3Comments

Rich-Harris picture Rich-Harris  Â·  3Comments

lnryan picture lnryan  Â·  3Comments

Rich-Harris picture Rich-Harris  Â·  3Comments