aurelia / i18n

A plugin that provides i18n support.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

T attribute inside a repeater refresh the whole table

gcastre opened this issue · comments

As discussed on the gitter with @zewa666

I'm submitting a bug report

  • Library Version:
    major.minor.patch-pre

Please tell us about your environment:

  • Operating System:
    Windows 10

  • Node Version:
    10.15.3

  • NPM Version:
    6.9.0

  • JSPM OR Webpack AND Version
    webpack 4.30.0

  • Browser:
    Chrome 73.0.3683.103

  • Language:
    ESNext

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.

@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.

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.

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

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