@@ -10,12 +10,13 @@ EventDispatcher.prototype = {
10
10
const types = type . split ( '.' ) ;
11
11
const _type = types [ 0 ] ;
12
12
const namespaces = types [ 1 ] ;
13
- let list = this . _listeners [ _type ] ;
13
+ const listName = `${ _type } ${ target ? target . getAttribute ( 'id' ) : '' } ` ;
14
+ let list = this . _listeners [ listName ] ;
14
15
let index = 0 ;
15
16
let listener ;
16
17
let i ;
17
18
if ( ! list ) {
18
- this . _listeners [ _type ] = list = [ ] ;
19
+ this . _listeners [ listName ] = list = [ ] ;
19
20
}
20
21
i = list . length ;
21
22
@@ -29,12 +30,12 @@ EventDispatcher.prototype = {
29
30
}
30
31
31
32
list . splice ( index , 0 , { c : callback , n : namespaces , t : _type } ) ;
32
- if ( ! this . _listFun [ _type ] ) {
33
- this . _listFun [ _type ] = this . _listFun [ _type ] || this . dispatchEvent . bind ( this , _type ) ;
33
+ if ( ! this . _listFun [ listName ] ) {
34
+ this . _listFun [ listName ] = this . _listFun [ listName ] || this . dispatchEvent . bind ( this , _type , target ) ;
34
35
if ( this . _eventTarget . addEventListener ) {
35
- ( target || this . _eventTarget ) . addEventListener ( _type , this . _listFun [ _type ] , false ) ;
36
+ ( target || this . _eventTarget ) . addEventListener ( _type , this . _listFun [ listName ] , false ) ;
36
37
} else if ( this . _eventTarget . attachEvent ) {
37
- ( target || this . _eventTarget ) . attachEvent ( `on${ _type } ` , this . _listFun [ _type ] ) ;
38
+ ( target || this . _eventTarget ) . attachEvent ( `on${ _type } ` , this . _listFun [ listName ] ) ;
38
39
}
39
40
}
40
41
} ,
@@ -43,7 +44,8 @@ EventDispatcher.prototype = {
43
44
const types = type . split ( '.' ) ;
44
45
const _type = types [ 0 ] ;
45
46
const namespaces = types [ 1 ] ;
46
- const list = this . _listeners [ _type ] ;
47
+ const listName = `${ _type } ${ target ? target . getAttribute ( 'id' ) : '' } ` ;
48
+ const list = this . _listeners [ listName ] ;
47
49
let i ;
48
50
let _force = force ;
49
51
if ( ! namespaces ) {
@@ -55,9 +57,9 @@ EventDispatcher.prototype = {
55
57
if ( list [ i ] . c === callback && ( _force || list [ i ] . n === namespaces ) ) {
56
58
list . splice ( i , 1 ) ;
57
59
if ( ! list . length ) {
58
- const func = this . _listFun [ _type ] ;
59
- delete this . _listeners [ _type ] ;
60
- delete this . _listFun [ _type ] ;
60
+ const func = this . _listFun [ listName ] ;
61
+ delete this . _listeners [ listName ] ;
62
+ delete this . _listFun [ listName ] ;
61
63
if ( this . _eventTarget . removeEventListener ) {
62
64
( target || this . _eventTarget ) . removeEventListener ( _type , func ) ;
63
65
} else if ( this . _eventTarget . detachEvent ) {
@@ -72,8 +74,9 @@ EventDispatcher.prototype = {
72
74
}
73
75
} ,
74
76
75
- dispatchEvent ( type , e ) {
76
- const list = this . _listeners [ type ] ;
77
+ dispatchEvent ( type , target , e ) {
78
+ const listName = `${ type } ${ target ? target . getAttribute ( 'id' ) : '' } ` ;
79
+ const list = this . _listeners [ listName ] ;
77
80
let i ;
78
81
let t ;
79
82
let listener ;
@@ -93,7 +96,8 @@ EventDispatcher.prototype = {
93
96
const types = type . split ( '.' ) ;
94
97
const _type = types [ 0 ] ;
95
98
const namespaces = types [ 1 ] ;
96
- const list = this . _listeners [ _type ] ;
99
+ const listName = `${ type } ${ target ? target . getAttribute ( 'id' ) : '' } ` ;
100
+ const list = this . _listeners [ listName ] ;
97
101
this . recoverLists = this . recoverLists . concat ( dataToArray ( list ) . filter ( item =>
98
102
item . n && item . n . match ( namespaces )
99
103
) ) ;
0 commit comments