mirror of
https://github.com/balena-io/etcher.git
synced 2025-07-27 21:26:38 +00:00
refactor: flatten "flash" data structure property (#521)
Currently, the "flash" property of the application state containing both the actual flashing state, and the flashing flag. To simplify things, the following changes have been introduced: - Move `flash.flashing` to `isFlashing`. - Move `flash.state` to `flashState`. - Rename `SET_FLASHING` to `SET_FLASHING_FLAG`. - Extract `UNSET_FLASHING_FLAG` from `SET_FLASHING_FLAG`. Signed-off-by: Juan Cruz Viotti <jviottidc@gmail.com>
This commit is contained in:
parent
78da500816
commit
4d89b1b1f7
@ -29,13 +29,11 @@ const redux = require('redux');
|
|||||||
const DEFAULT_STATE = Immutable.fromJS({
|
const DEFAULT_STATE = Immutable.fromJS({
|
||||||
availableDrives: [],
|
availableDrives: [],
|
||||||
selection: {},
|
selection: {},
|
||||||
flash: {
|
isFlashing: false,
|
||||||
flashing: false,
|
flashState: {
|
||||||
state: {
|
|
||||||
progress: 0,
|
progress: 0,
|
||||||
speed: 0
|
speed: 0
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -47,7 +45,8 @@ const ACTIONS = _.fromPairs(_.map([
|
|||||||
'SET_AVAILABLE_DRIVES',
|
'SET_AVAILABLE_DRIVES',
|
||||||
'SET_FLASH_STATE',
|
'SET_FLASH_STATE',
|
||||||
'RESET_FLASH_STATE',
|
'RESET_FLASH_STATE',
|
||||||
'SET_FLASHING',
|
'SET_FLASHING_FLAG',
|
||||||
|
'UNSET_FLASHING_FLAG',
|
||||||
'SELECT_DRIVE',
|
'SELECT_DRIVE',
|
||||||
'SELECT_IMAGE',
|
'SELECT_IMAGE',
|
||||||
'REMOVE_DRIVE',
|
'REMOVE_DRIVE',
|
||||||
@ -104,30 +103,27 @@ const storeReducer = function(state, action) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case ACTIONS.SET_FLASH_STATE: {
|
case ACTIONS.SET_FLASH_STATE: {
|
||||||
if (!state.getIn([ 'flash', 'flashing' ])) {
|
if (!state.get('isFlashing')) {
|
||||||
throw new Error('Can\'t set the flashing state when not flashing');
|
throw new Error('Can\'t set the flashing state when not flashing');
|
||||||
}
|
}
|
||||||
|
|
||||||
return state.setIn([ 'flash', 'state' ], Immutable.fromJS(action.data));
|
return state.set('flashState', Immutable.fromJS(action.data));
|
||||||
}
|
}
|
||||||
|
|
||||||
case ACTIONS.RESET_FLASH_STATE: {
|
case ACTIONS.RESET_FLASH_STATE: {
|
||||||
return state.setIn([ 'flash', 'state' ], DEFAULT_STATE.getIn([ 'flash', 'state' ]));
|
return state.set('flashState', DEFAULT_STATE.get('flashState'));
|
||||||
}
|
}
|
||||||
|
|
||||||
case ACTIONS.SET_FLASHING: {
|
case ACTIONS.SET_FLASHING_FLAG: {
|
||||||
const value = Boolean(action.data);
|
return state.set('isFlashing', true);
|
||||||
const newState = state.setIn([ 'flash', 'flashing' ], value);
|
}
|
||||||
|
|
||||||
if (!value) {
|
case ACTIONS.UNSET_FLASHING_FLAG: {
|
||||||
return storeReducer(newState, {
|
return storeReducer(state.set('isFlashing', false), {
|
||||||
type: ACTIONS.RESET_FLASH_STATE
|
type: ACTIONS.RESET_FLASH_STATE
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return newState;
|
|
||||||
}
|
|
||||||
|
|
||||||
case ACTIONS.SELECT_DRIVE: {
|
case ACTIONS.SELECT_DRIVE: {
|
||||||
if (!action.data.device) {
|
if (!action.data.device) {
|
||||||
throw new Error('Missing drive device');
|
throw new Error('Missing drive device');
|
||||||
|
@ -61,7 +61,7 @@ imageWriter.service('ImageWriterService', function($q, $timeout, SettingsModel,
|
|||||||
|
|
||||||
// Safely bring the state to the world of Angular
|
// Safely bring the state to the world of Angular
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
self.state = Store.getState().toJS().flash.state;
|
self.state = Store.getState().toJS().flashState;
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
@ -79,7 +79,7 @@ imageWriter.service('ImageWriterService', function($q, $timeout, SettingsModel,
|
|||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
this.isFlashing = function() {
|
this.isFlashing = function() {
|
||||||
return Store.getState().toJS().flash.flashing;
|
return Store.getState().toJS().isFlashing;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -96,10 +96,15 @@ imageWriter.service('ImageWriterService', function($q, $timeout, SettingsModel,
|
|||||||
* ImageWriterService.setFlashing(true);
|
* ImageWriterService.setFlashing(true);
|
||||||
*/
|
*/
|
||||||
this.setFlashing = function(status) {
|
this.setFlashing = function(status) {
|
||||||
|
if (Boolean(status)) {
|
||||||
Store.dispatch({
|
Store.dispatch({
|
||||||
type: Store.Actions.SET_FLASHING,
|
type: Store.Actions.SET_FLASHING_FLAG
|
||||||
data: status
|
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
Store.dispatch({
|
||||||
|
type: Store.Actions.UNSET_FLASHING_FLAG
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user