Skip to content

Commit 5d14abb

Browse files
optimize getting initial state function
1 parent 36461ab commit 5d14abb

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/utils/api/api.factory.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,15 @@ const _apiProps = {
117117
};
118118
Helper.setNoneEnumProps(_apiProps, {
119119
getInitialState: function () {
120-
const { selectedTabID, tabs, defaultPanelComponent } = this.optionsManager.options, openTabIDs = [];
121-
tabs.map(tab => {
122-
this._addTab(tab, { defaultPanelComponent });
123-
openTabIDs.push(tab.id);
124-
});
125-
return { selectedTabID, openTabIDs };
120+
if (!this._initialState) {
121+
const { selectedTabID, tabs, defaultPanelComponent } = this.optionsManager.options, openTabIDs = [];
122+
tabs.map(tab => {
123+
this._addTab(tab, { defaultPanelComponent });
124+
openTabIDs.push(tab.id);
125+
});
126+
this._initialState = { selectedTabID, openTabIDs };
127+
}
128+
return this._initialState;
126129
},
127130
eventHandlerFactory: function ({ e, id }) {
128131
const el = e.target, parentEl = el.parentElement, { closeClass, tabClass } = this.optionsManager.setting;
@@ -133,7 +136,11 @@ Helper.setNoneEnumProps(_apiProps, {
133136
}
134137
else {
135138
// if just on of the beforeSelect subscribers return false then it will prevent tab from select
136-
this.trigger('beforeSelect', this.userProxy, e, id).includes(false) || this.select(id);
139+
if (!this.trigger('beforeSelect', this.userProxy, e, id).includes(false)) {
140+
this.select(id).then(result => {
141+
}).catch(er => {
142+
});
143+
}
137144
}
138145
}
139146
});

src/utils/api/baseApi.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Helper from '../helper.js';
33
function BaseApi(helper) {
44
this._helper = helper;
55
this._state = {};
6+
this._initialState = null;
67
this._perviousState = {};
78
this._dispatch = () => { };
89
helper.setNoneEnumProps(this, {

0 commit comments

Comments
 (0)