2020-02-02 09:13:54 +01:00
|
|
|
<h1 align="center">🦉 <a href="https://odoo.github.io/owl/">OWL Framework</a> 🦉</h1>
|
2019-01-17 18:08:39 +01:00
|
|
|
|
2019-11-22 09:40:51 +01:00
|
|
|
_Class based components with hooks, reactive state and concurrent mode_
|
2019-05-01 11:00:49 +02:00
|
|
|
|
2019-03-28 09:49:19 +01:00
|
|
|
## Project Overview
|
2019-01-28 10:59:46 +01:00
|
|
|
|
2019-11-22 09:40:51 +01:00
|
|
|
The Odoo Web Library (OWL) is a smallish (~<20kb gzipped) UI framework intended to
|
2019-09-27 16:48:54 +02:00
|
|
|
be the basis for the [Odoo](https://www.odoo.com/) Web Client. Owl is a modern
|
|
|
|
|
framework, written in Typescript, taking the best ideas from React and Vue in a
|
|
|
|
|
simple and consistent way. Owl's main features are:
|
|
|
|
|
|
|
|
|
|
- a declarative component system,
|
|
|
|
|
- a reactivity system based on hooks,
|
2020-02-02 09:13:54 +01:00
|
|
|
- concurrent mode by default,
|
|
|
|
|
- a store and a frontend router
|
2019-04-23 11:46:08 +02:00
|
|
|
|
2020-01-24 15:41:39 +01:00
|
|
|
Owl components are defined with ES6 classes, they use QWeb templates, an
|
2020-02-02 09:13:54 +01:00
|
|
|
underlying virtual DOM, integrates beautifully with hooks, and the rendering is
|
2020-01-24 15:41:39 +01:00
|
|
|
asynchronous.
|
2019-09-27 16:48:54 +02:00
|
|
|
|
2020-01-24 15:41:39 +01:00
|
|
|
**Try it online!** An online playground is available at
|
|
|
|
|
[https://odoo.github.io/owl/playground](https://odoo.github.io/owl/playground)
|
|
|
|
|
to let you experiment with the Owl framework. There are some code examples to
|
|
|
|
|
showcase some interesting features.
|
2019-05-01 11:00:49 +02:00
|
|
|
|
2020-01-24 15:41:39 +01:00
|
|
|
Owl is currently stable. Possible future changes are explained in the
|
2019-10-17 18:14:29 +02:00
|
|
|
[roadmap](roadmap.md).
|
|
|
|
|
|
2020-01-24 15:41:39 +01:00
|
|
|
## Why Owl?
|
|
|
|
|
|
|
|
|
|
Why did Odoo decide to make Yet Another Framework? This is really a question
|
2020-02-02 09:13:54 +01:00
|
|
|
that deserves [a long answer](doc/miscellaneous/why_owl.md). But in short, we believe that
|
2020-01-24 15:41:39 +01:00
|
|
|
while the current state of the art frameworks are excellent, they are not
|
|
|
|
|
optimized for our use case, and there is still room for something else.
|
|
|
|
|
|
|
|
|
|
If you are interested in a comparison with React or Vue, you will
|
2020-02-02 09:13:54 +01:00
|
|
|
find some more additional information [here](doc/miscellaneous/comparison.md).
|
2020-01-24 15:41:39 +01:00
|
|
|
|
2019-06-14 15:24:04 +02:00
|
|
|
## Example
|
2019-01-28 10:59:46 +01:00
|
|
|
|
2019-06-20 09:42:33 +02:00
|
|
|
Here is a short example to illustrate interactive components:
|
2019-03-27 15:40:24 +01:00
|
|
|
|
|
|
|
|
```javascript
|
2019-10-30 10:22:59 +01:00
|
|
|
const { Component, useState } = owl;
|
2019-10-26 09:26:39 +02:00
|
|
|
const { xml } = owl.tags;
|
2019-09-12 09:45:32 +02:00
|
|
|
|
|
|
|
|
class Counter extends Component {
|
|
|
|
|
static template = xml`
|
2019-10-26 09:26:39 +02:00
|
|
|
<button t-on-click="state.value++">
|
2019-09-12 09:45:32 +02:00
|
|
|
Click Me! [<t t-esc="state.value"/>]
|
|
|
|
|
</button>`;
|
|
|
|
|
|
2019-09-24 14:06:53 +02:00
|
|
|
state = useState({ value: 0 });
|
2019-03-27 15:40:24 +01:00
|
|
|
}
|
|
|
|
|
|
2019-09-12 09:45:32 +02:00
|
|
|
class App extends Component {
|
|
|
|
|
static template = xml`
|
|
|
|
|
<div>
|
|
|
|
|
<span>Hello Owl</span>
|
|
|
|
|
<Counter />
|
|
|
|
|
</div>`;
|
|
|
|
|
|
2019-09-11 14:01:49 +02:00
|
|
|
static components = { Counter };
|
2019-08-28 12:10:46 +02:00
|
|
|
}
|
|
|
|
|
|
2019-10-30 10:22:59 +01:00
|
|
|
const app = new App();
|
2019-08-28 12:10:46 +02:00
|
|
|
app.mount(document.body);
|
2019-04-23 15:26:00 +02:00
|
|
|
```
|
2019-03-27 16:42:21 +01:00
|
|
|
|
2019-10-28 09:03:55 +01:00
|
|
|
Note that the counter component is made reactive with the [`useState` hook](doc/reference/hooks.md#usestate).
|
|
|
|
|
Also, all examples here uses the [`xml` helper](doc/reference/tags.md#xml-tag) to define inline templates.
|
2019-09-27 16:48:54 +02:00
|
|
|
But this is not mandatory, many applications will load templates separately.
|
2019-09-24 14:06:53 +02:00
|
|
|
|
2019-09-12 09:45:32 +02:00
|
|
|
More interesting examples can be found on the
|
2019-06-15 10:38:29 +02:00
|
|
|
[playground](https://odoo.github.io/owl/playground) application.
|
2019-03-27 15:40:24 +01:00
|
|
|
|
2019-09-27 16:48:54 +02:00
|
|
|
## Design Principles
|
2019-08-28 12:05:53 +02:00
|
|
|
|
|
|
|
|
OWL is designed to be used in highly dynamic applications where changing
|
|
|
|
|
requirements are common and code needs to be maintained by large teams.
|
|
|
|
|
|
|
|
|
|
- **XML based**: templates are based on the XML format, which allows interesting
|
|
|
|
|
applications. For example, they could be stored in a database and modified
|
|
|
|
|
dynamically with `xpaths`.
|
|
|
|
|
- **templates compilation in the browser**: this may not be a good fit for all
|
|
|
|
|
applications, but if you need to generate dynamically user interfaces in the
|
|
|
|
|
browser, this is very powerful. For example, a generic form view component
|
|
|
|
|
could generate a specific form user interface for each various models, from a XML view.
|
|
|
|
|
- **no toolchain required**: this is extremely useful for some applications, if,
|
|
|
|
|
for various reasons (security/deployment/dynamic modules/specific assets tools),
|
|
|
|
|
it is not ok to use standard web tools based on `npm`.
|
|
|
|
|
|
|
|
|
|
Owl is not designed to be fast nor small (even though it is quite good on those
|
2019-09-11 14:01:49 +02:00
|
|
|
two topics). It is a no nonsense framework to build applications. There is only
|
2020-02-02 09:13:54 +01:00
|
|
|
one way to define components (with classes). There is no black magic. It just
|
|
|
|
|
works.
|
2019-08-28 12:05:53 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
## Documentation
|
|
|
|
|
|
2019-10-10 12:27:32 +02:00
|
|
|
A complete documentation for Owl can be found here:
|
|
|
|
|
|
|
|
|
|
- [Main documentation page](doc/readme.md).
|
|
|
|
|
|
2020-02-02 09:13:54 +01:00
|
|
|
Some of the most important pages are:
|
2019-08-28 12:05:53 +02:00
|
|
|
|
2019-11-11 17:31:34 +01:00
|
|
|
- [Tutorial: TodoList application](doc/learning/tutorial_todoapp.md)
|
2020-02-02 09:13:54 +01:00
|
|
|
- [How to start an Owl project](doc/learning/quick_start.md)
|
2019-11-11 17:31:34 +01:00
|
|
|
- [QWeb templating language](doc/reference/qweb_templating_language.md)
|
2019-10-28 09:03:55 +01:00
|
|
|
- [Component](doc/reference/component.md)
|
|
|
|
|
- [Hooks](doc/reference/hooks.md)
|
2019-08-28 12:05:53 +02:00
|
|
|
|
|
|
|
|
|
2020-02-02 09:13:54 +01:00
|
|
|
## Installing Owl
|
2019-03-27 15:40:24 +01:00
|
|
|
|
2020-02-02 09:13:54 +01:00
|
|
|
Owl is available on `npm` and can be installed with the following command:
|
2019-12-19 14:12:00 +01:00
|
|
|
|
|
|
|
|
```
|
|
|
|
|
npm install @odoo/owl
|
|
|
|
|
```
|
|
|
|
|
|
2019-04-23 15:26:00 +02:00
|
|
|
If you want to use a simple `<script>` tag, the last release can be downloaded here:
|
2019-03-27 15:40:24 +01:00
|
|
|
|
2020-06-02 10:38:32 +02:00
|
|
|
- [owl-1.0.9.js](https://github.com/odoo/owl/releases/download/v1.0.9/owl.js)
|
|
|
|
|
- [owl-1.0.9.min.js](https://github.com/odoo/owl/releases/download/v1.0.9/owl.min.js)
|
2019-04-23 15:26:00 +02:00
|
|
|
|
2019-03-28 09:49:19 +01:00
|
|
|
## License
|
|
|
|
|
|
2019-08-28 12:10:46 +02:00
|
|
|
OWL is [LGPL licensed](./LICENSE).
|