Skip to content

Commit

Permalink
Introduce examples for mixins and string templates
Browse files Browse the repository at this point in the history
  • Loading branch information
stijnkoopal committed Nov 21, 2017
1 parent d972843 commit 1e3bcd9
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 0 deletions.
7 changes: 7 additions & 0 deletions examples/polymer-cli/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
globals: {
Polymer: true,
customElements: true,
CustomEvent: true,
},
};
17 changes: 17 additions & 0 deletions examples/polymer-cli/src/separated-button/separated-button.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<link rel="import" href="../../../../node_modules/@polymer/polymer/polymer-element.html">

<dom-module id="separated-button">
<template>
<button on-click="handleTap">
[[title]] [[counter]]
</button>
</template>
<script>
import { separatedButton } from './separated-button';

class PlaygroundButton extends separatedButton(Polymer.Element) {
}

customElements.define(PlaygroundButton.is, PlaygroundButton);
</script>
</dom-module>
26 changes: 26 additions & 0 deletions examples/polymer-cli/src/separated-button/separated-button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { uselessMixin } from './useless-mixin';

export const separatedButton = superClass =>
class SeparatedButton extends uselessMixin(superClass) {
static get is() {
return 'separated-button';
}

static get properties() {
return {
title: {
type: String,
value: 'Click me:',
},
counter: {
type: Number,
value: 0,
},
};
}

async handleTap() {
this.counter += await Promise.resolve(1);
this.someMethod();
}
};
12 changes: 12 additions & 0 deletions examples/polymer-cli/src/separated-button/useless-mixin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const uselessMixin = superClass =>
class UselessMixin extends superClass {
constructor() {
super();

this.eventType = 'test';
}

someMethod() {
this.dispatchEvent(new CustomEvent(this.eventType, { detail: 'test' }));
}
};
6 changes: 6 additions & 0 deletions examples/polymer-cli/src/stories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import {
import { document } from 'global';
import '../polymer-playground-app.html';
import '../playground-button.html';
import '../separated-button/separated-button.html';
import './storybook-welcome-to-polymer.html';
import { StringTemplateButton } from '../string-template-button';

storiesOf('Welcome', module).add(
'Welcome',
Expand Down Expand Up @@ -132,3 +134,7 @@ storiesOf('Addon Knobs', module)
</div>
`;
});

storiesOf('Element definition types', module)
.add('separated js', () => '<separated-button title="Click me!"></separated-button>')
.add('string template', () => new StringTemplateButton());
28 changes: 28 additions & 0 deletions examples/polymer-cli/src/string-template-button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export class StringTemplateButton extends Polymer.Element {
static get is() {
return 'string-template-button';
}

static get properties() {
return {
title: {
type: String,
value: 'Wow, I am inline',
},
counter: {
type: Number,
value: 0,
},
};
}

static get template() {
return '<button on-click="handleTap">[[title]]: [[counter]]</button>';
}

handleTap() {
this.counter += 1;
}
}

customElements.define(StringTemplateButton.is, StringTemplateButton);

0 comments on commit 1e3bcd9

Please sign in to comment.