diff --git a/src/samples.js b/src/samples.js index 63218d83..1c14991d 100644 --- a/src/samples.js +++ b/src/samples.js @@ -105,6 +105,69 @@ const WIDGET_COMPOSITION_XML = ` `; +const LIFECYCLE_DEMO = `const { Component, QWeb } = owl.core; + +class HookWidget extends Component { + constructor() { + super(...arguments); + this.template = "demo.hookwidget"; + this.state = { n: 0 }; + console.log("constructor"); + } + async willStart() { + console.log("willstart"); + } + mounted() { + console.log("mounted"); + } + async willUpdateProps(nextProps) { + console.log("willUpdateProps", nextProps); + } + willPatch() { + console.log("willPatch"); + } + patched() { + console.log("patched"); + } + willUnmount() { + console.log("willUnmount"); + } + increment() { + this.updateState({ n: this.state.n + 1 }); + } +} + +class ParentWidget extends Component { + constructor() { + super(...arguments); + this.widgets = { HookWidget }; + this.template = "demo.parentwidget"; + this.state = { n: 0, flag: true }; + } + increment() { + this.updateState({ n: this.state.n + 1 }); + } + toggleSubWidget() { + this.updateState({ flag: !this.state.flag }); + } +} + +const qweb = new QWeb(TEMPLATES); +const widget = new ParentWidget({ qweb }); +widget.mount(document.body); +`; + +const LIFECYCLE_DEMO_XML = ` +
+ + +
+ +
+
+
Demo Sub Widget. Props: . State: . (click on me to update me)
+
`; + const BENCHMARK_APP = `//------------------------------------------------------------------------------ // Generating demo data //------------------------------------------------------------------------------ @@ -505,6 +568,11 @@ export const SAMPLES = [ code: WIDGET_COMPOSITION, xml: WIDGET_COMPOSITION_XML }, + { + description: "Lifecycle demo", + code: LIFECYCLE_DEMO, + xml: LIFECYCLE_DEMO_XML + }, { description: "Benchmark application", code: BENCHMARK_APP,