Last active
January 28, 2016 18:29
-
-
Save beauwest/5c155637c3cb6bc54b47 to your computer and use it in GitHub Desktop.
Test Change Listener
This file contains hidden or 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
<!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