OSDN Git Service

Version 0.6.170, X.Audio is working ADVANCED_OPTIMIZATIONS.
[pettanr/clientJs.git] / 0.6.x / js / 01_core / 15_XEventDispatcher.js
index 5a5b17d..91e10b8 100644 (file)
@@ -15,7 +15,7 @@
  * <dd>dispatch 中か?さらにインスタンス自身の dispatch がネストした場合、その深さを記憶します。\r
  * <dt>2:RESERVES Array\r
  * <dd>イベント発火中に listen() が呼ばれた場合に引数を蓄え、完了時(DISPATCHING===0)に再度 listen() するための一時ストアです。\r
- * <dt>3:UNLISTENS Array\r
+ * <dt>3:UNLISTENS Object\r
  * <dd>イベント発火中に unlisten() が呼ばれた場合に対象リスナを記憶し、リスナが呼ばれないようにします。完了時(DISPATCHING===0)に再度 unlisten() します。\r
  * <dt>4:KILL_RESERVED boolean\r
  * <dd>dispatch 中に kill() が呼ばれた場合に一旦 kill をキャンセルし、完了時(DISPATCHING===0)に再度 kill() するためのフラグです。\r
@@ -176,7 +176,7 @@ var X_EventDispatcher = X[ 'EventDispatcher' ] =
                                if( !listeners || !( list = listeners[ opt_type ] ) ) return false;\r
                                if( opt_arg1 === undefined ) return X_EventDispatcher_needsIndex ? 0 : true;\r
                                \r
-                               // TODO callbackHash か?判定が不十分!\r
+                               // TODO callbackHash か?判定が不十分! skipConvertion\r
                                if( opt_arg1.kind ){\r
                                        cbHash = opt_arg1;\r
                                } else {\r
@@ -189,6 +189,7 @@ var X_EventDispatcher = X[ 'EventDispatcher' ] =
                                                if( f === cbHash || ( f.context === cbHash.context && f.func === cbHash.func && f.name === cbHash.name && f.supplement === cbHash.supplement && f.lock === lock ) ) return false;\r
                                        };\r
                                };\r
+                               \r
                                for( i = list.length; i; ){\r
                                        f = list[ --i ];\r
                                        if( f === cbHash || ( f.context === cbHash.context && f.func === cbHash.func && f.name === cbHash.name && f.supplement === cbHash.supplement && f.lock === lock ) ){\r
@@ -215,6 +216,9 @@ var X_EventDispatcher = X[ 'EventDispatcher' ] =
                                        e = delay;\r
                                        delay = 0;\r
                                };\r
+                               //{+dev\r
+                               delay === undefined && eval( 'throw "asyncDispatch で undefined イベントが指定されました"' );\r
+                               //}+dev\r
                                timerID = X_Timer_add( delay, 1, this, X_EventDispatcher_dispatch, [ e ] );\r
                                X_EventDispatcher_LAZY_TIMERS[ timerID ] = this;\r
                                return timerID;\r
@@ -255,22 +259,24 @@ function X_EventDispatcher_dispatch( e ){
        } else {\r
                listeners[ X_LISTENERS_DISPATCHING ] = 1;\r
        };\r
-       \r
-       // todo:\r
-       // type も保存\r
-       listeners[ X_LISTENERS_UNLISTENS ] = listeners[ X_LISTENERS_UNLISTENS ] || {};\r
-       unlistens = listeners[ X_LISTENERS_UNLISTENS ][ type ];\r
+\r
+       //listeners[ X_LISTENERS_UNLISTENS ] = listeners[ X_LISTENERS_UNLISTENS ] || {};\r
+       //unlistens = listeners[ X_LISTENERS_UNLISTENS ][ type ];\r
        \r
        for( i = 0; i < list.length; ++i ){\r
                f = list[ i ];\r
+               // TODO removed フラグは?\r
+               if( f.removed ) continue;\r
+               /*\r
                if( !unlistens ){\r
                        unlistens = listeners[ X_LISTENERS_UNLISTENS ][ type ];\r
                };\r
                if( unlistens && unlistens.indexOf( f ) !== -1 ) continue;\r
+               */\r
                \r
-               r = X_Closure_proxyCallback( f, args || ( args = [ e ] ) ) || 0;\r
+               r = X_Closure_proxyCallback( f, args || ( args = [ e ] ) );\r
                \r
-               if( f.once || r & X_CALLBACK_UN_LISTEN ){\r
+               if( f.once || ( r & X_CALLBACK_UN_LISTEN ) ){\r
                        // dispatch 中に unlisten が作られることがある\r
                        if( !unlistens ){\r
                                unlistens = listeners[ X_LISTENERS_UNLISTENS ] || ( listeners[ X_LISTENERS_UNLISTENS ] = {} );\r
@@ -455,13 +461,17 @@ function X_EventDispatcher_unlisten( opt_type, opt_arg1, opt_arg2, opt_arg3 ){
 \r
        f = ( list = listeners[ opt_type ] )[ i ];\r
        \r
-       if( unlistens = listeners[ X_LISTENERS_UNLISTENS ] ){\r
+       if( listeners[ X_LISTENERS_DISPATCHING ] ){\r
+               unlistens = listeners[ X_LISTENERS_UNLISTENS ] || ( listeners[ X_LISTENERS_UNLISTENS ] = {} );\r
                // _unlistens に入っている callbackHash は、lock のチェックは済んでいる\r
                ( unlistens = unlistens[ opt_type ] ) ?\r
                        ( unlistens[ unlistens.length ] = f ) :\r
                        ( listeners[ X_LISTENERS_UNLISTENS ][ opt_type ] = [ f ] );\r
+               f.removed = true;\r
        } else {\r
-               delete f.once;\r
+               //delete f.once;\r
+               X_Object_clear( f );\r
+               \r
                if( list.length !== 1 ){\r
                        list.splice( i, 1 );\r
                } else {\r