mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
add: new example with ES5 code
This commit is contained in:
@@ -34,6 +34,35 @@ const qweb = new QWeb(TEMPLATES);
|
|||||||
const hello = new HelloWorld({qweb}, { name: "World" });
|
const hello = new HelloWorld({qweb}, { name: "World" });
|
||||||
hello.mount(document.body);`;
|
hello.mount(document.body);`;
|
||||||
|
|
||||||
|
const HELLO_WORLD_ES5 = `const { Component, QWeb } = owl.core;
|
||||||
|
|
||||||
|
function HelloWorld(env, props) {
|
||||||
|
var obj = new Component(env, props);
|
||||||
|
Object.setPrototypeOf(obj, HelloWorld.prototype);
|
||||||
|
obj.template = "demo.hello";
|
||||||
|
obj.state = { greeting: "Hello" };
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
HelloWorld.prototype = Object.create(Component.prototype);
|
||||||
|
|
||||||
|
// we show here how to add methods to sub components
|
||||||
|
HelloWorld.prototype.changeGreeting = function() {
|
||||||
|
var newGreeting = this.state.greeting === "Hello" ? "Hi" : "Hello";
|
||||||
|
this.updateState({ greeting: newGreeting });
|
||||||
|
};
|
||||||
|
|
||||||
|
const qweb = new QWeb(TEMPLATES);
|
||||||
|
const hello = new HelloWorld({ qweb }, { name: "ES5 World" });
|
||||||
|
hello.mount(document.body);
|
||||||
|
`;
|
||||||
|
|
||||||
|
const HELLO_WORLD_ES5_XML = `<templates>
|
||||||
|
<div t-name="demo.hello" class="hello" t-on-click="changeGreeting">
|
||||||
|
<t t-esc="state.greeting"/> <t t-esc="props.name"/>
|
||||||
|
</div>
|
||||||
|
</templates>`;
|
||||||
|
|
||||||
const WIDGET_COMPOSITION = `class Counter extends owl.core.Component {
|
const WIDGET_COMPOSITION = `class Counter extends owl.core.Component {
|
||||||
constructor(parent, props) {
|
constructor(parent, props) {
|
||||||
super(parent, props);
|
super(parent, props);
|
||||||
@@ -465,6 +494,12 @@ export const SAMPLES = [
|
|||||||
xml: HELLO_WORLD_XML,
|
xml: HELLO_WORLD_XML,
|
||||||
css: HELLO_WORLD_CSS
|
css: HELLO_WORLD_CSS
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
description: "Hello World (ES5)",
|
||||||
|
code: HELLO_WORLD_ES5,
|
||||||
|
xml: HELLO_WORLD_ES5_XML,
|
||||||
|
css: HELLO_WORLD_CSS
|
||||||
|
},
|
||||||
{
|
{
|
||||||
description: "Widget Composition",
|
description: "Widget Composition",
|
||||||
code: WIDGET_COMPOSITION,
|
code: WIDGET_COMPOSITION,
|
||||||
|
|||||||
Reference in New Issue
Block a user