Skip to content

Commit

Permalink
Always use Ember object get.
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
blimmer committed Jul 13, 2016
1 parent 6d3b7e1 commit 4b5131d
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 111 deletions.
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'));
}
}
});
58 changes: 30 additions & 28 deletions tests/dummy/snippets/simple-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,7 +68,7 @@ export default Ember.Component.extend({
sort: column.get('valuePath'),
page: 1
});
this.table.setRows([]);
this.get('table').setRows([]);
this.fetchRecords();
}
}
Expand Down

0 comments on commit 4b5131d

Please sign in to comment.