Skip to content

Commit

Permalink
[BUGFIX] Always use Ember object get. (#101)
Browse files Browse the repository at this point in the history
In many places, we're currently accessing with this.varName, which
prevents people using computed properties.
  • Loading branch information
Ben Limmer authored and offirgolan committed Jul 14, 2016
1 parent 6d3b7e1 commit a6c3e3b
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 119 deletions.
16 changes: 8 additions & 8 deletions addon/classes/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export default class Table extends Ember.Object.extend({
* @return {Array} columns
*/
setColumns(columns = []) {
return this.columns.setObjects(Table.createColumns(columns));
return this.get('columns').setObjects(Table.createColumns(columns));
}

/**
Expand All @@ -250,7 +250,7 @@ export default class Table extends Ember.Object.extend({
* @param {Object} column
*/
addColumn(column) {
this.columns.addObject(Table.createColumn(column));
this.get('columns').addObject(Table.createColumn(column));
}

/**
Expand All @@ -259,7 +259,7 @@ export default class Table extends Ember.Object.extend({
* @param {Array} columns
*/
addColumns(columns = []) {
this.columns.addObjects(Table.createColumns(columns));
this.get('columns').addObjects(Table.createColumns(columns));
}

/**
Expand All @@ -270,7 +270,7 @@ export default class Table extends Ember.Object.extend({
*/
pushColumn(column) {
let _column = Table.createColumn(column);
this.columns.pushObject(_column);
this.get('columns').pushObject(_column);
return _column;
}

Expand All @@ -282,7 +282,7 @@ export default class Table extends Ember.Object.extend({
*/
pushColumns(columns = []) {
let _columns = Table.createColumns(columns);
this.columns.pushObjects(_columns);
this.get('columns').pushObjects(_columns);
return _columns;
}

Expand All @@ -295,7 +295,7 @@ export default class Table extends Ember.Object.extend({
*/
insertColumnAt(index, column) {
let _column = Table.createColumn(column);
this.columns.insertAt(index, _column);
this.get('columns').insertAt(index, _column);
return _column;
}

Expand All @@ -305,7 +305,7 @@ export default class Table extends Ember.Object.extend({
* @param {Object} column
*/
removeColumn(column) {
return this.columns.removeObject(column);
return this.get('columns').removeObject(column);
}

/**
Expand All @@ -314,7 +314,7 @@ export default class Table extends Ember.Object.extend({
* @param {Array} columns
*/
removeColumns(columns = []) {
return this.columns.removeObjects(columns);
return this.get('columns').removeObjects(columns);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/dummy/app/controllers/selectable.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ export default TableController.extend({

actions: {
selectAll() {
this.table.rows.setEach('selected', true);
this.get('table.rows').setEach('selected', true);
},

deselectAll() {
this.table.get('selectedRows').setEach('selected', false);
this.get('table.selectedRows').setEach('selected', false);
},

deleteAll() {
this.table.removeRows(this.table.get('selectedRows'));
this.get('table').removeRows(this.get('table.selectedRows'));
}
}
});
4 changes: 2 additions & 2 deletions tests/dummy/app/controllers/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default Ember.Controller.extend({
fetchRecords() {
this.set('isLoading', true);
this.store.query('user', this.getProperties(['page', 'limit', 'sort', 'dir'])).then(records => {
this.table.addRows(records);
this.get('table').addRows(records);
this.set('isLoading', false);
this.set('canLoadMore', !isEmpty(records));
});
Expand All @@ -44,7 +44,7 @@ export default Ember.Controller.extend({
sort: column.get('valuePath'),
page: 1
});
this.table.setRows([]);
this.get('table').setRows([]);
this.fetchRecords();
}
}
Expand Down
24 changes: 13 additions & 11 deletions tests/dummy/snippets/expandable-table.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Ember from 'ember';
import Table from 'ember-light-table';

const { isEmpty } = Ember;
const { isEmpty, computed } = Ember;

export default Ember.Component.extend({
page: 1,
Expand All @@ -12,23 +12,25 @@ export default Ember.Component.extend({
isLoading: false,
canLoadMore: true,

columns: [{
label: 'First Name',
valuePath: 'firstName'
}, {
label: 'Last Name',
valuePath: 'lastName'
}],
columns: computed(function() {
return [{
label: 'First Name',
valuePath: 'firstName'
}, {
label: 'Last Name',
valuePath: 'lastName'
}];
}),

init() {
this._super(...arguments);
this.set('table', new Table(this.columns));
this.set('table', new Table(this.get('columns')));
},

fetchRecords() {
this.set('isLoading', true);
this.get('store').query('user', this.getProperties(['page', 'limit', 'sort', 'dir'])).then(records => {
this.table.addRows(records);
this.get('table').addRows(records);
this.set('isLoading', false);
this.set('canLoadMore', !isEmpty(records));
});
Expand All @@ -49,7 +51,7 @@ export default Ember.Component.extend({
sort: column.get('valuePath'),
page: 1
});
this.table.setRows([]);
this.get('table').setRows([]);
this.fetchRecords();
}
}
Expand Down
74 changes: 38 additions & 36 deletions tests/dummy/snippets/grouped-table.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Ember from 'ember';
import Table from 'ember-light-table';

const { isEmpty } = Ember;
const { isEmpty, computed } = Ember;

export default Ember.Component.extend({
page: 1,
Expand All @@ -12,50 +12,52 @@ export default Ember.Component.extend({
isLoading: false,
canLoadMore: true,

columns: [{
label: 'User Details',
sortable: false,
align: 'center',
subColumns: [{
label: 'Avatar',
valuePath: 'avatar',
width: '60px',
columns: computed(function() {
return [{
label: 'User Details',
sortable: false,
cellComponent: 'user-avatar'
align: 'center',
subColumns: [{
label: 'Avatar',
valuePath: 'avatar',
width: '60px',
sortable: false,
cellComponent: 'user-avatar'
}, {
label: 'First',
valuePath: 'firstName',
width: '150px'
}, {
label: 'Last',
valuePath: 'lastName',
width: '150px'
}]
}, {
label: 'First',
valuePath: 'firstName',
width: '150px'
}, {
label: 'Last',
valuePath: 'lastName',
width: '150px'
}]
}, {
label: 'Contact Information',
sortable: false,
align: 'center',
subColumns: [{
label: 'Address',
valuePath: 'address'
}, {
label: 'State',
valuePath: 'state'
}, {
label: 'Country',
valuePath: 'country'
}]
}],
label: 'Contact Information',
sortable: false,
align: 'center',
subColumns: [{
label: 'Address',
valuePath: 'address'
}, {
label: 'State',
valuePath: 'state'
}, {
label: 'Country',
valuePath: 'country'
}]
}];
}),

init() {
this._super(...arguments);
this.set('table', new Table(this.columns));
this.set('table', new Table(this.get('columns')));
},

fetchRecords() {
this.set('isLoading', true);
this.get('store').query('user', this.getProperties(['page', 'limit', 'sort', 'dir'])).then(records => {
this.table.addRows(records);
this.get('table').addRows(records);
this.set('isLoading', false);
this.set('canLoadMore', !isEmpty(records));
});
Expand All @@ -76,7 +78,7 @@ export default Ember.Component.extend({
sort: column.get('valuePath'),
page: 1
});
this.table.setRows([]);
this.get('table').setRows([]);
this.fetchRecords();
}
}
Expand Down
64 changes: 33 additions & 31 deletions tests/dummy/snippets/selectable-table.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Ember from 'ember';
import Table from 'ember-light-table';

const { isEmpty } = Ember;
const { isEmpty, computed } = Ember;

export default Ember.Component.extend({
page: 1,
Expand All @@ -12,40 +12,42 @@ export default Ember.Component.extend({
isLoading: false,
canLoadMore: true,

columns: [{
label: 'Avatar',
valuePath: 'avatar',
width: '60px',
sortable: false,
cellComponent: 'user-avatar'
}, {
label: 'First Name',
valuePath: 'firstName',
width: '150px'
}, {
label: 'Last Name',
valuePath: 'lastName',
width: '150px'
}, {
label: 'Address',
valuePath: 'address'
}, {
label: 'State',
valuePath: 'state'
}, {
label: 'Country',
valuePath: 'country'
}],
columns: computed(function() {
return [{
label: 'Avatar',
valuePath: 'avatar',
width: '60px',
sortable: false,
cellComponent: 'user-avatar'
}, {
label: 'First Name',
valuePath: 'firstName',
width: '150px'
}, {
label: 'Last Name',
valuePath: 'lastName',
width: '150px'
}, {
label: 'Address',
valuePath: 'address'
}, {
label: 'State',
valuePath: 'state'
}, {
label: 'Country',
valuePath: 'country'
}];
}),

init() {
this._super(...arguments);
this.set('table', new Table(this.columns));
this.set('table', new Table(this.get('columns')));
},

fetchRecords() {
this.set('isLoading', true);
this.get('store').query('user', this.getProperties(['page', 'limit', 'sort', 'dir'])).then(records => {
this.table.addRows(records);
this.get('table').addRows(records);
this.set('isLoading', false);
this.set('canLoadMore', !isEmpty(records));
});
Expand All @@ -66,21 +68,21 @@ export default Ember.Component.extend({
sort: column.get('valuePath'),
page: 1
});
this.table.setRows([]);
this.get('table').setRows([]);
this.fetchRecords();
}
},

selectAll() {
this.table.rows.setEach('selected', true);
this.get('table').rows.setEach('selected', true);
},

deselectAll() {
this.table.get('selectedRows').setEach('selected', false);
this.get('table.selectedRows').setEach('selected', false);
},

deleteAll() {
this.table.removeRows(this.table.get('selectedRows'));
this.get('table').removeRows(this.get('table.selectedRows'));
}
}
});
Loading

0 comments on commit a6c3e3b

Please sign in to comment.