Permalink
Browse files

fix(watch): Watch can now handle HTMLElements and descendants as part…

… of Component.state
  • Loading branch information...
calebdwilliams committed Aug 25, 2018
1 parent d49ed95 commit 1d72704ce297db0d4b9f56009d618cb394731ded
@@ -77,7 +77,7 @@ <h1>
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
Code coverage
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Tue Aug 21 2018 21:31:45 GMT-0500 (CDT)
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Tue Aug 21 2018 21:32:44 GMT-0500 (CDT)
</div>
</div>
<script src="prettify.js"></script>
@@ -77,7 +77,7 @@ <h1>
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
Code coverage
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Tue Aug 21 2018 21:31:45 GMT-0500 (CDT)
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Tue Aug 21 2018 21:32:44 GMT-0500 (CDT)
</div>
</div>
<script src="../prettify.js"></script>
@@ -1957,7 +1957,7 @@ <h1>
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
Code coverage
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Tue Aug 21 2018 21:31:45 GMT-0500 (CDT)
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Tue Aug 21 2018 21:32:44 GMT-0500 (CDT)
</div>
</div>
<script src="../prettify.js"></script>
@@ -191,19 +191,21 @@ export class Component extends HTMLElement {
export const watch = (object, onChange) => {
const handler = {
get(target, property, receiver) {
const desc = Object.getOwnPropertyDescriptor(target, property);
const value = Reflect.get(target, property, receiver);

if (desc && !desc.writable && !desc.configurable) {
return value;
}

try {
const desc = Object.getOwnPropertyDescriptor(target, property);
const value = Reflect.get(target, property, receiver);

if (desc && !desc.writable && !desc.configurable) {
return value;
}
if (typeof target[property] === 'function' && (target instanceof Date || target instanceof Map ||target instanceof WeakMap)) {
return new Proxy(target[property].bind(target), handler);
}
return new Proxy(target[property], handler);
} catch (err) {
if (target instanceof HTMLElement) {
return target[property];
}
return Reflect.get(target, property, receiver);
}
},

0 comments on commit 1d72704

Please sign in to comment.