Skip to content

Commit

Permalink
updated for derivative state prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
thescientist13 committed Jan 2, 2024
1 parent 6ae1e8e commit 06bf2b7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
30 changes: 30 additions & 0 deletions src/components/badge/badge.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export const inferredObservability = true;

export default class BadgeComponent extends HTMLElement {

constructor() {
super();

this.counter = 0;
}

connectedCallback() {
this.render();
}

render() {
const { counter } = this;
const condition = ` (${counter % 2 === 0 ? 'even' : 'odd'}) `;
// const conditionalClass = ` (${predicate ? 'even' : 'odd'}) `;
// const conditionalText = predicate ? ' 🥳' : '';

// TODO <span class={conditionalClass}>{counter}<span>{conditionalText}</span></span>
// should have attr AND text instructions
// though technically conditionalClass should only observe off predicate
return (
<span><span>{counter}</span><span>{condition}</span></span>
);
}
}

customElements.define('wcc-badge', BadgeComponent);
4 changes: 3 additions & 1 deletion src/components/counter/counter.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import '../badge/badge.jsx';

export const inferredObservability = true;

export default class Counter extends HTMLElement {
Expand All @@ -16,7 +18,7 @@ export default class Counter extends HTMLElement {
return (
<div>
<button onclick={this.count -= 1}> -</button>
<span>You have clicked {count} times !!!</span>
<span>You have clicked <wcc-badge counter={count}></wcc-badge> times !!!</span>
<button onclick={this.count += 1}> +</button>
</div>
);
Expand Down
2 changes: 0 additions & 2 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@
window.addEventListener('load', () => {
counter = document.getElementsByTagName('wcc-counter')[0];

counter.setAttribute('count', 0);

document.getElementById('start').addEventListener('click', () => {
startIncrement();
});
Expand Down

0 comments on commit 06bf2b7

Please sign in to comment.