Skip to content

Instantly share code, notes, and snippets.

@beauwest
Last active January 28, 2016 18:29
Show Gist options
  • Save beauwest/5c155637c3cb6bc54b47 to your computer and use it in GitHub Desktop.
Save beauwest/5c155637c3cb6bc54b47 to your computer and use it in GitHub Desktop.
Test Change Listener
<!doctype html>
<meta charset="utf-8">
<base href="http://polygit.org/polymer+v1.2.4/components/">
<script src="webcomponentsjs/webcomponents-lite.js"></script>
<link href="polymer/polymer.html" rel="import">
<script>
addEventListener('WebComponentsReady', function () {
window.InputBehavior = {
properties: {
displayValue: {type: String, notify: true, observer: 'displayValueChanged'},
currentvalue: {type: String, notify: true, observer: 'currentvalueChanged'}
},
listeners: {
'field.input': 'handleInput'
},
handleInput: function () {
this.currentvalue = this.$.field.value;
},
currentvalueChanged: function (newValue) {
console.log('original', 'changed', newValue);
}
};
window.CustomBehavior = {
behaviorEvent: function (event) {
event.stopPropagation(); // <--- THIS DOES IT!
console.log('behavior', 'changed', event);
},
attached: function () {
this.listen(this, 'currentvalue-changed', 'behaviorEvent');
}
};
});
</script>
<dom-module id="custom-input">
<template>
<input type="text" id="field">
</template>
<script>
addEventListener('WebComponentsReady', function () {
Polymer({
is: 'custom-input',
behaviors: [
InputBehavior,
CustomBehavior
]
});
});
</script>
</dom-module>
<script>
addEventListener('WebComponentsReady', function () {
var element = document.createElement('custom-input');
document.body.appendChild(element);
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment