Created
February 20, 2019 13:36
-
-
Save heyMP/6946ed51abe6ce234de6a52a7cecde4e to your computer and use it in GitHub Desktop.
Example Mixin for Polymer element
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Copyright 2019 PSU | |
* @license Apache-2.0, see License.md for full text. | |
*/ | |
import { html, PolymerElement } from "@polymer/polymer/polymer-element.js"; | |
const SelectedMixin = function (superClass) { | |
return class extends superClass { | |
static get properties() { | |
return { | |
isSelected: { | |
type: Boolean, | |
value: false, | |
notify: true, | |
observer: '_selectedChanged' | |
} | |
}; | |
} | |
_selectedChanged(selected) { | |
// do something | |
} | |
getSelectedItems() { | |
// do something | |
} | |
} | |
} | |
/** | |
* `glossary-consumer` | |
* `Consumer renderless componet for glossary-service` | |
* | |
* @microcopy - language worth noting: | |
* - | |
* | |
* @customElement | |
* @polymer | |
* @demo demo/index.html | |
*/ | |
class GlossaryConsumer extends SelectedMixin(PolymerElement) { | |
/* REQUIRED FOR TOOLING DO NOT TOUCH */ | |
/** | |
* Store the tag name to make it easier to obtain directly. | |
* @notice function name must be here for tooling to operate correctly | |
*/ | |
static get tag() { | |
return "glossary-consumer"; | |
} | |
/** | |
* life cycle, element is afixed to the DOM | |
*/ | |
connectedCallback() { | |
super.connectedCallback(); | |
} | |
disconnectedCallback() { | |
super.disconnectedCallback() | |
} | |
} | |
window.customElements.define(MyComponent.tag, MyComponent); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment