[FIX] playground: stop using class fields

as Edge doesn't support them.

Closes #509
This commit is contained in:
Aaron Bohy
2019-11-28 10:18:46 +01:00
committed by Géry Debongnie
parent 85d4393242
commit 9400c0adad
+87 -37
View File
@@ -2,7 +2,10 @@ const COMPONENTS = `// In this example, we show how components can be defined an
const { Component, useState } = owl; const { Component, useState } = owl;
class Greeter extends Component { class Greeter extends Component {
state = useState({ word: 'Hello' }); constructor() {
super(...arguments);
this.state = useState({ word: 'Hello' });
}
toggle() { toggle() {
this.state.word = this.state.word === 'Hi' ? 'Hello' : 'Hi'; this.state.word = this.state.word === 'Hi' ? 'Hello' : 'Hi';
@@ -11,7 +14,10 @@ class Greeter extends Component {
// Main root component // Main root component
class App extends Component { class App extends Component {
state = useState({ name: 'World'}); constructor() {
super(...arguments);
this.state = useState({ name: 'World'});
}
} }
App.components = { Greeter }; App.components = { Greeter };
@@ -47,7 +53,10 @@ const ANIMATION = `// The goal of this component is to see how the t-transition
const { Component, useState } = owl; const { Component, useState } = owl;
class Counter extends Component { class Counter extends Component {
state = useState({ value: 0 }); constructor() {
super(...arguments);
this.state = useState({ value: 0 });
}
increment() { increment() {
this.state.value++; this.state.value++;
@@ -55,7 +64,10 @@ class Counter extends Component {
} }
class App extends Component { class App extends Component {
state = useState({ flag: false, componentFlag: false, numbers: [] }); constructor() {
super(...arguments);
this.state = useState({ flag: false, componentFlag: false, numbers: [] });
}
toggle(key) { toggle(key) {
this.state[key] = !this.state[key]; this.state[key] = !this.state[key];
@@ -213,7 +225,10 @@ class DemoComponent extends Component {
} }
class App extends Component { class App extends Component {
state = useState({ n: 0, flag: true }); constructor() {
super(...arguments);
this.state = useState({ n: 0, flag: true });
}
increment() { increment() {
this.state.n++; this.state.n++;
@@ -282,11 +297,14 @@ function useMouse() {
// Main root component // Main root component
class App extends owl.Component { class App extends owl.Component {
// simple state hook (reactive object) constructor() {
counter = useState({ value: 0 }); super(...arguments);
// simple state hook (reactive object)
this.counter = useState({ value: 0 });
// this hooks is bound to the 'mouse' property. // this hooks is bound to the 'mouse' property.
mouse = useMouse(); this.mouse = useMouse();
}
increment() { increment() {
this.counter.value++; this.counter.value++;
@@ -318,7 +336,10 @@ const { Component, Context } = owl;
const { useContext } = owl.hooks; const { useContext } = owl.hooks;
class ToolbarButton extends Component { class ToolbarButton extends Component {
theme = useContext(this.env.themeContext); constructor() {
super(...arguments);
this.theme = useContext(this.env.themeContext);
}
get style () { get style () {
const theme = this.theme; const theme = this.theme;
@@ -451,12 +472,11 @@ const actions = {
// TodoItem // TodoItem
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
class TodoItem extends Component { class TodoItem extends Component {
state = useState({ isEditing: false }); constructor() {
dispatch = useDispatch(); super(...arguments);
constructor(...args) {
super(...args);
useAutofocus("input"); useAutofocus("input");
this.state = useState({ isEditing: false });
this.dispatch = useDispatch();
} }
handleKeyup(ev) { handleKeyup(ev) {
@@ -483,9 +503,12 @@ class TodoItem extends Component {
// TodoApp // TodoApp
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
class TodoApp extends Component { class TodoApp extends Component {
state = useState({ filter: "all" }); constructor() {
todos = useStore(state => state.todos); super(...arguments);
dispatch = useDispatch(); this.state = useState({ filter: "all" });
this.todos = useStore(state => state.todos);
this.dispatch = useDispatch();
}
get visibleTodos() { get visibleTodos() {
switch (this.state.filter) { switch (this.state.filter) {
@@ -1008,7 +1031,10 @@ class FormView extends owl.Component {}
FormView.components = { AdvancedComponent }; FormView.components = { AdvancedComponent };
class Chatter extends owl.Component { class Chatter extends owl.Component {
messages = Array.from(Array(100).keys()); constructor() {
super(...arguments);
this.messages = Array.from(Array(100).keys());
}
} }
class App extends owl.Component {} class App extends owl.Component {}
@@ -1150,7 +1176,10 @@ const SLOTS = `// We show here how slots can be used to create generic component
const { Component, useState } = owl; const { Component, useState } = owl;
class Card extends Component { class Card extends Component {
state = useState({ showContent: true }); constructor() {
super(...arguments);
this.state = useState({ showContent: true });
}
toggleDisplay() { toggleDisplay() {
this.state.showContent = !this.state.showContent; this.state.showContent = !this.state.showContent;
@@ -1158,7 +1187,10 @@ class Card extends Component {
} }
class Counter extends Component { class Counter extends Component {
state = useState({val: 1}); constructor() {
super(...arguments);
this.state = useState({val: 1});
}
inc() { inc() {
this.state.val++; this.state.val++;
@@ -1167,7 +1199,10 @@ class Counter extends Component {
// Main root component // Main root component
class App extends Component { class App extends Component {
state = useState({a: 1, b: 3}); constructor() {
super(...arguments);
this.state = useState({a: 1, b: 3});
}
inc(key, delta) { inc(key, delta) {
this.state[key] += delta; this.state[key] += delta;
@@ -1277,7 +1312,10 @@ class SlowComponent extends Component {
class NotificationList extends Component {} class NotificationList extends Component {}
class App extends Component { class App extends Component {
state = useState({ value: 0, notifs: [] }); constructor() {
super(...arguments);
this.state = useState({ value: 0, notifs: [] });
}
increment() { increment() {
this.state.value++; this.state.value++;
@@ -1350,13 +1388,16 @@ const FORM = `// This example illustrate how the t-model directive can be used t
const { Component, useState } = owl; const { Component, useState } = owl;
class Form extends Component { class Form extends Component {
state = useState({ constructor() {
text: "", super(...arguments);
othertext: "", this.state = useState({
number: 11, text: "",
color: "", othertext: "",
bool: false number: 11,
}); color: "",
bool: false
});
}
} }
// Application setup // Application setup
@@ -1419,7 +1460,10 @@ const { useRef } = owl.hooks;
class HelloWorld extends Component {} class HelloWorld extends Component {}
class Counter extends Component { class Counter extends Component {
state = useState({ value: 0 }); constructor() {
super(...arguments);
this.state = useState({ value: 0 });
}
inc() { inc() {
this.state.value++; this.state.value++;
@@ -1470,11 +1514,14 @@ class Window extends Component {
} }
class WindowManager extends Component { class WindowManager extends Component {
windows = []; constructor() {
nextId = 1; super(...arguments);
currentZindex = 1; this.windows = [];
nextLeft = 0; this.nextId = 1;
nextTop = 0; this.currentZindex = 1;
this.nextLeft = 0;
this.nextTop = 0;
}
addWindow(name) { addWindow(name) {
const info = this.env.windows.find(w => w.name === name); const info = this.env.windows.find(w => w.name === name);
@@ -1518,7 +1565,10 @@ class WindowManager extends Component {
WindowManager.components = { Window }; WindowManager.components = { Window };
class App extends Component { class App extends Component {
wmRef = useRef("wm"); constructor() {
super(...arguments);
this.wmRef = useRef("wm");
}
addWindow(name) { addWindow(name) {
this.wmRef.comp.addWindow(name); this.wmRef.comp.addWindow(name);