diff --git a/README.md b/README.md index ab51757f..81c10d18 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,46 @@ const hello = new HelloWorld(env, { name: "World" }); hello.mount(document.body); ``` +The next example show how interactive widgets can be created and how widget +composition works: + +```javascript +class Counter extends owl.core.Component { + inlineTemplate = ` +
+ + Value: + +
`; + + constructor(parent, props) { + super(parent, props); + this.state = { + counter: props.initialState || 0 + }; + } + + increment(delta) { + this.updateState({ counter: this.state.counter + delta }); + } +} + +class App extends owl.core.Component { + inlineTemplate = ` +
+ + +
`; +} + +const env = { + qweb: new owl.core.QWeb() +}; + +const app = new App(env); +app.mount(document.body); +``` + More interesting examples on how to work with this web framework can be found in the _examples/_ folder: - [Todo Application](examples/readme.md#todo-app)