add quick start section to doc

This commit is contained in:
Géry Debongnie
2019-03-14 14:12:51 +01:00
parent 80745c6b09
commit 5d87ee5c9e
2 changed files with 64 additions and 2 deletions
+3 -2
View File
@@ -72,5 +72,6 @@ that assets are properly rebuilt if necessary, and then reloaded.
## Documentation
[Component](doc/component.md)
[QWeb](doc/qweb.md)
- [Quick Start](doc/quick_start.md)
- [Component](doc/component.md)
- [QWeb](doc/qweb.md)
+61
View File
@@ -0,0 +1,61 @@
# Quick Start
To build an application (or a sub-part of an application), we need two things:
- an environment
- a root widget
Here are a few steps that may be useful to get started:
- get the templates
- create a qweb engine, with the templates
- create an environment
- create an instance of the root widget
- mount the root widget to a DOM element
## Simple example
In a oversimplified example, here is what it could look like:
```javascript
const templates = await loadTemplates();
const qweb = new QWeb();
qweb.loadTemplates(templates);
const env = {
qweb: qweb
};
const root = new RootWidget(env, { initialState: 17 });
const target = document.getElementById("app");
root.mount(target);
```
## Managing state
The environment is propagated to each subchildren. So, it is convenient to use
to give a reference to some global object. This is potentially very useful
in a redux-like architecture:
```javascript
...
const store = new Store();
const env = {
qweb: qweb,
store: store,
};
const state = store.getState()
const root = new RootWidget(env, state);
store.on('state_change', nextState => {
root.updateProps(nextState);
});
const target = document.getElementById('app');
root.mount(target);
```