Skip to content
This repository has been archived by the owner on Jan 19, 2018. It is now read-only.

Commit

Permalink
Fix #2, #4, use node.js for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cho45 committed Sep 16, 2010
1 parent b3f9fa6 commit d1e3320
Show file tree
Hide file tree
Showing 10 changed files with 551 additions and 62 deletions.
4 changes: 3 additions & 1 deletion Rakefile
Expand Up @@ -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}"
Expand Down Expand Up @@ -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 }"
Expand Down
2 changes: 1 addition & 1 deletion binding/jquery.js
@@ -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);
}
Expand Down
55 changes: 28 additions & 27 deletions binding/userscript.js
@@ -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")
Expand Down Expand Up @@ -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;
}
6 changes: 4 additions & 2 deletions jsdeferred.jquery.js
Expand Up @@ -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));
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 3 additions & 1 deletion jsdeferred.js
Expand Up @@ -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));
Expand Down Expand Up @@ -603,3 +603,5 @@ Deferred.define = function (obj, list) {
return Deferred;
};

this.Deferred = Deferred;

0 comments on commit d1e3320

Please sign in to comment.