Skip to content

Commit

Permalink
Convert to constructor syntax for safari support
Browse files Browse the repository at this point in the history
  • Loading branch information
sukima committed Oct 24, 2020
1 parent 99b7d15 commit fc64aa5
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 16 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ and allow you to make small and yet *performant* custom elements.
```js
class MyCustomElement extends Component {

count = tracked(0);
constructor() {
super();
this.count = tracked(0);
}

connectedCallback() {
super.connectedCallback();
Expand Down
3 changes: 1 addition & 2 deletions examples/1.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@
import { tracked } from '../tracking.js';

class FooBar extends Component {
foo = tracked(0);

get bar() {
return `bar-${this.foo}`;
}

constructor() {
super();
this.foo = tracked(0);
this.shadow.querySelector('.go')
.addEventListener('click', () => { this.foo += 1 });
}
Expand Down
3 changes: 1 addition & 2 deletions examples/2.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@
import { tracked } from '../tracking.js';

class FooBar extends Component {
foo = tracked(0);

get bar() {
return `bar-${this.foo}`;
}

constructor() {
super();
this.foo = tracked(0);
this.shadow.querySelector('.go')
.addEventListener('click', () => { this.foo += 1 });
}
Expand Down
3 changes: 1 addition & 2 deletions examples/3.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@
import { tracked } from '../tracking.js';

class FooBar extends Component {
foo = tracked(0);

get bar() {
return `bar-${this.foo}`;
}

constructor() {
super();
this.foo = tracked(0);
this.shadow.querySelector('.go')
.addEventListener('click', () => { this.foo += 1 });
}
Expand Down
5 changes: 4 additions & 1 deletion examples/6.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@

class MyCustomElement extends Component {

count = tracked(0);
constructor() {
super();
this.count = tracked(0);
}

connectedCallback() {
super.connectedCallback();
Expand Down
23 changes: 16 additions & 7 deletions examples/7.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@
}

class BlinknLights extends Component {
lights = new Set();
previousEmojiCount = 0;
timer = tracked();
constructor() {
super();
this.lights = new Set();
this.previousEmojiCount = 0;
this.timer = tracked();
}
connectedCallback() {
super.connectedCallback();
if (this.hasAttribute('autostart')) { this.start(); }
Expand Down Expand Up @@ -92,16 +95,22 @@
}

class BlinknLight extends Component {
emoji = tracked(EMOJIES[0]);
constructor() {
super();
this.emoji = tracked(EMOJIES[0]);
}
render() {
this.shadow.querySelector('.emoji').textContent = this.emoji;
}
}

class FpsMeter extends Component {
be = new Date();
running = false;
fps = tracked(0);
constructor() {
super();
this.be = new Date();
this.running = false;
this.fps = tracked(0);
}
connectedCallback() {
super.connectedCallback();
this.start();
Expand Down
4 changes: 3 additions & 1 deletion tracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ let currentComputation = null;
let onTagDirtied = () => {};

class Tag {
[REVISION] = CURRENT_REVISION;
constructor() {
this[REVISION] = CURRENT_REVISION;
}
}

class TrackedProperty {
Expand Down

0 comments on commit fc64aa5

Please sign in to comment.