diff options
| author | Aaron Bohy <aab@odoo.com> | 2017-04-26 09:18:15 +0200 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2017-04-26 11:19:20 +0200 |
| commit | bead8452c262e81597cd87269ea008991cd20fed (patch) | |
| tree | 0bb2c6d1ffb5bc1a6089d3cfa30976a1a262dc9a /addons/web/static/src/js | |
| parent | 8f9362809e91ff7c2876ab464017abb13a4e0974 (diff) | |
[FIX] web: Views: sequential lazy loading of libs
The views can specify js (and css) libraries to lazy load when
they are instantiated for the first time. The previous
implementation was too naive as it always loaded the specified
libraries in parallel. However, it may happen (e.g. gantt view)
that some of those libraries depend on other ones.
This commit implements a mechanism to handle libs dependencies
between each other. For instance, specifying:
js_libs: [
['a', 'b'],
['c'],
],
will load 'a' and 'b' in parallel, but wait for them to be
loaded before loading 'c'.
The new implementation still supports the old syntax. So,
js_libs: ['a', 'b', 'c'],
will load 'a', 'b' and 'c' in parallel.
Diffstat (limited to 'addons/web/static/src/js')
| -rw-r--r-- | addons/web/static/src/js/views/abstract_view.js | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/addons/web/static/src/js/views/abstract_view.js b/addons/web/static/src/js/views/abstract_view.js index fdb029da6c3..f4def9f69c8 100644 --- a/addons/web/static/src/js/views/abstract_view.js +++ b/addons/web/static/src/js/views/abstract_view.js @@ -185,8 +185,24 @@ var AbstractView = Class.extend({ */ _loadLibs: function () { var defs = []; - _.each(this.config.js_libs, function (url) { - defs.push(ajax.loadJS(url)); + var jsDefs; + _.each(this.config.js_libs, function (urls) { + if (typeof(urls) === 'string') { + // js_libs is an array of urls: those urls can be loaded in + // parallel + defs.push(ajax.loadJS(urls)); + } else { + // js_libs is an array of arrays of urls: those arrays of urls + // must be loaded sequentially, but the urls inside each + // sub-array can be loaded in parallel + defs.push($.when.apply($, jsDefs).then(function () { + jsDefs = []; + _.each(urls, function (url) { + jsDefs.push(ajax.loadJS(url)); + }); + return $.when.apply($, jsDefs); + })); + } }); _.each(this.config.css_libs, function (url) { defs.push(ajax.loadCSS(url)); |
