vertical-collection icon indicating copy to clipboard operation
vertical-collection copied to clipboard

No rerender on a @tracked array update

Open oliverlj opened this issue 3 years ago • 3 comments

The @tracked array used as items do not rerender on update

oliverlj avatar Nov 28 '21 19:11 oliverlj

@oliverlj How are you updating the array? If it's a native array, then you can't use the push() method. You need to create a new array object so @tracked knows it changed.

@tracked items = [];

addItem(item) {
  // doesn't work
  this.items.push(item)

  // works
  this.items = [...this.items, item];
}

paulyoder avatar Dec 01 '21 14:12 paulyoder

I'm using a js getter of a @tracked property. Normal table is rerender, vertical collection not

{{#if this.sortedTransactions}}
            {{!-- {{#vertical-collection
              this.sortedTransactions
              containerSelector=".transax"
              tagName="tbody"
              estimateHeight="3rem"
              staticHeight=true
              class="tx-body"
              as |tx|
            }}
              <tr class="line-height-tx">
                <TxTable::TxItem @tx={{tx}} />
              </tr>
            {{/vertical-collection}} --}}
            <tbody class="tx-body">
              {{#each this.sortedTransactions as |tx|}}
                {{#if this.state}}
                  <tr class="line-height-tx deactivate-line">
                    <TxTable::TxItem @tx={{tx}} />
                  </tr>
                {{else}}
                  <tr class="line-height-tx">
                    <TxTable::TxItem @tx={{tx}} />
                  </tr>
                {{/if}}
              {{/each}}
            </tbody>
          {{else}}
  get sortedTransactions() {
    if (this.catSortOrder !== SortOrder.NONE) {
      return this.filteredTransactions.slice().sort(Sorts.text((tx: TxDatum) => tx.category, this.catSortOrder));
    }

    if (this.dateSortOrder !== SortOrder.NONE) {
      return this.filteredTransactions.slice().sort(Sorts.date((tx: TxDatum) => tx.date, this.dateSortOrder));
    }

    if (this.pfSortOrder !== SortOrder.NONE) {
      return this.filteredTransactions.slice().sort(Sorts.text((tx: TxDatum) => tx.wallet, this.pfSortOrder));
    }

    return this.filteredTransactions;
  }

oliverlj avatar Dec 01 '21 15:12 oliverlj

works good on v3

oliverlj avatar Jan 08 '22 11:01 oliverlj