diff --git a/README.md b/README.md index 8f86f711..c061da06 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ find some more additional information [here](doc/miscellaneous/comparison.md). Here is a short example to illustrate interactive components: ```javascript -const { Component, useState } = owl; +const { Component, useState, mount } = owl; const { xml } = owl.tags; class Counter extends Component { @@ -63,8 +63,7 @@ class App extends Component { static components = { Counter }; } -const app = new App(); -app.mount(document.body); +mount(App, { target: document.body }); ``` Note that the counter component is made reactive with the [`useState` hook](doc/reference/hooks.md#usestate). diff --git a/doc/learning/how_to_test.md b/doc/learning/how_to_test.md index b8fb4901..ca1fd70c 100644 --- a/doc/learning/how_to_test.md +++ b/doc/learning/how_to_test.md @@ -85,8 +85,7 @@ afterEach(() => { describe("SomeComponent", () => { test("component behaves as expected", async () => { const props = {...}; // depends on the component - const comp = new SomeComponent(null, props); - await comp.mount(fixture); + const comp = await mount(SomeComponent, { target: fixture, props }); // do some assertions expect(...).toBe(...); diff --git a/doc/learning/quick_start.md b/doc/learning/quick_start.md index e4f99246..48deae64 100644 --- a/doc/learning/quick_start.md +++ b/doc/learning/quick_start.md @@ -54,7 +54,7 @@ Now, `index.html` should contain the following: And `app.js` should look like this: ```js -const { Component } = owl; +const { Component, mount } = owl; const { xml } = owl.tags; const { whenReady } = owl.utils; @@ -65,8 +65,7 @@ class App extends Component { // Setup code function setup() { - const app = new App(); - app.mount(document.body); + mount(App, target: { document.body }) } whenReady(setup); @@ -124,7 +123,7 @@ Here is the content of `app.js` and `main.js`: ```js // app.js ---------------------------------------------------------------------- -const { Component } = owl; +const { Component, mount } = owl; const { xml } = owl.tags; export class App extends Component { @@ -135,8 +134,7 @@ export class App extends Component { import { App } from "./app.js"; function setup() { - const app = new App(); - app.mount(document.body); + mount(App, { target: document.body }); } owl.utils.whenReady(setup); @@ -240,12 +238,11 @@ export class App extends Component { } // src/main.js ----------------------------------------------------------------- -import { utils } from "@odoo/owl"; +import { utils, mount } from "@odoo/owl"; import { App } from "./components/App"; function setup() { - const app = new App(); - app.mount(document.body); + mount(App, { target: document.body }); } utils.whenReady(setup); @@ -253,6 +250,7 @@ utils.whenReady(setup); // tests/components/App.test.js ------------------------------------------------ import { App } from "../../src/components/App"; import { makeTestFixture, nextTick, click } from "../helpers"; +import { mount } from "@odoo/owl"; let fixture; @@ -266,8 +264,7 @@ afterEach(() => { describe("App", () => { test("Works as expected...", async () => { - const app = new App(); - await app.mount(fixture); + await mount(App, { target: fixture }); expect(fixture.innerHTML).toBe("
pre-existing
`; fixture.appendChild(div); - const app = new App(); - await app.mount(div, { position: "self" }); + const app = await mount(App, { target: div, position: "self" }); expect(fixture.innerHTML).toBe( `pre-existing
appanother tag