@@ -14,26 +14,40 @@ const api = function (getDeps, param = { options: {} }) {
1414 userProxy : getUserProxy ( this )
1515 } ) ;
1616 this . pub_sub = pub_sub_Instance ;
17- this . _createSubscribers ( ) ;
17+ this . _alterOnChangeCallback ( ) . _subscribeCallbacksOptions ( ) . _subscribeSelectedTabsHistory ( ) ;
1818} ;
1919api . prototype = Object . create ( BaseApi . prototype ) ;
2020api . prototype . constructor = api ;
21- api . prototype . _createSubscribers = function ( ) {
22- const op = this . getOptions ( ) , api = this . userProxy , _pp = this . _panelProxy ;
23- this . pub_sub
24- . subscribe ( 'onLoad' , ( ) => { op . onLoad . call ( api ) ; } )
25- . subscribe ( 'onDestroy' , ( ) => { op . onDestroy . call ( api ) ; } )
26- . subscribe ( 'beforeSwitchTab' , ( id ) => { _pp . addRenderedPanel ( id ) ; } )
27- . subscribe ( 'onChange' , ( { closedTabsId } ) => { closedTabsId . map ( id => { _pp . removeRenderedPanel ( id ) ; } ) ; } )
28- . subscribe ( 'onChange' , ( { isSwitched, oldState } ) => { isSwitched && this . activedTabsHistory . add ( oldState . selectedTabID ) ; } )
29- . subscribe ( 'onChange' , ( { newState, oldState, closedTabsId, openedTabsId, isSwitched } ) => {
30- const currentSelectedTabId = newState . selectedTabID
31- , perviousSelectedTabId = oldState . selectedTabID ;
32- openedTabsId . length && op . onOpen . call ( api , openedTabsId ) ;
33- closedTabsId . length && op . onClose . call ( api , closedTabsId ) ;
34- isSwitched && op . onSelect . call ( api , { currentSelectedTabId, perviousSelectedTabId } ) ;
35- op . onChange . call ( api , { currentData : newState , perviousData : oldState } ) ;
21+ api . prototype . _alterOnChangeCallback = function ( ) {
22+ const op = this . getOptions ( ) ;
23+ op . onChange = op . onChange || ( ( ) => { } ) ;
24+ const oldOnchange = op . onChange ;
25+ op . onChange = function ( { newState, oldState, closedTabsId, openedTabsId, isSwitched } ) {
26+ oldOnchange . call ( this , { currentData : newState , perviousData : oldState } ) ;
27+ openedTabsId . length && this . trigger ( 'onOpen' , openedTabsId , this ) ;
28+ closedTabsId . length && this . trigger ( 'onClose' , closedTabsId , this ) ;
29+ isSwitched && this . trigger ( 'onSelect' , {
30+ currentSelectedTabId : newState . selectedTabID ,
31+ perviousSelectedTabId : oldState . selectedTabID
32+ } , this ) ;
33+ } ;
34+ return this ;
35+ } ;
36+ api . prototype . _subscribeSelectedTabsHistory = function ( ) {
37+ this . pub_sub . subscribe ( 'onChange' , ( { isSwitched, oldState } ) => {
38+ isSwitched && this . activedTabsHistory . add ( oldState . selectedTabID ) ;
39+ } ) ;
40+ return this ;
41+ } ;
42+ api . prototype . _subscribeCallbacksOptions = function ( ) {
43+ const op = this . getOptions ( ) ;
44+ Object . keys ( this . pub_sub . publishers ) . map ( publisher => {
45+ this . pub_sub . subscribe ( publisher , param => {
46+ if ( op . hasOwnProperty ( publisher ) && typeof op [ publisher ] === 'function' )
47+ op [ publisher ] . call ( this , param ) ;
3648 } ) ;
49+ } ) ;
50+ return this ;
3751} ;
3852api . prototype . getCopyPerviousData = function ( ) { return this . helper . getCopyState ( this . perviousState ) ; } ;
3953api . prototype . getOptions = function ( ) { return this . optionManager . getMutableOptions ( ) ; } ;
0 commit comments