@@ -3,7 +3,7 @@ const { throwMissingParam: missingParamEr, throwInvalidParam: invalidParamEr } =
3
3
export const apiConstructor = function ( getDeps , param = { options : { } } ) {
4
4
const { optionsManager, helper, activedTabsHistory } = getDeps . call ( this , param . options ) ;
5
5
helper . setNoneEnumProps ( this , { optionsManager, helper, activedTabsHistory } ) ;
6
- this . _setUserProxy ( ) . _subscribeSelectedTabsHistory ( ) . _subscribeCallbacksOptions ( ) . _subscribeOnChange ( ) ;
6
+ this . _setUserProxy ( ) . _subscribeSelectedTabsHistory ( ) . _subscribeCallbacksOptions ( ) ; // ._subscribeOnChange();
7
7
} ;
8
8
const _apiProps = {
9
9
_setUserProxy : function ( ) {
@@ -23,22 +23,11 @@ const _apiProps = {
23
23
this . userProxy = userProxy ;
24
24
return this ;
25
25
} ,
26
- _subscribeOnChange : function ( ) {
27
- this . on ( 'onChange' , ( { newState, oldState, closedTabsId, openedTabsId, isSwitched } ) => {
28
- openedTabsId . length && this . trigger ( 'onOpen' , this . userProxy , openedTabsId ) ;
29
- closedTabsId . length && this . trigger ( 'onClose' , this . userProxy , closedTabsId ) ;
30
- isSwitched && this . trigger ( 'onSelect' , this . userProxy , {
31
- currentSelectedTabId : newState . selectedTabID ,
32
- perviousSelectedTabId : oldState . selectedTabID
33
- } ) ;
34
- } ) ;
35
- return this ;
36
- } ,
37
26
_subscribeCallbacksOptions : function ( ) {
38
27
const op = this . optionsManager . options ;
39
28
Object . keys ( this . _publishers ) . map ( eventName => {
40
29
this . on ( eventName , function ( ) {
41
- op [ eventName ] . apply ( this . userProxy , arguments ) ;
30
+ op [ eventName ] . apply ( this , arguments ) ;
42
31
} ) ;
43
32
} ) ;
44
33
return this ;
@@ -127,20 +116,29 @@ Helper.setNoneEnumProps(_apiProps, {
127
116
}
128
117
return this . _initialState ;
129
118
} ,
119
+ onChange : function ( { newState, oldState, closedTabsId, openedTabsId, isSwitched } ) {
120
+ if ( isSwitched || openedTabsId . length || closedTabsId . length ) {
121
+ this . trigger ( 'onChange' , this . userProxy , {
122
+ currentData : { ...newState } ,
123
+ perviousData : { ...oldState }
124
+ } ) ;
125
+ openedTabsId . length && this . trigger ( 'onOpen' , this . userProxy , openedTabsId ) ;
126
+ closedTabsId . length && this . trigger ( 'onClose' , this . userProxy , closedTabsId ) ;
127
+ isSwitched && this . trigger ( 'onSelect' , this . userProxy , {
128
+ currentSelectedTabId : newState . selectedTabID ,
129
+ perviousSelectedTabId : oldState . selectedTabID
130
+ } ) ;
131
+ }
132
+ return this ;
133
+ } ,
130
134
eventHandlerFactory : function ( { e, id } ) {
131
135
const el = e . target , parentEl = el . parentElement , { closeClass, tabClass } = this . optionsManager . setting ;
132
136
if ( el . className . includes ( closeClass ) && parentEl && parentEl . lastChild && ( parentEl . lastChild == el )
133
137
&& parentEl . className . includes ( tabClass ) ) {
134
- // if just on of the beforeClose subscribers return false then it will prevent tab from close
135
- this . trigger ( 'beforeClose' , this . userProxy , e , id ) . includes ( false ) || this . close ( id ) ;
138
+ ( this . getOption ( 'beforeClose' ) . call ( this . userProxy , e , id ) !== false ) && this . close ( id ) ;
136
139
}
137
140
else {
138
- // if just on of the beforeSelect subscribers return false then it will prevent tab from select
139
- if ( ! this . trigger ( 'beforeSelect' , this . userProxy , e , id ) . includes ( false ) ) {
140
- this . select ( id ) . then ( result => {
141
- } ) . catch ( er => {
142
- } ) ;
143
- }
141
+ ( this . getOption ( 'beforeSelect' ) . call ( this . userProxy , e , id ) !== false ) && this . select ( id ) ;
144
142
}
145
143
}
146
144
} ) ;
0 commit comments