2009-04-18

Enhancing of jQuery.ajax with JSDeferred 1.0.0 をリリースしました

こんばんは。なかじまんです。Enhancing of jQuery.ajax with JSDeferred 1.0.0 をリリースしました。

http://plugins.jquery.com/project/ajax-deferred

Enhancing of jQuery.ajax with JSDeferred は jQuery.ajax とショートカットのチェーンとエラーハンドリングを実現するものです。基本的な使い方は、過去エントリの Enhancing of jQuery.ajax with JSDeferred: jQuery.ajax チェーンとその short cut のエラーハンドリング を見てください。

今回のリリースでは、次のとおり jQuery.ajax とショートカットで deferred チェーンできるようにしました。

$.getJSON('/foo').next(function(foo) {
console.log('next', foo);
return $.getJSON('/bar').next(function(bar) {
console.log('bar', bar);
return [foo, bar];
});
}).next(function(foobar) {
console.log('foobar', foobar[0], foobar[1]);
}).post('/foo.json', { foo: 'bar' }).next(function() {
}).error(function(status) {
console.log('error', status);
});

また jQuery.ajax 以外から deferred チェーンを開始できるように jQuery.next を追加しました。さらに deferred チェーンを同期できるように jQuery.call を追加しました。これで、より複雑な状況にも対応できるようになりました。

$.next(function() {
function foo(a, b) {
return a + b;
};
return $.call(foo, 10, 1);
}).next(function(sum) {
console.log(sum);
});

また jQuery.wait を追加して、ちょい待ちにも対応できるようになりました。

$.wait(10).next(function() {
});

まとめると、次のメソッドが使えることになります。

jQuery.wait
jQuery.next
jQuery.call
jQuery.ajax
jQuery.get
jQuery.getJSON
jQuery.post
Deferred.next
Deferred.error
Deferred.call
Deferred.fail
Deferred.cancel
Deferred.wait
Deferred.next
Deferred.call
Deferred.ajax
Deferred.get
Deferred.getJSON
Deferred.post

以上は、次のバージョンの opensocial-jquery でも使えるようにします。

0 件のコメント: