[Pkg-javascript-commits] [less.js] 41/285: Return a promise rather than an event emitter
Jonas Smedegaard
dr at jones.dk
Mon Oct 26 23:23:35 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 b2820b09f4747e049ca73ce6a3029b21dfb13720
Author: Forbes Lindesay <forbes.lindesay at red-gate.com>
Date: Tue May 20 15:36:04 2014 +0100
Return a promise rather than an event emitter
[discussed in #1902]
---
lib/less/index.js | 15 ++++++---------
package.json | 3 ++-
2 files changed, 8 insertions(+), 10 deletions(-)
diff --git a/lib/less/index.js b/lib/less/index.js
index 043029e..058bfd9 100644
--- a/lib/less/index.js
+++ b/lib/less/index.js
@@ -1,3 +1,4 @@
+var Promise = require('promise');
var less = require("./non-node-index.js");
less.render = function (input, options, callback) {
@@ -8,8 +9,7 @@ less.render = function (input, options, callback) {
options = {};
}
- var parser = new(less.Parser)(options),
- ee;
+ var parser = new(less.Parser)(options);
if (callback) {
parser.parse(input, function (e, root) {
@@ -22,16 +22,13 @@ less.render = function (input, options, callback) {
callback(null, css);
});
} else {
- ee = new (require('events').EventEmitter)();
-
- process.nextTick(function () {
+ return new Promise(function (resolve, reject) {
parser.parse(input, function (e, root) {
- if (e) { return ee.emit('error', e); }
- try { ee.emit('success', root.toCSS(options)); }
- catch (err) { ee.emit('error', err); }
+ if (e) { return reject(e); }
+ try { resolve(root.toCSS(options)); }
+ catch (err) { reject( err); }
});
});
- return ee;
}
};
less.formatError = function(ctx, options) {
diff --git a/package.json b/package.json
index 747b875..65f8e47 100644
--- a/package.json
+++ b/package.json
@@ -44,7 +44,8 @@
"request": ">=2.33.0",
"mkdirp": "~0.3.5",
"clean-css": "2.1.x",
- "source-map": "0.1.x"
+ "source-map": "0.1.x",
+ "promise": "~5.0.0"
},
"devDependencies": {
"diff": "~1.0",
--
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