Skip to content

Commit

Permalink
CPs using filterBy should also be dependent on the array size (#220)
Browse files Browse the repository at this point in the history
  • Loading branch information
offirgolan authored Oct 12, 2016
1 parent 4cbcb96 commit d0b972b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion addon/classes/Column.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export default class Column extends Ember.Object.extend({
* @type {Array}
* @private
*/
visibleSubColumns: computed('subColumns.@each.hidden', 'hidden', function() {
visibleSubColumns: computed('subColumns.[]', 'subColumns.@each.hidden', 'hidden', function() {
let subColumns = this.get('subColumns');
return isEmpty(subColumns) || this.get('hidden') ? [] : subColumns.filterBy('hidden', false);
}).readOnly()
Expand Down
26 changes: 16 additions & 10 deletions addon/classes/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ const {
A: emberArray
} = Ember;

function filterBy(dependentKey, propertyKey, value) {
return computed(`${dependentKey}.[]`, `${dependentKey}.@each.${propertyKey}`, function() {
return emberArray(this.get(dependentKey).filterBy(propertyKey, value));
});
}

const RowSyncArrayProxy = SyncArrayProxy.extend({
serializeContentObjects(objects) {
return Table.createRows(objects);
Expand Down Expand Up @@ -56,55 +62,55 @@ export default class Table extends Ember.Object.extend({
* @property expandedRows
* @type {Ember.Array}
*/
expandedRows: computed.filterBy('rows', 'expanded', true).readOnly(),
expandedRows: filterBy('rows', 'expanded', true).readOnly(),

/**
* @property selectedRows
* @type {Ember.Array}
*/
selectedRows: computed.filterBy('rows', 'selected', true).readOnly(),
selectedRows: filterBy('rows', 'selected', true).readOnly(),

/**
* @property visibleRows
* @type {Ember.Array}
*/
visibleRows: computed.filterBy('rows', 'hidden', false).readOnly(),
visibleRows: filterBy('rows', 'hidden', false).readOnly(),

/**
* @property sortableColumns
* @type {Ember.Array}
*/
sortableColumns: computed.filterBy('visibleColumns', 'sortable', true).readOnly(),
sortableColumns: filterBy('visibleColumns', 'sortable', true).readOnly(),

/**
* @property sortedColumns
* @type {Ember.Array}
*/
sortedColumns: computed.filterBy('visibleColumns', 'sorted', true).readOnly(),
sortedColumns: filterBy('visibleColumns', 'sorted', true).readOnly(),

/**
* @property hideableColumns
* @type {Ember.Array}
*/
hideableColumns: computed.filterBy('allColumns', 'hideable', true).readOnly(),
hideableColumns: filterBy('allColumns', 'hideable', true).readOnly(),

/**
* @property hiddenColumns
* @type {Ember.Array}
*/
hiddenColumns: computed.filterBy('allColumns', 'hidden', true).readOnly(),
hiddenColumns: filterBy('allColumns', 'hidden', true).readOnly(),

/**
* @property visibleColumns
* @type {Ember.Array}
*/
visibleColumns: computed.filterBy('allColumns', 'hidden', false).readOnly(),
visibleColumns: filterBy('allColumns', 'hidden', false).readOnly(),

/**
* @property visibleColumnGroups
* @type {Ember.Array}
*/
visibleColumnGroups: computed('columns.@each.{hidden,isVisibleGroupColumn}', function() {
visibleColumnGroups: computed('columns.[]', 'columns.@each.{hidden,isVisibleGroupColumn}', function() {
return emberArray(this.get('columns').reduce((arr, c) => {
if (c.get('isVisibleGroupColumn') || (!c.get('isGroupColumn') && !c.get('hidden'))) {
arr.push(c);
Expand All @@ -117,7 +123,7 @@ export default class Table extends Ember.Object.extend({
* @property visibleSubColumns
* @type {Ember.Array}
*/
visibleSubColumns: computed('columns.@each.visibleSubColumns', function() {
visibleSubColumns: computed('columns.[]', 'columns.@each.visibleSubColumns', function() {
return emberArray([].concat(...this.get('columns').getEach('visibleSubColumns')));
}).readOnly(),

Expand Down

0 comments on commit d0b972b

Please sign in to comment.