Skip to content

Commit

Permalink
Convert static fields to getters for safari support
Browse files Browse the repository at this point in the history
  • Loading branch information
sukima committed Oct 25, 2020
1 parent 99b7d15 commit 21302af
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 13 deletions.
8 changes: 7 additions & 1 deletion README.md
Expand Up @@ -14,6 +14,10 @@ class MyCustomElement extends Component {

count = tracked(0);

constructor() {
super();
}

connectedCallback() {
super.connectedCallback();
this.timer = setInterval(() => this.count++, 1000);
Expand All @@ -28,7 +32,9 @@ class MyCustomElement extends Component {
this.shadow.querySelector('output').value = this.count;
}

static template = `<span>Counter: <output></output></span>`;
static get template() {
return `<span>Counter: <output></output></span>`;
}

}

Expand Down
2 changes: 2 additions & 0 deletions examples/1.html
Expand Up @@ -12,6 +12,7 @@
import { tracked } from '../tracking.js';

class FooBar extends Component {

foo = tracked(0);

get bar() {
Expand All @@ -28,6 +29,7 @@
this.shadow.querySelector('.foo').value = this.foo;
this.shadow.querySelector('.bar').value = this.bar;
}

}

FooBar.register();
Expand Down
13 changes: 8 additions & 5 deletions examples/2.html
Expand Up @@ -12,6 +12,7 @@
import { tracked } from '../tracking.js';

class FooBar extends Component {

foo = tracked(0);

get bar() {
Expand All @@ -29,11 +30,13 @@
this.shadow.querySelector('.bar').value = this.bar;
}

static template = `
<button class="go">+1</button>
<output class="foo"></output>
<output class="bar"></output>
`;
static get template() {
return `
<button class="go">+1</button>
<output class="foo"></output>
<output class="bar"></output>
`;
}

}

Expand Down
1 change: 1 addition & 0 deletions examples/3.html
Expand Up @@ -12,6 +12,7 @@
import { tracked } from '../tracking.js';

class FooBar extends Component {

foo = tracked(0);

get bar() {
Expand Down
1 change: 1 addition & 0 deletions examples/4.html
Expand Up @@ -31,6 +31,7 @@
this.shadow.querySelector('.foo').value = globalTrackable.foo;
this.shadow.querySelector('.bar').value = this.bar;
}

}

FooBar.register();
Expand Down
1 change: 1 addition & 0 deletions examples/5.html
Expand Up @@ -40,6 +40,7 @@
this.shadow.querySelector('.foo').value = getGlobalValue();
this.shadow.querySelector('.bar').value = this.bar;
}

}

FooBar.register();
Expand Down
8 changes: 7 additions & 1 deletion examples/6.html
Expand Up @@ -15,6 +15,10 @@

count = tracked(0);

constructor() {
super();
}

connectedCallback() {
super.connectedCallback();
this.timer = setInterval(() => this.count++, 1000);
Expand All @@ -29,7 +33,9 @@
this.shadow.querySelector('output').value = this.count;
}

static template = `<span>Counter: <output></output></span>`;
static get template() {
return `<span>Counter: <output></output></span>`;
}

}

Expand Down
15 changes: 10 additions & 5 deletions examples/7.html
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;
}
connectedCallback() {
super.connectedCallback();
if (this.hasAttribute('autostart')) { this.start(); }
Expand Down Expand Up @@ -143,15 +146,14 @@
}

class PlayPauseButton extends Component {
static template = `<button type="button"></button>`;
connectedCallback() {
super.connectedCallback();
this.clickHandler = () => this.toggle();
this.buttonElement.addEventListener('click', this.clickHandler);
this.buttonElement.addEventListener('mouseup', this.clickHandler);
}
disconnectedCallback() {
super.disconnectedCallback();
this.buttonElement.removeEventListener('click', this.clickHandler);
this.buttonElement.removeEventListener('mouseup', this.clickHandler);
}
toggle() {
let { runnableElement } = this;
Expand All @@ -169,6 +171,9 @@
let id = this.getAttribute('for');
return document.querySelector(`#${id}`);
}
static get template() {
return `<button type="button"></button>`;
}
}

FpsMeter.register();
Expand Down
4 changes: 3 additions & 1 deletion tracking.js
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 21302af

Please sign in to comment.