Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimize CPs #691

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions addon/components/-private/row-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ export default Component.extend({
},

destroy() {
this._cells.forEach(cell => cell.destroy());
for (let cell of this._cells) {
cell.destroy();
}

this._super(...arguments);
},
Expand Down Expand Up @@ -114,7 +116,8 @@ export default Component.extend({
}
}

_cells.forEach((cell, i) => {
for (let i = 0; i < this._cells.length; i++) {
let cell = this._cells[i];
let columnValue = objectAt(columns, i);
let columnMeta = this.get('columnMetaCache').get(columnValue);

Expand All @@ -128,7 +131,7 @@ export default Component.extend({
rowValue,
rowsCount,
});
});
}

return _cells;
}
Expand Down
60 changes: 22 additions & 38 deletions addon/components/ember-td/component.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import BaseTableCell from '../-private/base-table-cell';

import { computed } from '@ember/object';
import { alias, readOnly } from '@ember/object/computed';

import layout from './template';
import { SELECT_MODE } from '../../-private/collapse-tree';

Expand Down Expand Up @@ -66,32 +63,13 @@ export default BaseTableCell.extend({
return this.get('api.api') || this.get('api');
}),

cellValue: alias('unwrappedApi.cellValue'),

cellMeta: readOnly('unwrappedApi.cellMeta'),

columnValue: readOnly('unwrappedApi.columnValue'),

columnMeta: readOnly('unwrappedApi.columnMeta'),

rowValue: readOnly('unwrappedApi.rowValue'),

rowMeta: readOnly('unwrappedApi.rowMeta'),

rowsCount: readOnly('unwrappedApi.rowsCount'),

rowSelectionMode: readOnly('unwrappedApi.rowSelectionMode'),

checkboxSelectionMode: readOnly('unwrappedApi.checkboxSelectionMode'),

canCollapse: readOnly('rowMeta.canCollapse'),

depthClass: computed('rowMeta.depth', function() {
return `depth-${this.get('rowMeta.depth')}`;
depthClass: computed('unwrappedApi.rowMeta.depth', function() {
return `depth-${this.get('unwrappedApi.rowMeta.depth')}`;
}),

canSelect: computed('shouldShowCheckbox', 'rowSelectionMode', function() {
let rowSelectionMode = this.get('rowSelectionMode');
canSelect: computed('shouldShowCheckbox', 'unwrappedApi.rowSelectionMode', function() {
let unwrappedApi = this.get('unwrappedApi');
let rowSelectionMode = unwrappedApi.get('rowSelectionMode');
let shouldShowCheckbox = this.get('shouldShowCheckbox');

return (
Expand All @@ -101,8 +79,9 @@ export default BaseTableCell.extend({
);
}),

shouldShowCheckbox: computed('checkboxSelectionMode', function() {
let checkboxSelectionMode = this.get('checkboxSelectionMode');
shouldShowCheckbox: computed('unwrappedApi.checkboxSelectionMode', function() {
let unwrappedApi = this.get('unwrappedApi');
let checkboxSelectionMode = unwrappedApi.get('checkboxSelectionMode');

return (
checkboxSelectionMode === SELECT_MODE.MULTIPLE || checkboxSelectionMode === SELECT_MODE.SINGLE
Expand All @@ -111,8 +90,10 @@ export default BaseTableCell.extend({

actions: {
onSelectionToggled(event) {
let rowMeta = this.get('rowMeta');
let checkboxSelectionMode = this.get('checkboxSelectionMode') || this.get('rowSelectionMode');
let unwrappedApi = this.get('unwrappedApi');
let rowMeta = unwrappedApi.get('rowMeta');
let checkboxSelectionMode =
unwrappedApi.get('checkboxSelectionMode') || unwrappedApi.get('rowSelectionMode');

if (rowMeta && checkboxSelectionMode === SELECT_MODE.MULTIPLE) {
let toggle = true;
Expand All @@ -127,7 +108,8 @@ export default BaseTableCell.extend({
},

onCollapseToggled() {
let rowMeta = this.get('rowMeta');
let unwrappedApi = this.get('unwrappedApi');
let rowMeta = unwrappedApi.get('rowMeta');

rowMeta.toggleCollapse();

Expand All @@ -149,14 +131,16 @@ export default BaseTableCell.extend({
return;
}

let cellValue = this.get('cellValue');
let cellMeta = this.get('cellMeta');
let { unwrappedApi } = this;

let cellValue = unwrappedApi.get('cellValue');
let cellMeta = unwrappedApi.get('cellMeta');

let columnValue = this.get('columnValue');
let columnMeta = this.get('columnMeta');
let columnValue = unwrappedApi.get('columnValue');
let columnMeta = unwrappedApi.get('columnMeta');

let rowValue = this.get('rowValue');
let rowMeta = this.get('rowMeta');
let rowValue = unwrappedApi.get('rowValue');
let rowMeta = unwrappedApi.get('rowMeta');

Object.assign(values, {
cellValue,
Expand Down
14 changes: 7 additions & 7 deletions addon/components/ember-td/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
>
{{-ember-table-private/simple-checkbox
data-test-select-row=true
checked=rowMeta.isGroupSelected
checked=unwrappedApi.rowMeta.isGroupSelected
onClick=(action "onSelectionToggled")
ariaLabel="Select row"
}}
<span></span>
</span>
{{/if}}

{{#if canCollapse}}
{{#if unwrappedApi.rowMeta.canCollapse}}
<span class="et-toggle-collapse et-depth-indent {{depthClass}}">
{{-ember-table-private/simple-checkbox
data-test-collapse-row=true
checked=rowMeta.isCollapsed
checked=unwrappedApi.rowMeta.isCollapsed
onChange=(action "onCollapseToggled")
ariaLabel="Collapse row"
}}
Expand All @@ -31,16 +31,16 @@

<div class="et-cell-content">
{{#if hasBlock}}
{{yield cellValue columnValue rowValue cellMeta columnMeta rowMeta rowsCount}}
{{yield unwrappedApi.cellValue unwrappedApi.columnValue unwrappedApi.rowValue unwrappedApi.cellMeta unwrappedApi.columnMeta unwrappedApi.rowMeta unwrappedApi.rowsCount}}
{{else}}
{{cellValue}}
{{unwrappedApi.cellValue}}
{{/if}}
</div>
</div>
{{else}}
{{#if hasBlock}}
{{yield cellValue columnValue rowValue cellMeta columnMeta rowMeta rowsCount}}
{{yield unwrappedApi.cellValue unwrappedApi.columnValue unwrappedApi.rowValue unwrappedApi.cellMeta unwrappedApi.columnMeta unwrappedApi.rowMeta unwrappedMeta.rowsCount}}
{{else}}
{{cellValue}}
{{unwrappedApi.cellValue}}
{{/if}}
{{/if}}
28 changes: 10 additions & 18 deletions addon/components/ember-tr/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,32 +72,23 @@ export default Component.extend({
*/
onDoubleClick: null,

rowValue: readOnly('api.rowValue'),
isSelected: readOnly('api.rowMeta.isSelected'),

rowMeta: readOnly('api.rowMeta'),
isGroupSelected: readOnly('api.rowMeta.isGroupSelected'),

cells: readOnly('api.cells'),

rowSelectionMode: readOnly('api.rowSelectionMode'),

isHeader: readOnly('api.isHeader'),

isSelected: readOnly('rowMeta.isSelected'),

isGroupSelected: readOnly('rowMeta.isGroupSelected'),

isSelectable: computed('rowSelectionMode', function() {
let rowSelectionMode = this.get('rowSelectionMode');
isSelectable: computed('api.rowSelectionMode', function() {
let rowSelectionMode = this.get('api').rowSelectionMode;

return rowSelectionMode === SELECT_MODE.MULTIPLE || rowSelectionMode === SELECT_MODE.SINGLE;
}),

click(event) {
let rowSelectionMode = this.get('rowSelectionMode');
let api = this.get('api');
let rowSelectionMode = api.rowSelectionMode;
let inputParent = closest(event.target, 'input, button, label, a, select');

if (!inputParent) {
let rowMeta = this.get('rowMeta');
let rowMeta = api.rowMeta;

if (rowMeta && rowSelectionMode === SELECT_MODE.MULTIPLE) {
let toggle = event.ctrlKey || event.metaKey;
Expand All @@ -117,8 +108,9 @@ export default Component.extend({
},

sendEventAction(action, event) {
let rowValue = this.get('rowValue');
let rowMeta = this.get('rowMeta');
let api = this.get('api');
let rowValue = api.rowValue;
let rowMeta = api.rowMeta;

let closureAction = this[action];

Expand Down
42 changes: 21 additions & 21 deletions addon/components/ember-tr/template.hbs
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
{{#each cells as |api|}}
{{#each api.cells as |cellApi|}}
{{#if hasBlock}}
{{#if isHeader}}
{{#if api.isHeader}}
{{yield (hash
columnValue=api.columnValue
columnMeta=api.columnMeta
columnValue=cellApi.columnValue
columnMeta=cellApi.columnMeta

sorts=api.sorts
sendUpdateSort=api.sendUpdateSort
sorts=cellApi.sorts
sendUpdateSort=cellApi.sendUpdateSort

rowMeta=api.rowMeta
rowsCount=api.rowsCount
rowMeta=cellApi.rowMeta
rowsCount=cellApi.rowsCount

cell=(component "ember-th" api=api)
cell=(component "ember-th" api=cellApi)
)}}
{{else}}
{{yield (hash
api=api
api=cellApi

cellValue=api.cellValue
cellMeta=api.cellMeta
cellValue=cellApi.cellValue
cellMeta=cellApi.cellMeta

columnValue=api.columnValue
columnMeta=api.columnMeta
columnValue=cellApi.columnValue
columnMeta=cellApi.columnMeta

rowValue=api.rowValue
rowMeta=api.rowMeta
rowValue=cellApi.rowValue
rowMeta=cellApi.rowMeta

rowsCount=api.rowsCount
rowsCount=cellApi.rowsCount

cell=(component "ember-td" api=api)
cell=(component "ember-td" api=cellApi)
)}}
{{/if}}
{{else if isHeader}}
{{ember-th api=api}}
{{else if api.isHeader}}
{{ember-th api=cellApi}}
{{else}}
{{ember-td api=api}}
{{ember-td api=cellApi}}
{{/if}}
{{/each}}