4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Sencha Touch 2でのイベントキャプチャー

Last updated at Posted at 2013-02-07

Ext JSやSencha Touch 1では、あるオブジェクトのイベントをすべてキャプチャーする、
captureというメソッドが、Ext.util.Observableにありました。

このメソッドは、デバッグの時や、コンポーネントのイベント発火の挙動を確かめるときに非常に便利です。

Ext.util.Observable.capture(someCmp, function () {
    console.log(argumetns);
});

なんてやっておくと、someCmpで何かイベントが発生したら全部ログしてくれます。
そのログをみて、「はぁ、こういう風に動くんだ」とか「あ!ここではイベント発火しないんだ!」とかわかるわけです。

と、開発時に便利なメソッドなんですが、Sencha Touch 2では廃止されて、なくなってしまいました。そのことをつぶやいたら、 @kotsutsumi さんが同じ事をやる方法を教えてくれました。

Ext.define('Override.mixin.Observable', {
    override : 'Ext.mixin.Observable',

    fireEvent : function(eventName) {
        console.log(eventName);

        this.callOverridden(arguments);
    },

    fireAction : function(eventName) {
        console.log(eventName);

        this.callOverridden(arguments);
    }
});

ちなみに、Ext.util.ObservableもExt.mixin.ObservableもSencha Touch 2では同じです。

Ext.defineのoverride指定で、fireEventをオーバーライドしています。
これを実行した後にイベントを装着したクラスをインスタンス化したら、
それらみんなのオブジェクトをキャプチャーできるようになります。

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?