From fd127da3425caa0eb0f17d79c85382081645b40c Mon Sep 17 00:00:00 2001 From: Alexis Svinartchouk Date: Thu, 9 Jan 2020 17:47:26 +0100 Subject: [PATCH] Convert available-drives.js to typescript Change-type: patch --- lib/gui/app/app.js | 1 + lib/gui/app/models/available-drives.js | 71 ----------------------- lib/gui/app/models/available-drives.ts | 34 +++++++++++ lib/gui/app/models/selection-state.js | 1 + tests/gui/models/available-drives.spec.js | 1 + tests/gui/models/selection-state.spec.js | 1 + 6 files changed, 38 insertions(+), 71 deletions(-) delete mode 100644 lib/gui/app/models/available-drives.js create mode 100644 lib/gui/app/models/available-drives.ts diff --git a/lib/gui/app/app.js b/lib/gui/app/app.js index efe130cf..0db0e3a2 100644 --- a/lib/gui/app/app.js +++ b/lib/gui/app/app.js @@ -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') diff --git a/lib/gui/app/models/available-drives.js b/lib/gui/app/models/available-drives.js deleted file mode 100644 index a6f4b33f..00000000 --- a/lib/gui/app/models/available-drives.js +++ /dev/null @@ -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 -} diff --git a/lib/gui/app/models/available-drives.ts b/lib/gui/app/models/available-drives.ts new file mode 100644 index 00000000..c0822898 --- /dev/null +++ b/lib/gui/app/models/available-drives.ts @@ -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; +} diff --git a/lib/gui/app/models/selection-state.js b/lib/gui/app/models/selection-state.js index b8d0eb70..1ff311c6 100644 --- a/lib/gui/app/models/selection-state.js +++ b/lib/gui/app/models/selection-state.js @@ -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') /** diff --git a/tests/gui/models/available-drives.spec.js b/tests/gui/models/available-drives.spec.js index 7149640f..d6f9436d 100644 --- a/tests/gui/models/available-drives.spec.js +++ b/tests/gui/models/available-drives.spec.js @@ -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 diff --git a/tests/gui/models/selection-state.spec.js b/tests/gui/models/selection-state.spec.js index 9e4d1d79..bbf2195d 100644 --- a/tests/gui/models/selection-state.spec.js +++ b/tests/gui/models/selection-state.spec.js @@ -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')