diff --git a/attach-effect/Counter.mjs b/examples/attach-effect/Counter.mjs similarity index 81% rename from attach-effect/Counter.mjs rename to examples/attach-effect/Counter.mjs index a4f2c0f..409ddc2 100644 --- a/attach-effect/Counter.mjs +++ b/examples/attach-effect/Counter.mjs @@ -1,6 +1,6 @@ // @ts-check -import WebComponent from "../src/WebComponent.js"; -import { attachEffect } from "../src/attach-effect.js"; +import WebComponent from "../../src/WebComponent.js"; +import { attachEffect } from "../../src/attach-effect.js"; export class Counter extends WebComponent { static properties = ["count"]; diff --git a/examples/attach-effect/Decrease.mjs b/examples/attach-effect/Decrease.mjs new file mode 100644 index 0000000..e8af741 --- /dev/null +++ b/examples/attach-effect/Decrease.mjs @@ -0,0 +1,25 @@ +// @ts-check +import WebComponent from "../../src/WebComponent.js"; +import { attachEffect } from "../../src/attach-effect.js"; + +export class Decrease extends WebComponent { + static properties = ["count"]; + onInit() { + this.props.count = 999; + this.onclick = () => --this.props.count; + attachEffect( + this.props.count, + (count) => console.log(count) + ); + } + + afterViewInit(){ + attachEffect(this.props.count, (count) => console.log(count + 100)); + } + + get template() { + return ``; + } +} + +customElements.define("my-decrement", Decrease); diff --git a/attach-effect/index.html b/examples/attach-effect/index.html similarity index 65% rename from attach-effect/index.html rename to examples/attach-effect/index.html index 0b077eb..63ec0a0 100644 --- a/attach-effect/index.html +++ b/examples/attach-effect/index.html @@ -4,10 +4,12 @@