Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No rerender on a @tracked array update #340

Open
oliverlj opened this issue Nov 28, 2021 · 3 comments
Open

No rerender on a @tracked array update #340

oliverlj opened this issue Nov 28, 2021 · 3 comments

Comments

@oliverlj
Copy link

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

@oliverlj oliverlj changed the title No rerender on a @tracked array No rerender on a @tracked array update Nov 28, 2021
@paulyoder
Copy link

@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];
}

@oliverlj
Copy link
Author

oliverlj commented Dec 1, 2021

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
Copy link
Author

oliverlj commented Jan 8, 2022

works good on v3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants