refactor: use static props
in all examples (#19)
This commit is contained in:
parent
8aabf89208
commit
d290fc90a0
10 changed files with 29 additions and 17 deletions
|
@ -1,9 +1,10 @@
|
||||||
// @ts-check
|
// @ts-check
|
||||||
import { WebComponent, attachEffect } from "../../src/index.js";
|
import { WebComponent, attachEffect } from "../../src/index.js";
|
||||||
export class Counter extends WebComponent {
|
export class Counter extends WebComponent {
|
||||||
static properties = ["count"];
|
static props = {
|
||||||
|
count: 0,
|
||||||
|
};
|
||||||
onInit() {
|
onInit() {
|
||||||
this.props.count = 0;
|
|
||||||
this.onclick = () => ++this.props.count;
|
this.onclick = () => ++this.props.count;
|
||||||
attachEffect(this.props.count, (count) => console.log(count));
|
attachEffect(this.props.count, (count) => console.log(count));
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,11 @@
|
||||||
import { WebComponent, attachEffect } from "../../src/index.js";
|
import { WebComponent, attachEffect } from "../../src/index.js";
|
||||||
|
|
||||||
export class Decrease extends WebComponent {
|
export class Decrease extends WebComponent {
|
||||||
static properties = ["count"];
|
static props = {
|
||||||
|
count: 999,
|
||||||
|
};
|
||||||
|
|
||||||
onInit() {
|
onInit() {
|
||||||
this.props.count = 999;
|
|
||||||
this.onclick = () => --this.props.count;
|
this.onclick = () => --this.props.count;
|
||||||
attachEffect(this.props.count, (count) => console.log(count));
|
attachEffect(this.props.count, (count) => console.log(count));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
import { WebComponent } from "../../src/index.js";
|
import { WebComponent } from "../../src/index.js";
|
||||||
|
|
||||||
export class BooleanPropTest extends WebComponent {
|
export class BooleanPropTest extends WebComponent {
|
||||||
static properties = ["is-inline", "anotherone"];
|
static props = {
|
||||||
|
isInline: false,
|
||||||
|
anotherone: false,
|
||||||
|
};
|
||||||
|
|
||||||
get template() {
|
get template() {
|
||||||
return `<p>is-inline: ${this.props.isInline}</p><p>another-one: ${this.props.anotherone}</p>`;
|
return `<p>is-inline: ${this.props.isInline}</p><p>another-one: ${this.props.anotherone}</p>`;
|
||||||
|
|
|
@ -2,7 +2,10 @@
|
||||||
import { WebComponent } from "../../src/index.js";
|
import { WebComponent } from "../../src/index.js";
|
||||||
|
|
||||||
export class HelloWorld extends WebComponent {
|
export class HelloWorld extends WebComponent {
|
||||||
static properties = ["count", "emotion"];
|
static props = {
|
||||||
|
count: 0,
|
||||||
|
emotion: "sad",
|
||||||
|
};
|
||||||
|
|
||||||
onInit() {
|
onInit() {
|
||||||
this.props.count = 0;
|
this.props.count = 0;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<!DOCTYPE html>
|
<!doctype html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
|
|
|
@ -27,9 +27,10 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
class Toggle extends WebComponent {
|
class Toggle extends WebComponent {
|
||||||
static properties = ["toggle"];
|
static props = {
|
||||||
|
toggle: false,
|
||||||
|
};
|
||||||
onInit() {
|
onInit() {
|
||||||
this.props.toggle = false;
|
|
||||||
this.onclick = () => (this.props.toggle = !this.props.toggle);
|
this.onclick = () => (this.props.toggle = !this.props.toggle);
|
||||||
}
|
}
|
||||||
get template() {
|
get template() {
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
// @ts-check
|
// @ts-check
|
||||||
import { WebComponent, html } from "../../src/index.js";
|
import { WebComponent } from "../../src/index.js";
|
||||||
|
|
||||||
export class Counter extends WebComponent {
|
export class Counter extends WebComponent {
|
||||||
static properties = ["count"];
|
static props = {
|
||||||
|
count: 1,
|
||||||
|
};
|
||||||
onInit() {
|
onInit() {
|
||||||
this.props.count = 1;
|
|
||||||
let i = 1;
|
let i = 1;
|
||||||
this.onclick = () => ++this.props.count;
|
this.onclick = () => ++this.props.count;
|
||||||
let double = () => i * 2;
|
let double = () => i * 2;
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
import { WebComponent } from "../../src/index.js";
|
import { WebComponent } from "../../src/index.js";
|
||||||
|
|
||||||
export class HelloWorld extends WebComponent {
|
export class HelloWorld extends WebComponent {
|
||||||
static properties = ["name"];
|
static props = {
|
||||||
|
name: "a",
|
||||||
|
};
|
||||||
onInit() {
|
onInit() {
|
||||||
this.props.name = "a";
|
|
||||||
this.onclick = () => (this.props.name += "a");
|
this.onclick = () => (this.props.name += "a");
|
||||||
}
|
}
|
||||||
get template() {
|
get template() {
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { WebComponent } from "../../src/index.js";
|
import { WebComponent } from "../../src/index.js";
|
||||||
|
|
||||||
export class ObjectText extends WebComponent {
|
export class ObjectText extends WebComponent {
|
||||||
// static properties = ["object"];
|
|
||||||
static props = {
|
static props = {
|
||||||
object: {
|
object: {
|
||||||
hello: "worldzz",
|
hello: "worldzz",
|
||||||
|
|
|
@ -2,9 +2,10 @@
|
||||||
import { WebComponent } from "../../src/index.js";
|
import { WebComponent } from "../../src/index.js";
|
||||||
|
|
||||||
export class Toggle extends WebComponent {
|
export class Toggle extends WebComponent {
|
||||||
static properties = ["toggle"];
|
static props = {
|
||||||
|
toggle: false,
|
||||||
|
};
|
||||||
onInit() {
|
onInit() {
|
||||||
this.props.toggle = false;
|
|
||||||
this.onclick = () => this.handleToggle();
|
this.onclick = () => this.handleToggle();
|
||||||
}
|
}
|
||||||
handleToggle() {
|
handleToggle() {
|
||||||
|
|
Loading…
Reference in a new issue