Skip to content

Commit

Permalink
Start converting to classic classes (#677)
Browse files Browse the repository at this point in the history
* Start converting to classic classes

* Finish up conversion and convert TBody
  • Loading branch information
RobbieTheWagner authored and pzuraq committed Apr 11, 2019
1 parent 878194c commit 90f07d8
Show file tree
Hide file tree
Showing 5 changed files with 194 additions and 164 deletions.
37 changes: 37 additions & 0 deletions addon/-private/utils/default-to.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { computed } from '@ember/object';

let VALUES = new WeakMap();

function valuesFor(obj) {
if (!VALUES.has(obj)) {
VALUES.set(obj, Object.create(null));
}

return VALUES.get(obj);
}

export default function defaultTo(defaultValue) {
return computed({
get(key) {
let values = valuesFor(this);

if (!(key in values)) {
values[key] = typeof defaultValue === 'function' ? defaultValue() : defaultValue;
}

return defaultValue;
},

set(key, value) {
let values = valuesFor(this);

if (value === undefined) {
values[key] = typeof defaultValue === 'function' ? defaultValue() : defaultValue;
} else {
values[key] = value;
}

return values[key];
},
});
}
49 changes: 19 additions & 30 deletions addon/components/ember-table/component.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import Component from '@ember/component';
import { computed } from '@ember/object';
import { htmlSafe } from '@ember/string';

import { computed } from '@ember-decorators/object';
import { attribute, classNames } from '@ember-decorators/component';
import { service } from '@ember-decorators/service';
import { inject as service } from '@ember/service';

import {
setupLegacyStickyPolyfill,
Expand Down Expand Up @@ -35,22 +33,15 @@ import layout from './template';
@yield {Component} t.body - The table body component
@yield {Component} t.foot - The table footer component
*/
@classNames('ember-table')
export default class EmberTable extends Component {
@service
userAgent;

@attribute('data-test-ember-table')
dataTestEmberTable = true;

init() {
super.init(...arguments);
export default Component.extend({
layout,
classNames: ['ember-table'],
userAgent: service(),

this.layout = layout;
}
'data-test-ember-table': true,

didInsertElement() {
super.didInsertElement(...arguments);
this._super(...arguments);

let browser = this.get('userAgent.browser');

Expand All @@ -67,7 +58,7 @@ export default class EmberTable extends Component {
setupTableStickyPolyfill(tfoot);
}
}
}
},

willDestroyElement() {
let browser = this.get('userAgent.browser');
Expand All @@ -87,24 +78,22 @@ export default class EmberTable extends Component {
}
}

super.willDestroyElement(...arguments);
}
this._super(...arguments);
},

@computed('tableWidth')
get tableStyle() {
tableStyle: computed('tableWidth', function() {
return htmlSafe(`width: ${this.get('tableWidth')}px;`);
}
}),

@computed
get api() {
api: computed(function() {
return {
columns: null,
registerColumnTree: this.registerColumnTree,
registerColumnTree: this.registerColumnTree.bind(this),
tableId: this.elementId,
};
}
}),

registerColumnTree = columnTree => {
registerColumnTree(columnTree) {
this.set('api.columnTree', columnTree);
};
}
},
});
Loading

0 comments on commit 90f07d8

Please sign in to comment.