Permalink
Browse files

Fix #2, #4, use node.js for tests

  • Loading branch information...
1 parent b3f9fa6 commit d1e3320e6015fab1c76de06469d3373c55d5321e @cho45 committed Sep 16, 2010
Showing with 551 additions and 62 deletions.
  1. +3 −1 Rakefile
  2. +1 −1 binding/jquery.js
  3. +28 −27 binding/userscript.js
  4. +4 −2 jsdeferred.jquery.js
  5. +3 −1 jsdeferred.js
  6. +345 −0 jsdeferred.node.js
  7. +4 −2 jsdeferred.nodoc.js
  8. +23 −20 jsdeferred.userscript.js
  9. +44 −8 test-jsdeferred.js
  10. +96 −0 test-node.js
View
@@ -39,7 +39,8 @@ task :create => RELEASES
desc "Test JSDeferred"
task :test => RELEASES do
- sh %{rhino -opt 0 -w -strict test-rhino.js jsdeferred.js}
+ # sh %{rhino -opt 0 -w -strict test-rhino.js jsdeferred.js}
+ sh %{node test-node.js}
end
desc "Make all release file and tagging #{Version}"
@@ -88,6 +89,7 @@ file "jsdeferred.jquery.js" => ["jsdeferred.js", "binding/jquery.js"] do |t|
}
end
+
file "jsdeferred.userscript.js" => ["jsdeferred.js", "binding/userscript.js"] do |t|
File.open(t.name, "w") {|f|
f.puts "// Usage:: with (D()) { your code }"
View
@@ -1,7 +1,7 @@
(function ($) {
$.deferred = Deferred;
$.fn.extend({
- deferred: function(name) {
+ deferred: function (name) {
var args = Array.prototype.slice.call(arguments, 1);
return Deferred.connect(this[name], { target:this }).apply(null, args);
}
View
@@ -1,32 +1,6 @@
function D () {
/*include JSDeferred*/
-/* function xhttp (opts) //=> Deferred
- * Cross site version of `http`.
- */
-/* function xhttp.get (url) //=> Deferred
- */
-/* function xhttp.post (url, data) //=> Deferred
- */
-function xhttp (opts) {
- var d = Deferred();
- if (opts.onload) d = d.next(opts.onload);
- if (opts.onerror) d = d.error(opts.onerror);
- opts.onload = function (res) {
- d.call(res);
- };
- opts.onerror = function (res) {
- d.fail(res);
- };
- setTimeout(function () {
- GM_xmlhttpRequest(opts);
- }, 0);
- return d;
-}
-xhttp.get = function (url) { return xhttp({method:"get", url:url}) };
-xhttp.post = function (url, data) { return xhttp({method:"post", url:url, data:data, headers:{"Content-Type":"application/x-www-form-urlencoded"}}) };
-
-
/* function http (opts) //=> Deferred
* Sample:
* http.get("http://example.com/hogehoge")
@@ -91,8 +65,35 @@ http.jsonp = function (url, params) {
return d;
};
+/* function xhttp (opts) //=> Deferred
+ * Cross site version of `http`.
+ */
+/* function xhttp.get (url) //=> Deferred
+ */
+/* function xhttp.post (url, data) //=> Deferred
+ */
+function xhttp (opts) {
+ var d = Deferred();
+ if (opts.onload) d = d.next(opts.onload);
+ if (opts.onerror) d = d.error(opts.onerror);
+ opts.onload = function (res) {
+ d.call(res);
+ };
+ opts.onerror = function (res) {
+ d.fail(res);
+ };
+ setTimeout(function () {
+ GM_xmlhttpRequest(opts);
+ }, 0);
+ return d;
+}
+xhttp.get = function (url) { return xhttp({method:"get", url:url}) };
+xhttp.post = function (url, data) { return xhttp({method:"post", url:url, data:data, headers:{"Content-Type":"application/x-www-form-urlencoded"}}) };
+
+
+
Deferred.Deferred = Deferred;
Deferred.http = http;
-Deferred.xhttp = xhttp;
+Deferred.xhttp = (typeof(GM_xmlhttpRequest) == 'undefined') ? http : xhttp;
return Deferred;
}
View
@@ -284,7 +284,7 @@ Deferred.connect = function () {
var d = new Deferred();
d.next = function (fun) { return this._post("ok", function () {
- fun.apply(this, (arguments[0] instanceof Deferred.Arguments) ? arguments[0].args : arguments);
+ return fun.apply(this, (arguments[0] instanceof Deferred.Arguments) ? arguments[0].args : arguments);
}) };
var args = partialArgs.concat(Array.prototype.slice.call(arguments, 0));
@@ -336,10 +336,12 @@ Deferred.define = function (obj, list) {
return Deferred;
};
+this.Deferred = Deferred;
+
(function ($) {
$.deferred = Deferred;
$.fn.extend({
- deferred: function(name) {
+ deferred: function (name) {
var args = Array.prototype.slice.call(arguments, 1);
return Deferred.connect(this[name], { target:this }).apply(null, args);
}
View
@@ -536,7 +536,7 @@ Deferred.connect = function () {
var d = new Deferred();
d.next = function (fun) { return this._post("ok", function () {
- fun.apply(this, (arguments[0] instanceof Deferred.Arguments) ? arguments[0].args : arguments);
+ return fun.apply(this, (arguments[0] instanceof Deferred.Arguments) ? arguments[0].args : arguments);
}) };
var args = partialArgs.concat(Array.prototype.slice.call(arguments, 0));
@@ -603,3 +603,5 @@ Deferred.define = function (obj, list) {
return Deferred;
};
+this.Deferred = Deferred;
+
Oops, something went wrong.

0 comments on commit d1e3320

Please sign in to comment.