Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reimplement in typescript and customElements V1 #9

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
annotations?
  • Loading branch information
laat committed Feb 25, 2020
commit 9d7a83e907f9a2f719d88de0c9caf9e868f114dd
39 changes: 39 additions & 0 deletions src/chess-circle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
class ChessCircle extends HTMLElement {
connectedCallback() {
this._upgradeProperty("square");
this._upgradeProperty("color");
}

set square(square: string | null) {
if (square != null) {
this.setAttribute("square", square);
} else {
this.removeAttribute("square");
}
}
get square() {
return this.getAttribute("square");
}

set color(color: string | null) {
if (color != null) {
this.setAttribute("color", color);
} else {
this.removeAttribute("color");
}
}
get color() {
return this.getAttribute("color");
}

private _upgradeProperty(prop: any) {
if (this.hasOwnProperty(prop)) {
// @ts-ignore
let value = this[prop];
// @ts-ignore
delete this[prop];
// @ts-ignore
this[prop] = value;
}
}
}