Convert available-drives.js to typescript

Change-type: patch
This commit is contained in:
Alexis Svinartchouk 2020-01-09 17:47:26 +01:00 committed by Lorenzo Alberto Maria Ambrosi
parent a8728336ca
commit fd127da342
6 changed files with 38 additions and 71 deletions

View File

@ -43,6 +43,7 @@ const settings = require('./models/settings')
const windowProgress = require('./os/window-progress')
// eslint-disable-next-line node/no-missing-require
const analytics = require('./modules/analytics')
// eslint-disable-next-line node/no-missing-require
const availableDrives = require('./models/available-drives')
// eslint-disable-next-line node/no-missing-require
const { scanner: driveScanner } = require('./modules/drive-scanner')

View File

@ -1,71 +0,0 @@
/*
* Copyright 2016 balena.io
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict'
const _ = require('lodash')
// eslint-disable-next-line node/no-missing-require
const { Actions, store } = require('./store')
/**
* @summary Check if there are available drives
* @function
* @public
*
* @returns {Boolean} whether there are available drives
*
* @example
* if (availableDrives.hasAvailableDrives()) {
* console.log('There are available drives!');
* }
*/
exports.hasAvailableDrives = () => {
return !_.isEmpty(exports.getDrives())
}
/**
* @summary Set a list of drives
* @function
* @private
*
* @param {Object[]} drives - drives
*
* @throws Will throw if no drives
* @throws Will throw if drives is not an array of objects
*
* @example
* availableDrives.setDrives([ ... ]);
*/
exports.setDrives = (drives) => {
store.dispatch({
type: Actions.SET_AVAILABLE_DRIVES,
data: drives
})
}
/**
* @summary Get detected drives
* @function
* @private
*
* @returns {Object[]} drives
*
* @example
* const drives = availableDrives.getDrives();
*/
exports.getDrives = () => {
return store.getState().toJS().availableDrives
}

View File

@ -0,0 +1,34 @@
/*
* Copyright 2016 balena.io
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as _ from 'lodash';
import { Actions, store } from './store';
export function hasAvailableDrives() {
return !_.isEmpty(getDrives());
}
export function setDrives(drives: any[]) {
store.dispatch({
type: Actions.SET_AVAILABLE_DRIVES,
data: drives,
});
}
export function getDrives() {
return store.getState().toJS().availableDrives;
}

View File

@ -19,6 +19,7 @@
const _ = require('lodash')
// eslint-disable-next-line node/no-missing-require
const { Actions, store } = require('./store')
// eslint-disable-next-line node/no-missing-require
const availableDrives = require('./available-drives')
/**

View File

@ -18,6 +18,7 @@
const m = require('mochainon')
const path = require('path')
// eslint-disable-next-line node/no-missing-require
const availableDrives = require('../../../lib/gui/app/models/available-drives')
const selectionState = require('../../../lib/gui/app/models/selection-state')
// eslint-disable-next-line node/no-missing-require

View File

@ -19,6 +19,7 @@
const m = require('mochainon')
const _ = require('lodash')
const path = require('path')
// eslint-disable-next-line node/no-missing-require
const availableDrives = require('../../../lib/gui/app/models/available-drives')
const selectionState = require('../../../lib/gui/app/models/selection-state')