Skip to content

Commit

Permalink
Show TouchBar slider only state length > 0
Browse files Browse the repository at this point in the history
  • Loading branch information
jhen0409 committed Mar 10, 2017
1 parent 11ba41d commit adb8834
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
7 changes: 5 additions & 2 deletions app/middlewares/reduxAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,16 @@ export default inStore => {
toWorker(action);
}
if (action.type === UPDATE_STATE || action.type === LIFTED_ACTION) {
setReduxDevToolsMethods(true, actions.liftedDispatch);
next(action);
const state = store.getState();
const instances = state.instances;
const id = getActiveInstance(instances);
const liftedState = instances.states[id];
if (!action.action || !action.action.dontUpdateTouchBarSlider) {
if (
(!action.action || !action.action.dontUpdateTouchBarSlider) &&
liftedState.currentStateIndex > 0
) {
setReduxDevToolsMethods(true, actions.liftedDispatch);
updateSliderContent(liftedState);
}
return;
Expand Down
10 changes: 5 additions & 5 deletions app/middlewares/touchBarBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ export const setReduxDevToolsMethods = (enabled, dispatch) => {
dontUpdateTouchBarSlider,
});

leftBar.slider = new TouchBarSlider({
rightBar.slider = new TouchBarSlider({
value: 0,
minValue: 0,
maxValue: 0,
change: handleSliderChange,
});
leftBar.prev = new TouchBarButton({
rightBar.prev = new TouchBarButton({
label: 'Prev',
click() {
const nextIndex = storeLiftedState.currentStateIndex - 1;
Expand All @@ -93,7 +93,7 @@ export const setReduxDevToolsMethods = (enabled, dispatch) => {
}
},
});
leftBar.next = new TouchBarButton({
rightBar.next = new TouchBarButton({
label: 'Next',
click() {
const nextIndex = storeLiftedState.currentStateIndex + 1;
Expand All @@ -109,6 +109,6 @@ export const setReduxDevToolsMethods = (enabled, dispatch) => {
export const updateSliderContent = liftedState => {
storeLiftedState = liftedState;
const { currentStateIndex, computedStates } = liftedState;
leftBar.slider.maxValue = computedStates.length - 1;
leftBar.slider.value = currentStateIndex;
rightBar.slider.maxValue = computedStates.length - 1;
rightBar.slider.value = currentStateIndex;
};

0 comments on commit adb8834

Please sign in to comment.