Last active
May 22, 2020 17:07
-
-
Save MatthiasKainer/bb3f0af88381877bbf14ad9017acdb99 to your computer and use it in GitHub Desktop.
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
@customElement("demo-element") | |
export class DemoElement extends LitElement { | |
state: DispatcherType<DemoElementState>; | |
constructor() { | |
super() | |
// register dispatcher in the constructor | |
this.state = useDispatcher<DemoElementState>(this, { actions: [] }) | |
} | |
render() { | |
// get the current state for each rendering | |
const { actions } = this.state.getState() | |
// Change the state from multiple different actions using the publish function | |
const { publish } = this.state | |
return html` <div> | |
<trigger-button name="Button1" | |
@trigger="${(e: CustomEvent) => publish({ actions: [...actions, e.detail] })}" | |
></trigger-button> | |
<trigger-button name="Button2" | |
@trigger="${(e: CustomEvent) => publish({ actions: [...actions, e.detail] })}" | |
></trigger-button> | |
<input | |
type="checkbox" | |
@change="${({ target }: CheckableInputElement) => publish({ actions: [...actions, `Element checked: ${target.checked}`] })}" | |
/> | |
</div> | |
<action-list .actions="${actions}"></action-list>` | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment