@andrew1 wrote:
I'm sorting an array of objects in my app and some of the parameters are sorted alphabetically, while others are sorted as integers:
_sortedContent: Ember.computed( '_alphaSortedContent', '_intSortedContent', '_sortKey', '_sortOrder', function () { console.log('_sortedContent'); let columns = Ember.get(this, 'columns'); let sortKey = Ember.get(this, '_sortKey'); let selectedColumn = Ember.A(columns).findBy('propertyName', sortKey); if (typeof selectedColumn === 'undefined' || typeof sortKey === 'undefined') { return Ember.get(this, 'content'); } switch (Ember.get(selectedColumn, 'sortType')) { case 'int': console.log('_intSortedContent'); return Ember.get(this, '_intSortedContent'); default: return Ember.get(this, '_alphaSortedContent'); } } ), _alphaSortedContent: Ember.computed.sort('content', '_sortDefinition'), _intSortedContent: Ember.computed.sort('content', function (a, b) { let aSortKey = parseInt(Ember.get(a, Ember.get(this, '_sortKey'))); let bSortKey = parseInt(Ember.get(b, Ember.get(this, '_sortKey'))); let sortOrder = Ember.get(this, '_sortOrder'); if (aSortKey > bSortKey) { console.log(`aSortKey:${aSortKey}, bSortKey:${bSortKey}, sortOrder:${sortOrder}`); console.log('greater than'); return (sortOrder === 'asc') ? 1 : -1; } else if (aSortKey < bSortKey) { console.log(`aSortKey:${aSortKey}, bSortKey:${bSortKey}, sortOrder:${sortOrder}`); console.log('less than'); return (sortOrder === 'asc') ? -1 : 1; } return 0; } ),
The
_alphaSortedContent
works fine and I can toggle betweenasc
anddesc
(_sortDefinition
is a computed property on_sortKey
and_sortOrder
so it changes when_sortOrder
changes). But, the_intSortedContent
won't update when_sortOrder
changes fromasc
todesc
._sortedContent
is being fired and it calls_intSortedContent
but it looks like_intSortedContent
is then returning a cached copy rather than recalculating.What's the best way to invalidate the cache of
intSortedContent
?Thanks!
Posts: 5
Participants: 2