Skip to content

Commit

Permalink
fix: reuse code to avoid duplication (code climate)
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrik Kullman authored and cristinecula committed Apr 15, 2020
1 parent 174cdd4 commit 0f6f38d
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 101 deletions.
2 changes: 1 addition & 1 deletion cosmoz-data-nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class CosmozDataNav extends translatable(mixinBehaviors([IronResizableBehavior],
<template id="incompleteTemplate">
<cosmoz-bottom-bar-view active incomplete class="fit">
<div slot="scroller-content" class="flex layout horizontal center-justified center">
<paper-spinner-lite active=""></paper-spinner-lite>
<paper-spinner-lite active></paper-spinner-lite>
<div style="margin-left: 10px">
<h3><span>[[ _('Data is updating', t) ]]</span></h3>
</div>
Expand Down
59 changes: 21 additions & 38 deletions demo/helpers/cosmoz-demo-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,31 @@ import '@polymer/iron-flex-layout/iron-flex-layout-classes';
import { PolymerElement } from '@polymer/polymer/polymer-element';
import { html } from '@polymer/polymer/lib/utils/html-tag';

class CosmozDemoView extends PolymerElement {
import {
dataNavUserMixin
} from '../../test/helpers/utils.js';

class CosmozDemoView extends dataNavUserMixin(PolymerElement) {
static get template() {
return html`
<style>
.text {
font-size: 300px;
line-height: 360px;
text-align: center;
}
</style>
<div class="flex text">{{ item.id }}</div>
<div>
<paper-icon-button slot="actions" disabled$="[[ prevDisabled ]]" icon="chevron-left" cosmoz-data-nav-select="-1"></paper-icon-button>
<span>[[ index ]]</span>
<paper-icon-button slot="actions" disabled$="[[ nextDisabled ]]" icon="chevron-right" cosmoz-data-nav-select="+1"></paper-icon-button>
<paper-icon-button icon="refresh" on-tap="onReplace">Replace</paper-icon-button>
</div>
`;
}

static get is() {
return 'cosmoz-demo-view';
}
static get properties() {
return {
item: {
type: Object,
notify: true
},
index: {
type: Number
},
prevDisabled: {
type: Boolean
},
nextDisabled: {
type: Boolean
}
};
<style>
.text {
font-size: 300px;
line-height: 360px;
text-align: center;
}
</style>
<div class="flex text">[[ item.id ]]</div>
<div>
<paper-icon-button slot="actions" disabled$="[[ prevDisabled ]]" icon="chevron-left" cosmoz-data-nav-select="-1"></paper-icon-button>
<span>[[ index ]]</span>
<paper-icon-button slot="actions" disabled$="[[ nextDisabled ]]" icon="chevron-right" cosmoz-data-nav-select="+1"></paper-icon-button>
<paper-icon-button icon="refresh" on-tap="onReplace">Replace</paper-icon-button>
</div>
`;
}
onReplace() {
this.item = { id: '--' };
}
}
customElements.define(CosmozDemoView.is, CosmozDemoView);
customElements.define('cosmoz-demo-view', CosmozDemoView);
44 changes: 2 additions & 42 deletions test/helpers/cosmoz-data-nav-resizable-view.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,9 @@
import '@polymer/paper-icon-button/paper-icon-button';
import '@polymer/iron-flex-layout/iron-flex-layout';
import '@polymer/iron-flex-layout/iron-flex-layout-classes';

import { PolymerElement } from '@polymer/polymer/polymer-element';
import { html } from '@polymer/polymer/lib/utils/html-tag';

import { mixinBehaviors } from '@polymer/polymer/lib/legacy/class';
import { IronResizableBehavior } from '@polymer/iron-resizable-behavior/iron-resizable-behavior';

class CosmozDataNavResizableView extends mixinBehaviors([IronResizableBehavior], PolymerElement) {
static get template() {
return html`
<style>
.text {
font-size: 300px;
line-height: 360px;
text-align: center;
}
</style>
<div class="flex text">{{ item.id }}</div>
<div>
<paper-icon-button slot="actions" disabled$="[[ prevDisabled ]]" icon="chevron-left" cosmoz-data-nav-select="-1"></paper-icon-button>
<span>[[ index ]]</span>
<paper-icon-button slot="actions" disabled$="[[ nextDisabled ]]" icon="chevron-right" cosmoz-data-nav-select="+1"></paper-icon-button>
</div>
`;
}
import { CosmozDataNavTestView } from './cosmoz-data-nav-test-view.js';

static get properties() {
return {
item: {
type: Object,
notify: true
},
index: {
type: Number
},
prevDisabled: {
type: Boolean
},
nextDisabled: {
type: Boolean
}
};
}
class CosmozDataNavResizableView extends mixinBehaviors([IronResizableBehavior], CosmozDataNavTestView) {
ready() {
this.addEventListener('iron-resize', this._onIronResize);
super.ready();
Expand Down
30 changes: 10 additions & 20 deletions test/helpers/cosmoz-data-nav-test-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import '@polymer/iron-flex-layout/iron-flex-layout-classes';
import { PolymerElement } from '@polymer/polymer/polymer-element';
import { html } from '@polymer/polymer/lib/utils/html-tag';

class CosmozDataNavTestView extends PolymerElement {
import {
dataNavUserMixin
} from './utils.js';

class CosmozDataNavTestView extends dataNavUserMixin(PolymerElement) {
static get template() {
return html`
<style>
Expand All @@ -15,31 +19,17 @@ class CosmozDataNavTestView extends PolymerElement {
text-align: center;
}
</style>
<div class="flex text">{{ item.id }}</div>
<div class="flex text">[[ item.id ]]</div>
<div>
<paper-icon-button slot="actions" disabled$="[[ prevDisabled ]]" icon="chevron-left" cosmoz-data-nav-select="-1"></paper-icon-button>
<span>[[ index ]]</span>
<paper-icon-button slot="actions" disabled$="[[ nextDisabled ]]" icon="chevron-right" cosmoz-data-nav-select="+1"></paper-icon-button>
</div>
`;
}

static get properties() {
return {
item: {
type: Object,
notify: true
},
index: {
type: Number
},
prevDisabled: {
type: Boolean
},
nextDisabled: {
type: Boolean
}
};
}
}
customElements.define('cosmoz-data-nav-test-view', CosmozDataNavTestView);

export {
CosmozDataNavTestView
};
22 changes: 22 additions & 0 deletions test/helpers/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { html } from '@open-wc/testing';
import '@polymer/polymer/lib/elements/custom-style.js';
import '@polymer/iron-flex-layout/iron-flex-layout.js';
import '@polymer/iron-flex-layout/iron-flex-layout-classes.js';

export const
flushRenderQueue = nav => {
Expand All @@ -8,6 +11,25 @@ export const
},
selectedSlide = nav => nav.querySelector('div.selected .slide'),
isVisible = el => Boolean(el.offsetHeight || el.offsetWidth),
dataNavUserMixin = baseClass => class extends baseClass {
static get properties() {
return {
item: {
type: Object,
notify: true
},
index: {
type: Number
},
prevDisabled: {
type: Boolean
},
nextDisabled: {
type: Boolean
}
};
}
},
customStyle = html`
<custom-style>
<style include="iron-flex iron-positioning">
Expand Down

0 comments on commit 0f6f38d

Please sign in to comment.