Skip to content

Commit b2184dc

Browse files
onChange event takes closedTabIDs and
openedTabIDs as a parameter
1 parent 627b805 commit b2184dc

File tree

2 files changed

+8
-20
lines changed

2 files changed

+8
-20
lines changed

src/useDynamicTabs/useDynamicTabs.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ function useDynamicTabs(getDeps, options = {}) {
2828
}, []);
2929
useLayoutEffect(() => {
3030
const oldState = api.getCopyPerviousData(),
31-
[openedTabsId, closedTabsId] = api.helper.getArraysDiff(state.openTabIDs, oldState.openTabIDs),
31+
[openedTabIDs, closedTabIDs] = api.helper.getArraysDiff(state.openTabIDs, oldState.openTabIDs),
3232
isSwitched = oldState.selectedTabID !== state.selectedTabID;
33-
api.onChange({newState: state, oldState, closedTabsId, openedTabsId, isSwitched});
33+
api.onChange({newState: state, oldState, closedTabIDs, openedTabIDs, isSwitched});
3434
}, [state]);
3535
useLayoutEffect(() => {
3636
api.trigger('_onFlushEffects', api.userProxy, {currentData: api.getCopyData(), instance: api.userProxy});

src/utils/api/api.factory.js

+6-18
Original file line numberDiff line numberDiff line change
@@ -163,28 +163,16 @@ const _apiProps = {
163163
},
164164
};
165165
Helper.setNoneEnumProps(_apiProps, {
166-
// getInitialState: function () {
167-
// if (!this._initialState) {
168-
// const { selectedTabID, tabs, defaultPanelComponent } = this.optionsManager.options, openTabIDs = [];
169-
// tabs.map(tab => {
170-
// const newTab = this._addTab(tab, { defaultPanelComponent });
171-
// openTabIDs.push(newTab.id);
172-
// });
173-
// this._initialState = {
174-
// selectedTabID: selectedTabID + '', //make sure it is type of string
175-
// openTabIDs
176-
// };
177-
// }
178-
// return this._initialState;
179-
// },
180-
onChange: function ({newState, oldState, closedTabsId, openedTabsId, isSwitched}) {
181-
if (isSwitched || openedTabsId.length || closedTabsId.length) {
166+
onChange: function ({newState, oldState, closedTabIDs, openedTabIDs, isSwitched}) {
167+
if (isSwitched || openedTabIDs.length || closedTabIDs.length) {
182168
this.trigger('onChange', this.userProxy, {
183169
currentData: {...newState},
184170
perviousData: {...oldState},
171+
closedTabIDs,
172+
openedTabIDs,
185173
});
186-
openedTabsId.length && this.trigger('onOpen', this.userProxy, openedTabsId);
187-
closedTabsId.length && this.trigger('onClose', this.userProxy, closedTabsId);
174+
openedTabIDs.length && this.trigger('onOpen', this.userProxy, openedTabIDs);
175+
closedTabIDs.length && this.trigger('onClose', this.userProxy, closedTabIDs);
188176
isSwitched &&
189177
this.trigger('onSelect', this.userProxy, {
190178
currentSelectedTabId: newState.selectedTabID,

0 commit comments

Comments
 (0)