refactor(utils): make PERCENTAGE_ constants public, and re-use them in flash.js (#1353)

This commit is contained in:
Andrew Scheller 2017-04-26 16:05:14 +01:00 committed by Juan Cruz Viotti
parent bc01e151c4
commit 30c531417a
2 changed files with 10 additions and 11 deletions

View File

@ -19,6 +19,7 @@
const messages = require('../../../../shared/messages');
const settings = require('../../../models/settings');
const flashState = require('../../../models/flash-state');
const utils = require('../../../../shared/utils');
module.exports = function(
$state,
@ -102,14 +103,12 @@ module.exports = function(
this.getProgressButtonLabel = () => {
const currentFlashState = flashState.getFlashState();
const isChecking = currentFlashState.type === 'check';
const PERCENTAGE_MINIMUM = 0;
const PERCENTAGE_MAXIMUM = 100;
if (!flashState.isFlashing()) {
return 'Flash!';
} else if (currentFlashState.percentage === PERCENTAGE_MINIMUM && !currentFlashState.speed) {
} else if (currentFlashState.percentage === utils.PERCENTAGE_MINIMUM && !currentFlashState.speed) {
return 'Starting...';
} else if (currentFlashState.percentage === PERCENTAGE_MAXIMUM) {
} else if (currentFlashState.percentage === utils.PERCENTAGE_MAXIMUM) {
if (isChecking && settings.get('unmountOnSuccess')) {
return 'Unmounting...';
}

View File

@ -22,18 +22,18 @@ const errors = require('./errors');
/**
* @summary Minimum percentage value
* @constant
* @private
* @public
* @type {Number}
*/
const PERCENTAGE_MINIMUM = 0;
exports.PERCENTAGE_MINIMUM = 0;
/**
* @summary Maximum percentage value
* @constant
* @private
* @public
* @type {Number}
*/
const PERCENTAGE_MAXIMUM = 100;
exports.PERCENTAGE_MAXIMUM = 100;
/**
* @summary Check if a percentage is valid
@ -51,8 +51,8 @@ const PERCENTAGE_MAXIMUM = 100;
exports.isValidPercentage = (percentage) => {
return _.every([
_.isNumber(percentage),
percentage >= PERCENTAGE_MINIMUM,
percentage <= PERCENTAGE_MAXIMUM
percentage >= exports.PERCENTAGE_MINIMUM,
percentage <= exports.PERCENTAGE_MAXIMUM
]);
};
@ -76,5 +76,5 @@ exports.percentageToFloat = (percentage) => {
});
}
return percentage / PERCENTAGE_MAXIMUM;
return percentage / exports.PERCENTAGE_MAXIMUM;
};