Last active
November 28, 2024 20:06
-
-
Save KonnorRogers/330b9bf5514f0af0911737f67f7f00fe to your computer and use it in GitHub Desktop.
a rough sketch of writing reactive components.
This file contains hidden or 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
<template component="MyComponent" store="global"> | |
<div | |
@click="(e) => console.log('Clicked on: ' + this.name)" // event listeners | |
.name={{ name }} // properties | |
name="{{ name }}" // attributes | |
> | |
Hello {{ name }} | |
</div> | |
</template> | |
<div component="MyComponent"></div> | |
<script type="module"> | |
import { createStore } from "fe-framework" | |
const globalStore = createStore("global", { | |
name: null | |
}) | |
setTimeout(() => { | |
globalStore.name = "Cory" | |
}, 2_000) | |
// Listen to changes | |
globalStore.addEventListener("update", (e) => { | |
console.log(e.changedProperties) | |
// => Map { "name": { oldValue: null, newValue: "Cory" } } | |
}) | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment