Skip to content

Commit

Permalink
(wip) templatize
Browse files Browse the repository at this point in the history
  • Loading branch information
cristinecula authored and megheaiulian committed Mar 16, 2019
1 parent cc7f8d4 commit 7d7a37a
Show file tree
Hide file tree
Showing 11 changed files with 28,306 additions and 21,512 deletions.
49,367 changes: 28,092 additions & 21,275 deletions analysis.json

Large diffs are not rendered by default.

85 changes: 2 additions & 83 deletions cosmoz-omnitable-column-mixin.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<link rel="import" href="../shadycss/apply-shim.html"/>
<link rel="import" href="cosmoz-omnitable-templatize-mixin.html" />
<link rel="import" href="../polymer/lib/utils/mixin.html"/>

<link rel="import" href="cosmoz-omnitable-templatizer.html" />

<script>
window.Cosmoz = window.Cosmoz || {};
Expand All @@ -10,7 +10,7 @@
* @polymer
* @mixinFunction
*/
Cosmoz.OmnitableColumnMixin = Polymer.dedupingMixin(base => class extends base {
Cosmoz.OmnitableColumnMixin = Polymer.dedupingMixin(base => class extends Cosmoz.OmnitableTemplatizeMixin(base) {
static get properties() {
return {
title: {
Expand Down Expand Up @@ -185,10 +185,6 @@
value: 0
},

cellTemplate: {
type: Object,
observer: '_cellTemplateChanged'
},
/**
* Cell title function, can be overriden.
*/
Expand Down Expand Up @@ -223,16 +219,6 @@
type: String,
computed: '_computePreferredDropdownHorizontalAlign(columnIndex)'
},

_dataTemplatizer: {
type: Object,
value: null
},

_headerTemplatizer: {
type: Object,
value: null
}
};
}

Expand All @@ -245,42 +231,9 @@

ready() {
super.ready();
this._headerTemplatizer = this._createTemplatizer('template.header');
this._itemCells = [];
}

_createTemplatizer(templateElementOrSelector) {
let template,
templateHost,
root;
if (templateElementOrSelector instanceof HTMLTemplateElement) {
template = templateElementOrSelector;
templateHost = templateElementOrSelector.parentNode;
} else {
template = this.querySelector(templateElementOrSelector);
if (template) {
root = this.getRootNode();
} else {
root = this.getRootNode();
template = this.root.querySelector(templateElementOrSelector);
}
if (root) {
templateHost = root.host;
}
}

const templatizer = document.createElement('cosmoz-omnitable-templatizer');
this.appendChild(templatizer);
templatizer.init(template, templateHost);
return templatizer;
}

_cellTemplateChanged(cellTemplate) {
if (cellTemplate != null) {
this._cellTemplatizer = this._createTemplatizer(cellTemplate);
}
}

_externalValuesChanged(newExternalValuesValue) {
if (newExternalValuesValue) {
return;
Expand All @@ -294,36 +247,6 @@
}));
}

get editableTemplatizer() {
return this._editableTemplatizer = this._editableTemplatizer ||
this._createTemplatizer('template.edit-cell');
}
get cellTemplatizer() {
return this._cellTemplatizer = this._cellTemplatizer ||
this._createTemplatizer('template.cell');
}

get dataTemplatizer() {
return this.editable ? this.editableTemplatizer : this.cellTemplatizer;
}

get headerTemplatizer() {
return this._headerTemplatizer;
}

getHeaderTemplateInstance() {
if (!this._headerTemplatizer || !this._headerTemplatizer.createInstance) {
return;
}
return this._headerTemplatizer.createInstance();
}

releaseHeaderTemplateInstance(instance) {
if (this._headerTemplatizer) {
this._headerTemplatizer.releaseInstance(instance);
}
}

/**
* Override this in column elements if you need a different default width
*/
Expand Down Expand Up @@ -462,10 +385,6 @@
}

_editableChanged() {
const prevTemplatizer = this.editable ? this._cellTemplatizer : this._editableTemplatizer;
if (prevTemplatizer) {
prevTemplatizer.releaseInstances();
}
this.dispatchEvent(new CustomEvent('cosmoz-column-editable-changed', {bubbles: true, detail: { column: this }}));
}

Expand Down
8 changes: 4 additions & 4 deletions cosmoz-omnitable-group-row.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@
this.columns = [newColumn];
}

_getTemplateInstance(column) {
return column.dataTemplatizer.getInstance();
_getTemplateInstance(column, props) {
return column.getTemplateInstance(Cosmoz.OmnitableTemplatizeMixin.CELL_TEMPLATE, props);
}

_detachTemplateInstance(instance, column, element) {
column.dataTemplatizer.detachInstance(instance, element);
_detachTemplateInstance(instance, column) {
column.detachTemplateInstance(instance);
}

_configureTemplateInstance(instance) {
Expand Down
10 changes: 4 additions & 6 deletions cosmoz-omnitable-header-row.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,12 @@
return 'header-cell';
}

_getTemplateInstance(column) {
return column.headerTemplatizer.getInstance();
_getTemplateInstance(column, props) {
return column.getTemplateInstance(Cosmoz.OmnitableTemplatizeMixin.HEADER_TEMPLATE, props);
}

_detachTemplateInstance(instance, column, element) {
if (column.headerTemplatizer) {
column.headerTemplatizer.detachInstance(instance, element);
}
_detachTemplateInstance(instance, column) {
column.detachTemplateInstance(instance);
}

_configureElement(element, column) {
Expand Down
8 changes: 4 additions & 4 deletions cosmoz-omnitable-item-expand.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@
return 'item-expand-line';
}

_getTemplateInstance(column) {
return column.dataTemplatizer.getInstance();
_getTemplateInstance(column, props) {
return column.getTemplateInstance(Cosmoz.OmnitableTemplatizeMixin.CELL_TEMPLATE, props);
}

_detachTemplateInstance(instance, column, element) {
column.dataTemplatizer.detachInstance(instance, element);
_detachTemplateInstance(instance, column) {
column.detachTemplateInstance(instance);
}

_configureElement(element, column) {
Expand Down
8 changes: 4 additions & 4 deletions cosmoz-omnitable-item-row.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@
return 'item-cell';
}

_getTemplateInstance(column) {
return column.dataTemplatizer.getInstance();
_getTemplateInstance(column, props) {
return column.getTemplateInstance(column.editable ? Cosmoz.OmnitableTemplatizeMixin.EDIT_TEMPLATE : Cosmoz.OmnitableTemplatizeMixin.CELL_TEMPLATE, props);
}

_detachTemplateInstance(instance, column, element) {
column.dataTemplatizer.detachInstance(instance, element);
_detachTemplateInstance(instance, column) {
column.detachTemplateInstance(instance);
}

_configureElement(element, column) {
Expand Down
5 changes: 2 additions & 3 deletions cosmoz-omnitable-repeater-mixin.html
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,10 @@

_addElements(start, count) {
const end = start + count;

for (let i = start; i < end; i++) {
const column = this.columns[i],
element = document.createElement(this._elementType),
instance = this._getTemplateInstance(column);
instance = this._getTemplateInstance(column, {item: this.item});
element.__instance = instance;
element.__column = column;

Expand Down Expand Up @@ -205,7 +204,7 @@
this._elements
.splice(start, removedColumns.length)
.forEach(element => {
this._detachTemplateInstance(element.__instance, element.__column, element);
this._detachTemplateInstance(element.__instance, element.__column);
element.__instance = element.__column = element.column = null;
this.removeChild(element);
});
Expand Down
Loading

0 comments on commit 7d7a37a

Please sign in to comment.