Skip to content

Commit

Permalink
add attribute to inferredObservablity test case
Browse files Browse the repository at this point in the history
  • Loading branch information
thescientist13 committed Jan 9, 2024
1 parent ab80fb6 commit 7e6054a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
export const inferredObservability = true;
export default class Counter extends HTMLElement {
static get observedAttributes() {
return ['count'];
}
attributeChangedCallback(name, oldValue, newValue) {
attributeChangedCallback(name, oldValue, newValue) {
console.debug('???attributeChangedCallback', { name });
console.debug('???attributeChangedCallback', { oldValue });
console.debug('???attributeChangedCallback', { newValue });
Expand All @@ -15,6 +10,9 @@ export default class Counter extends HTMLElement {
case 'count':
this.count = getValue(newValue);
break;
case 'highlight':
this.highlight = getValue(newValue);
break;
}
this.update(name, oldValue, newValue);
}
Expand Down Expand Up @@ -45,35 +43,10 @@ export default class Counter extends HTMLElement {
break;
}
});
if (['count'].includes(name)) {
if ([
'count',
'highlight'
].includes(name)) {
}
console.debug('****************************');
}
constructor() {
super();
this.count = 0;
}
increment() {
this.count += 1;
this.render();
}
decrement() {
this.count -= 1;
this.render();
}
connectedCallback() {
this.render();
}
render() {
const {count} = this;
this.innerHTML = `<div>
<wcc-badge count="${ count }" data-wcc-count="count" data-wcc-ins="attr"></wcc-badge>
<h3 data-test="hello123">Counter JSX</h3>
<button id="evt-this" onclick="this.parentElement.parentElement.decrement()"> - (function reference)</button>
<button id="evt-assignment" onclick="this.parentElement.parentElement.count-=1; this.parentElement.parentElement.setAttribute(\'count\', this.parentElement.parentElement.count);"> - (inline state update)</button>
<span>You have clicked <span class="red" id="expression" data-wcc-count="${ this.count }" data-wcc-ins="text">${ count }</span> times</span>
<button onclick="this.parentElement.parentElement.count+=1; this.parentElement.parentElement.setAttribute(\'count\', this.parentElement.parentElement.count);"> + (inline state update)</button>
<button onclick="this.parentElement.parentElement.increment()"> + (function reference)</button>
</div>`;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
static get observedAttributes() {
return['count'];
return['count', 'highlight'];
}
5 changes: 3 additions & 2 deletions test/cases/jsx-inferred-observability/src/counter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export default class Counter extends HTMLElement {
constructor() {
super();
this.count = 0;
this.highlight = 'red';
}

increment() {
Expand All @@ -21,15 +22,15 @@ export default class Counter extends HTMLElement {
}

render() {
const { count } = this;
const { count, highlight } = this;

return (
<div>
<wcc-badge count={count}></wcc-badge>
<h3 data-test="hello123">Counter JSX</h3>
<button id="evt-this" onclick={this.decrement}> - (function reference)</button>
<button id="evt-assignment" onclick={this.count -= 1}> - (inline state update)</button>
<span>You have clicked <span class="red" id="expression">{count}</span> times</span>
<span>You have clicked <span class={highlight} id="expression">{count}</span> times</span>
<button onclick={this.count += 1}> + (inline state update)</button>
<button onclick={this.increment}> + (function reference)</button>
</div>
Expand Down

0 comments on commit 7e6054a

Please sign in to comment.