@@ -3,7 +3,7 @@ const { throwMissingParam: missingParamEr, throwInvalidParam: invalidParamEr } =
33export const apiConstructor = function ( getDeps , param = { options : { } } ) {
44 const { optionsManager, helper, activedTabsHistory } = getDeps . call ( this , param . options ) ;
55 helper . setNoneEnumProps ( this , { optionsManager, helper, activedTabsHistory } ) ;
6- this . _setUserProxy ( ) . _subscribeSelectedTabsHistory ( ) . _subscribeCallbacksOptions ( ) . _subscribeOnChange ( ) ;
6+ this . _setUserProxy ( ) . _subscribeSelectedTabsHistory ( ) . _subscribeCallbacksOptions ( ) ; // ._subscribeOnChange();
77} ;
88const _apiProps = {
99 _setUserProxy : function ( ) {
@@ -23,22 +23,11 @@ const _apiProps = {
2323 this . userProxy = userProxy ;
2424 return this ;
2525 } ,
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- } ,
3726 _subscribeCallbacksOptions : function ( ) {
3827 const op = this . optionsManager . options ;
3928 Object . keys ( this . _publishers ) . map ( eventName => {
4029 this . on ( eventName , function ( ) {
41- op [ eventName ] . apply ( this . userProxy , arguments ) ;
30+ op [ eventName ] . apply ( this , arguments ) ;
4231 } ) ;
4332 } ) ;
4433 return this ;
@@ -127,20 +116,29 @@ Helper.setNoneEnumProps(_apiProps, {
127116 }
128117 return this . _initialState ;
129118 } ,
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+ } ,
130134 eventHandlerFactory : function ( { e, id } ) {
131135 const el = e . target , parentEl = el . parentElement , { closeClass, tabClass } = this . optionsManager . setting ;
132136 if ( el . className . includes ( closeClass ) && parentEl && parentEl . lastChild && ( parentEl . lastChild == el )
133137 && 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 ) ;
136139 }
137140 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 ) ;
144142 }
145143 }
146144} ) ;
0 commit comments