react-dyn-tabs
Version:
React dynamic tabs with full API
72 lines • 1.94 kB
JavaScript
import actions from '../stateManagement/actions';
import Helper from '../helper.js';
export default Helper.module(function (_ref) {
var helper = _ref.helper,
initialState = _ref.initialState;
this._helper = helper;
this._dispatch = null;
this._setFlushState = null;
this._isReady = false;
helper.setNoneEnumProps(this, {
state: this._helper.getCopyState(initialState),
// it will be updated after each render
forceUpdateState: {},
previousState: this._helper.getCopyState(initialState),
// it is a previous value of this.state
stateRef: {} // have a same reference with state . It will be updated in each execution of useDynamicTabs.js
});
}, {
_select: function _select(tabId) {
this._dispatch({
type: actions.active,
tabId: tabId
});
this.__flushEffects();
},
_close: function _close(tabId) {
this._dispatch({
type: actions.close,
tabId: tabId
});
this.__flushEffects();
},
_open: function _open(tabId) {
this._dispatch({
type: actions.open,
tabId: tabId
});
this.__flushEffects();
},
_refresh: function _refresh() {
this.forceUpdateState = {};
this._dispatch({
type: actions.refresh
});
this.__flushEffects();
},
_sort: function _sort(tabId) {
this._dispatch({
type: actions.sort,
tabId: tabId
});
this.__flushEffects();
},
__flushEffects: function __flushEffects() {
this._setFlushState({});
}
}, {
updateStateRef: function updateStateRef(state, dispatch) {
this.stateRef = state;
this._dispatch = dispatch;
return this;
},
updateState: function updateState(state) {
this.previousState = this._helper.getCopyState(this.state);
this.state = this._helper.getCopyState(state);
return this;
},
updateFlushState: function updateFlushState(setFlushState) {
this._setFlushState = setFlushState;
return this;
}
});