Files
owl/doc/utils.md
T
2019-06-11 10:23:46 +02:00

1.3 KiB

🦉 Utils 🦉

Owl export a few useful utility functions, to help with common issues. Those functions are all available in the owl.utils namespace.

Content

whenReady

The function whenReady is useful to register some code that need to be executed as soon as the document (page) is ready:

owl.utils.whenReady(function() {
  const qweb = new owl.QWeb();
  const app = new App({ qweb });
  app.mount(document.body);
});

loadJS

loadJS takes a url (string) for a javascript resource, and loads it. It returns a promise, so the caller can properly react when it is ready. Also, it is smart: it maintains a list of urls previously loaded (or currently being loaded), and prevent doing twice the work.

class MyComponent extends owl.Component {
    willStart() {
        return owl.utils.loadJS('/static/libs/someLib.js');
    }
}

loadTemplates

async function makeEnv() {
    const templates = await owl.utils.loadTemplates('templates.xml');
    const qweb = new owl.QWeb(templates);
    return { qweb };
}

escape

debounce