-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add local storage for persistence and cross tab events.
- Loading branch information
Showing
6 changed files
with
222 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
run: | ||
python -m http.server 3000 |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/*** | ||
* This one just shows the counter value from the state. | ||
*/ | ||
/*** | ||
* This one just shows the counter value from the state AND lets you increment it. | ||
*/ | ||
import { LitElement, html } from 'lit' | ||
import '@material/web/button/filled-button.js' | ||
import state from '../state.js' | ||
|
||
class CountComponent extends LitElement { | ||
static properties = { | ||
counter: { type: Number } | ||
} | ||
|
||
constructor() { | ||
super() | ||
this.counter = 0 | ||
} | ||
|
||
connectedCallback() { | ||
super.connectedCallback() | ||
this.counter = state.get('counter') | ||
console.log("got counter 1:", this.counter) | ||
state.addEventListener('counter', (e) => { | ||
console.log("counter event", e) | ||
this.counter = e.detail.value | ||
}) | ||
} | ||
|
||
render() { | ||
return html` | ||
<div>${this.counter}</div> | ||
` | ||
} | ||
|
||
increment() { | ||
this.counter++ | ||
state.set('counter', this.counter) | ||
} | ||
|
||
} | ||
|
||
customElements.define('count-component', CountComponent) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/*** | ||
* This one just shows the counter value from the state AND lets you increment it. | ||
*/ | ||
import { LitElement, html } from 'lit' | ||
import '@material/web/button/filled-button.js' | ||
import state from '../state.js' | ||
|
||
class CounterComponent extends LitElement { | ||
static properties = { | ||
counter: { type: Number } | ||
} | ||
|
||
constructor() { | ||
super(); | ||
this.counter = 0 | ||
} | ||
|
||
connectedCallback() { | ||
super.connectedCallback() | ||
this.counter = state.get('counter') | ||
console.log("got counter 2:", this.counter) | ||
state.addEventListener('counter', (e) => { | ||
console.log("counter event", e) | ||
this.counter = e.detail.value | ||
}) | ||
} | ||
|
||
render() { | ||
return html` | ||
<div>${this.counter}</div> | ||
<md-filled-button @click=${this.increment}>Increment</md-filled-button> | ||
` | ||
} | ||
|
||
increment() { | ||
this.counter++ | ||
state.set('counter', this.counter) | ||
} | ||
|
||
} | ||
|
||
customElements.define('counter-component', CounterComponent) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<title>State Demo Page</title> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<script type="importmap"> | ||
{ | ||
"imports": { | ||
"lit": "https://cdn.jsdelivr.net/npm/lit@2/index.js", | ||
"lit/": "https://cdn.jsdelivr.net/npm/lit@2/", | ||
"@material/web/": "https://cdn.jsdelivr.net/npm/@material/web@1/", | ||
"@lit/localize": "https://cdn.jsdelivr.net/npm/@lit/localize/lit-localize.js", | ||
"@lit/reactive-element": "https://cdn.jsdelivr.net/npm/@lit/reactive-element@1/reactive-element.js", | ||
"@lit/reactive-element/": "https://cdn.jsdelivr.net/npm/@lit/reactive-element@1/", | ||
"lit-element/lit-element.js": "https://cdn.jsdelivr.net/npm/lit-element@3/lit-element.js", | ||
"lit-html": "https://cdn.jsdelivr.net/npm/lit-html@2/lit-html.js", | ||
"lit-html/": "https://cdn.jsdelivr.net/npm/lit-html@2/", | ||
"tslib": "https://cdn.jsdelivr.net/npm/tslib@2/tslib.es6.mjs" | ||
} | ||
} | ||
</script> | ||
|
||
</head> | ||
|
||
<body> | ||
<script type="module"> | ||
import './counter-component.js' | ||
import './count-component.js' | ||
</script> | ||
|
||
<style> | ||
/* Set up the flex container */ | ||
.nav-container { | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
background-color: #333; | ||
color: #fff; | ||
padding: 10px; | ||
} | ||
|
||
/* Style the links */ | ||
.nav-link { | ||
color: #fff; | ||
text-decoration: none; | ||
margin: 0 10px; | ||
} | ||
|
||
/* Style the active link */ | ||
.nav-link.active { | ||
font-weight: bold; | ||
} | ||
</style> | ||
|
||
<div class="nav-container"> | ||
<div> | ||
<a href="#" class="nav-link active">Home</a> | ||
<a href="#" class="nav-link">About</a> | ||
<a href="#" class="nav-link">Contact</a> | ||
</div> | ||
<div> | ||
<div>Count: <count-component></count-component></div> | ||
<a href="#" class="nav-link">Login</a> | ||
<a href="#" class="nav-link">Sign Up</a> | ||
</div> | ||
</div> | ||
|
||
<h1>Welcome to the state demo</h1> | ||
<p> | ||
<counter-component></counter-component> | ||
</p> | ||
</body> | ||
|
||
</html> |
This file contains 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