aurelia / i18n

A plugin that provides i18n support.
MIT License
93 stars 70 forks source link

T attribute inside a repeater refresh the whole table #302

Closed gcastre closed 5 years ago

gcastre commented 5 years ago

As discussed on the gitter with @zewa666

I'm submitting a bug report

Please tell us about your environment:

Current behavior:

Using the T custom attribute on a in a table cause the whole to be repainted when the array that is binded to the repeater change.

  <table>
    <tbody>
      <tr repeat.for="item of items">
        <td style="width:100px;" t="[title]${item.name}">${item.name & t}</td>
        <td style="width:100px;">${item.isAvailable}</td>
      </tr>
    </tbody>
  </table>

Expected/desired behavior:

Only the with properties that have been changed should be repainted just like if you did use the binding behaviour.

  <table>
    <tbody>
      <tr repeat.for="item of items">
        <td style="width:100px;" title.to-view="item.name & t">${item.name & t}</td>
        <td style="width:100px;">${item.isAvailable}</td>
      </tr>
    </tbody>
  </table>

Here is a sample based on a new project from the cli: https://github.com/gcastre/au-i18n

I used the paint flashing in chrome to see the issue.

bigopon commented 5 years ago

@gcastre I think the behavior you described is related to how I18N works. With a t custom attribute, probably the whole innerHTML is updated (by service from I18N library) while with value converter or binding behavior, only the text content is updated.

zewa666 commented 5 years ago

that is true. In most scenarios the original DOM element is recreated and replaced. This is partially due to avoid replacement issues (prepend/append, attributes) and due to this approach not really being the best for large tables. In such cases typically you'd want to stick with BindingBehavior or even better the T ValueConverter, if your locales are not going to change at runtime, due to smaller overhead. Preferably also with one-time bindings if the bound source is not going to change.

gcastre commented 5 years ago

Ok thank you for your response. May I suggest to add a warning about that in the documentation ?

zewa666 commented 5 years ago

Good idea. Created a PR for the docs, please have a quick review @gcastre.