Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

h5.async.when()に渡したprogressフィルタを、notifyWithで呼び出した時にコンテキストが正しくセットされていない #219

Closed
fukudayasuo opened this issue May 30, 2013 · 1 comment
Assignees
Labels
Milestone

Comments

@fukudayasuo
Copy link

whenに渡したdeferredをnotifyWithした時に、when()の戻り値から追加したprogressフィルタが実行されるが、その中のthisがrejectWithで指定したものになっていない。notify時と同様にnotifyしたdfdオブジェクトになっている。

jQuery.whenのprogressは、whenに渡したものからnotifyWithを呼ぶと、thisが配列にになる。

var context;
$.when(df1, df2).progress(function(){ context = this; });
df1.notifyWith({a:1});
// context [{a:1}, undefined]
df2.notifyWith({b:1});
// context [{a:1}, {b:1}]

jQuery.whenと同じような挙動にする。

@ghost ghost assigned fukudayasuo May 30, 2013
fukudayasuo pushed a commit to hifive-labs/hifivemain that referenced this issue May 31, 2013
@fukudayasuo
Copy link
Author

jQueryのバージョンによってcontextが異なります。jQuery1.8.0以降なら各dfdのreject/rejectWith時のthisが配列になって格納されます。(上記説明と同じ)。
しかしjQuery1.7以下では以下のような挙動になります。

// retは$.whenの戻り値のプロミス
notify/notifyWith: this === ret
resolve/resolveWith: thisはretの元のdeferred。(this !== ret; this.promise() === ret;)
reject: this === rejectを呼んだdeferred
rejectWith: this === rejectWithの第一引数

jQuery1.6.4にnotify/notifyWithはありませんが、それいがいはjQuery1.7と同じ挙動でした。

h5.async.whenでは基本的には$.whenのコールバックに渡されたthisを使用するようにしますが、thisが$.when()の戻り値のプロミスまたはそのプロミスの元となっているdeferredの場合(notify/notifyWith/resolve/resolveWithの場合)は、h5.async.whenの戻り値のプロミスまたはそのdeferredに差し替えるようにしました。(上記コミットで対応しています。)

fukudayasuo pushed a commit to hifive-labs/hifivemain that referenced this issue May 31, 2013
@simdy simdy closed this as completed Jun 4, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants