Skip to content

Instantly share code, notes, and snippets.

@saki007ster
Last active May 13, 2016 21:05
Show Gist options
  • Save saki007ster/8c52092d0c2b878e9cac8e04a09a6b09 to your computer and use it in GitHub Desktop.
Save saki007ster/8c52092d0c2b878e9cac8e04a09a6b09 to your computer and use it in GitHub Desktop.
polymer element lifecycle
<dom-module id="lifecycle-element">
<template>
<style>
:host {
display: block;
}
</style>
<button id="btn">Hello world</button>
</template>
<script>
Polymer({
is: 'lifecycle-element',
created: function(){
this.log('created');
this.addEventListener('click', function(){
this.remove();
});
},
ready: function(){
this.log('ready');
this.ticker = setInterval(this.tick.bind(this), 500);
},
attached: function(){
this.log('attached');
},
detached: function(){
this.log('detached');
clearInterval(this.ticker);
},
attributeChanged: function(name, oldValue, newValue){
console.log('%s was changed to %s from %s', name, newValue, oldValue);
},
tick: function(){
this.setAttribute('data-id', Math.random());
},
updateAtrribute: function(cycle){
this.setAttribute('class', cycle);
},
log: function(cycle){
console.log("******" + cycle);
this.$ && console.dir(this.$.btn);
this.updateAtrribute(cycle);
}
});
</script>
</dom-module>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment