Skip to content

Commit

Permalink
(patch) item-expand should render the items only when expanded
Browse files Browse the repository at this point in the history
Re #261
  • Loading branch information
cristinecula authored and megheaiulian committed Mar 16, 2019
1 parent b4d9f4e commit ade1f30
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 7 deletions.
5 changes: 5 additions & 0 deletions cosmoz-omnitable-header-row.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@
return 'header-cell';
}

constructor() {
super();
this.trackColumns();
}

/**
* @inheritdoc
*/
Expand Down
10 changes: 9 additions & 1 deletion cosmoz-omnitable-item-expand.html
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,16 @@
this.forwardChange('selected', selected);
}

_expandedChanged(expanded) {
_expandedChanged(expanded, prevValue) {
this.forwardChange('expanded', expanded);

if (expanded) {
this.trackColumns();
this.renderItems();
} else if (prevValue === true) {
this.stopTrackingColumns();
this.destroyItems();
}
}
}
customElements.define(OmnitableItemExpand.is, OmnitableItemExpand);
Expand Down
5 changes: 5 additions & 0 deletions cosmoz-omnitable-item-row.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@
return 'item-cell';
}

constructor() {
super();
this.trackColumns();
}

/**
* @inheritdoc
*/
Expand Down
35 changes: 29 additions & 6 deletions cosmoz-omnitable-repeater-mixin.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,38 @@
};
}

static get observers() {
return [
'_columnsChanged(columns.*)'
];
}

constructor() {
super();
this._elements = [];
this._columnsObserver = null;
}

trackColumns() {
if (this._columnsObserver) {
throw new Error('The columns are already tracked.');
}

this._createMethodObserver('_columnsChanged(columns.*)');

// HACK
this._columnsObserver = this[this.PROPERTY_EFFECT_TYPES.OBSERVE]['columns']
.find(fx => fx.info.methodName === '_columnsChanged');
}

stopTrackingColumns() {
if (!this._columnsObserver) {
throw new Error('The columns were not tracked.');
}
this._removePropertyEffect('columns', this.PROPERTY_EFFECT_TYPES.OBSERVE, this._columnsObserver);
this._columnsObserver = null;
}

renderItems() {
this._addElements(0, this.columns.length);
}

destroyItems() {
this._removeElements(0, this.columns);
}

forwardChange(property, value) {
Expand Down

0 comments on commit ade1f30

Please sign in to comment.