[Pkg-javascript-commits] [less.js] 169/285: refresh returns promise
Jonas Smedegaard
dr at jones.dk
Mon Oct 26 23:23:51 UTC 2015
This is an automated email from the git hooks/post-receive script.
js pushed a commit to annotated tag v2.0.0
in repository less.js.
commit a0b1b2f4bd35df1fdf467248684a32f3e6dc82c4
Author: Levi Thomason <me at levithomason.com>
Date: Sun Oct 12 15:57:57 2014 -0700
refresh returns promise
pass the error to reject()
---
lib/less-browser/index.js | 51 ++++++++++++++++++++++++++---------------------
1 file changed, 28 insertions(+), 23 deletions(-)
diff --git a/lib/less-browser/index.js b/lib/less-browser/index.js
index fcad374..32cca36 100644
--- a/lib/less-browser/index.js
+++ b/lib/less-browser/index.js
@@ -26,6 +26,7 @@ require("./log-listener")(less, options);
var errors = require("./error-reporting")(window, less, options);
var browser = require("./browser");
var cache = options.cache || require("./cache")(window, options, less.logger);
+var PromiseConstructor = typeof Promise === 'undefined' ? require('promise') : Promise;
options.env = options.env || (window.location.hostname == '127.0.0.1' ||
window.location.hostname == '0.0.0.0' ||
@@ -242,29 +243,33 @@ less.modifyVars = function(record) {
};
less.refresh = function (reload, modifyVars) {
- var startTime, endTime;
- startTime = endTime = new Date();
-
- loadStyleSheets(function (e, css, _, sheet, webInfo) {
- if (e) {
- return errors.add(e, e.href || sheet.href);
- }
- if (webInfo.local) {
- less.logger.info("loading " + sheet.href + " from cache.");
- } else {
- less.logger.info("rendered " + sheet.href + " successfully.");
- css = postProcessCSS(css);
- browser.createCSS(window.document, css, sheet);
- cache.setCSS(sheet.href, webInfo.lastModified, css);
- }
- less.logger.info("css for " + sheet.href + " generated in " + (new Date() - endTime) + 'ms');
- if (webInfo.remaining === 0) {
- less.logger.info("less has finished. css generated in " + (new Date() - startTime) + 'ms');
- }
- endTime = new Date();
- }, reload, modifyVars);
-
- loadStyles(modifyVars);
+ return new PromiseConstructor(function(resolve, reject) {
+ var startTime, endTime;
+ startTime = endTime = new Date();
+
+ loadStyleSheets(function (e, css, _, sheet, webInfo) {
+ if (e) {
+ errors.add(e, e.href || sheet.href);
+ reject(e);
+ }
+ if (webInfo.local) {
+ less.logger.info("loading " + sheet.href + " from cache.");
+ } else {
+ less.logger.info("rendered " + sheet.href + " successfully.");
+ css = postProcessCSS(css);
+ browser.createCSS(window.document, css, sheet);
+ cache.setCSS(sheet.href, webInfo.lastModified, css);
+ }
+ less.logger.info("css for " + sheet.href + " generated in " + (new Date() - endTime) + 'ms');
+ if (webInfo.remaining === 0) {
+ less.logger.info("less has finished. css generated in " + (new Date() - startTime) + 'ms');
+ resolve();
+ }
+ endTime = new Date();
+ }, reload, modifyVars);
+
+ loadStyles(modifyVars);
+ });
};
less.refreshStyles = loadStyles;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/less.js.git
More information about the Pkg-javascript-commits
mailing list