Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Commit

Permalink
refactor: replace various lodash methods with native alternatives (#1759
Browse files Browse the repository at this point in the history
)
  • Loading branch information
brenopolanski committed Mar 3, 2020
1 parent a04dcad commit 6554499
Show file tree
Hide file tree
Showing 46 changed files with 135 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
</template>

<script>
import chunk from 'lodash/chunk'
import { chunk } from 'lodash'
import { MenuOptions, MenuOptionsItem } from '@/components/Menu'
export default {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ import { ModalConfirmation } from '@/components/Modal'
import { MenuNavigationItem, MenuOptions, MenuOptionsItem, MenuDropdown } from '@/components/Menu'
import { ButtonSwitch } from '@/components/Button'
import { PluginManageBlacklistModal } from '@/components/PluginManager/PluginManagerModals'
import { isEmpty, isString } from 'lodash'
import { isEmpty } from 'lodash'
import os from 'os'
export default {
Expand Down Expand Up @@ -333,7 +333,7 @@ export default {
},
setTheme (theme) {
this.sessionTheme = isString(theme) ? theme : (theme ? 'dark' : 'light')
this.sessionTheme = typeof theme === 'string' ? theme : (theme ? 'dark' : 'light')
},
setBackgroundUpdateLedger (update) {
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/components/Input/InputAddress.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ import Cycled from 'cycled'
import InputField from './InputField'
import WalletService from '@/services/wallet'
import truncate from '@/filters/truncate'
import { includes, isEmpty, map, orderBy, unionBy } from 'lodash'
import { includes, isEmpty, orderBy, unionBy } from 'lodash'
export default {
name: 'InputAddress',
Expand Down Expand Up @@ -193,7 +193,7 @@ export default {
const source = unionBy(wallets, contacts, 'address').filter(wallet => wallet && !!wallet.address)
const addresses = map(source, (wallet) => {
const addresses = source.map(wallet => {
const address = {
name: null,
address: wallet.address
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/components/Input/InputCurrency.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
</template>

<script>
import { includes, isString } from 'lodash'
import { includes } from 'lodash'
import { required } from 'vuelidate/lib/validators'
import { MARKET } from '@config'
import InputField from './InputField'
Expand Down Expand Up @@ -255,7 +255,7 @@ export default {
if (!bigNum.isNaN()) {
return bigNum.isPositive() && bigNum.isFinite()
} else {
return !!(isString(amount) && amount.match(/^\s*[0-9.,]+([,. _]+[0-9]+)*\s*$/))
return !!(typeof amount === 'string' && amount.match(/^\s*[0-9.,]+([,. _]+[0-9]+)*\s*$/))
}
},
/**
Expand Down
7 changes: 3 additions & 4 deletions src/renderer/components/Menu/MenuStep/MenuStep.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
</template>

<script>
import { map, first, last } from 'lodash'
import { CollapseAccordion } from '@/components/Collapse'
export default {
Expand Down Expand Up @@ -55,15 +54,15 @@ export default {
methods: {
collectItems () {
const steps = this.collections_filterChildren('MenuStepItem', this.$refs.accordion) || []
const collapses = map(steps, step => step.$refs.collapse)
const collapses = steps.map(step => step.$refs.collapse)
// The first and last items has a different style and text on the default footer
const firstStep = first(steps)
const firstStep = steps[0]
if (firstStep) {
firstStep.isFirstItem = true
}
const lastStep = last(steps)
const lastStep = steps[steps.length - 1]
if (lastStep) {
lastStep.isLastItem = true
}
Expand Down
4 changes: 3 additions & 1 deletion src/renderer/components/Modal/ModalExportWallets.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
</template>

<script>
import { isNull, omitBy, uniqBy } from 'lodash'
import { omitBy, uniqBy } from 'lodash'
import ModalWindow from '@/components/Modal/ModalWindow'
import { ButtonGeneric, ButtonSwitch } from '@/components/Button'
import { ListDivided, ListDividedItem } from '@/components/ListDivided'
Expand Down Expand Up @@ -204,6 +204,8 @@ export default {
},
transformWallets () {
const isNull = val => val === null
return this.wallets.map(wallet => {
return omitBy({
name: this.getName(wallet.name),
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/components/Passphrase/PassphraseVerification.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
</template>

<script>
import { isEqual, isString, shuffle, uniq } from 'lodash'
import { isEqual, shuffle, uniq } from 'lodash'
import { InputText } from '@/components/Input'
export default {
Expand Down Expand Up @@ -158,7 +158,7 @@ export default {
* @param {String} word
*/
isAccepted (position, word) {
return isString(word) && word !== '' && isEqual(this.acceptedWords[position], word)
return typeof word === 'string' && word !== '' && isEqual(this.acceptedWords[position], word)
},
resetData (data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<script>
import SvgIcon from '@/components/SvgIcon'
import debounce from 'lodash/debounce'
import { debounce } from 'lodash'
export default {
name: 'PluginManagerSearchBar',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
</template>

<script>
import concat from 'lodash/concat'
import { concat } from 'lodash'
import { PLUGINS } from '@config'
import { PluginManagerButtonMenu } from '@/components/PluginManager/PluginManagerButtons'
Expand Down
4 changes: 1 addition & 3 deletions src/renderer/components/PluginManager/PluginManagerTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,7 @@ export default {
]
if (this.activeCategory !== 'all') {
const index = columns.findIndex(el => {
return el.field === 'categories'
})
const index = columns.findIndex(el => el.field === 'categories')
columns.splice(index, 1)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import TransactionFormVote from './TransactionFormVote'
import TransactionFormSecondSignature from './TransactionFormSecondSignature'
import TransactionFormBusiness from './TransactionFormBusiness'
import TransactionFormBridgechain from './TransactionFormBridgechain'
import { find } from 'lodash'
export default {
name: 'TransactionForm',
Expand Down Expand Up @@ -59,7 +58,7 @@ export default {
// TODO: Fetch fees remotely
mounted () {
const component = find(this.$options.components, component => {
const component = Object.values(this.$options.components).find(component => {
const group = component.transactionGroup || TRANSACTION_GROUPS.STANDARD
if (group !== this.group) {
return false
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/components/Transaction/TransactionModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
</template>

<script>
import { camelCase, includes, findKey, upperFirst } from 'lodash'
import { camelCase, includes, findKey } from 'lodash'
import { upperFirst } from '@/utils'
import { TRANSACTION_TYPES } from '@config'
import MultiSignature from '@/services/client-multisig'
import { ModalLoader, ModalWindow } from '@/components/Modal'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
</template>

<script>
import isEqual from 'lodash/isEqual'
import { isEqual } from 'lodash'
import { ButtonClose } from '@/components/Button'
import TableWrapper from '@/components/utils/TableWrapper'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@

<script>
import electron from 'electron'
import at from 'lodash/at'
import { at } from 'lodash'
/* eslint-disable vue/no-unused-components */
import { ButtonGeneric } from '@/components/Button'
import { TransactionModal } from '@/components/Transaction'
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/components/Wallet/WalletSelection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</template>

<script>
import { map, orderBy } from 'lodash'
import { orderBy } from 'lodash'
import { InputSelect } from '@/components/Input'
import truncate from '@/filters/truncate'
Expand Down Expand Up @@ -151,7 +151,7 @@ export default {
},
walletList () {
const addresses = map(this.wallets, (wallet) => {
const addresses = this.wallets.map(wallet => {
const address = {
name: null,
address: wallet.address
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
</template>

<script>
import { filter, uniqBy } from 'lodash'
import { uniqBy } from 'lodash'
import { sortByProps } from '@/components/utils/Sorting'
import Loader from '@/components/utils/Loader'
import { MenuNavigation, MenuNavigationItem } from '@/components/Menu'
Expand Down Expand Up @@ -402,13 +402,13 @@ export default {
let filtered = wallets
if (this.filters.hideLedger) {
filtered = filter(filtered, wallet => !wallet.isLedger)
filtered = filtered.filter(wallet => !wallet.isLedger)
}
if (this.filters.hideEmpty) {
filtered = filter(filtered, wallet => wallet.balance > 0)
filtered = filtered.filter(wallet => wallet.balance > 0)
}
if (this.searchQuery) {
filtered = filter(filtered, ({ address, balance, name }) => {
filtered = filtered.filter(({ address, balance, name }) => {
let match = [
address,
balance.toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@

<script>
import { ButtonClipboard, ButtonModal } from '@/components/Button'
import { WalletSignModal, WalletVerifyModal } from '../'
import { WalletSignModal, WalletVerifyModal } from '@/components/Wallet'
import SvgIcon from '@/components/SvgIcon'
import { clone } from 'lodash'
Expand Down
4 changes: 1 addition & 3 deletions src/renderer/components/Wallet/WalletTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,7 @@ export default {
]
if (!this.showVotedDelegates) {
const index = columns.findIndex(el => {
return el.field === 'delegate'
})
const index = columns.findIndex(el => el.field === 'delegate')
columns.splice(index, 1)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import at from 'lodash/at'
import isEqual from 'lodash/isEqual'
import { at, isEqual } from 'lodash'
import mixin from './mixin'
import mergeTableTransactions from '@/components/utils/merge-table-transactions'
import { TransactionTable } from '@/components/Transaction'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import at from 'lodash/at'
import isEqual from 'lodash/isEqual'
import { at, isEqual } from 'lodash'
import mixin from './mixin'
import { TransactionTableMultiSignature } from '@/components/Transaction'
import MultiSignature from '@/services/client-multisig'
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/mixins/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import merge from 'lodash/merge'
import { merge } from 'lodash'

const mixins = [
require('./assets').default,
Expand Down
9 changes: 5 additions & 4 deletions src/renderer/models/base.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { transform, isFunction, isObject, isUndefined, isNil } from 'lodash'
import { transform } from 'lodash'
import { validate as jsonValidate } from 'jsonschema'
import { isNil } from '@/utils'

export default class BaseModel {
constructor (schema) {
this.schema = schema
}

deserialize (input) {
if (!isObject(input)) {
if (typeof input !== 'object') {
throw new Error(`Invalid model input type: \`${input}\``)
}

Expand All @@ -24,9 +25,9 @@ export default class BaseModel {
return transform(this.schema.properties, (result, item, key) => {
let value

if (item.format && isFunction(item.format)) {
if (item.format && typeof item.format === 'function') {
value = item.format(input)
} else if (!isUndefined(input[key])) {
} else if (input[key] !== undefined) {
value = input[key]
}

Expand Down
3 changes: 1 addition & 2 deletions src/renderer/models/profile.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { isBoolean } from 'lodash'
import BaseModel from './base'

export default new BaseModel({
Expand Down Expand Up @@ -91,7 +90,7 @@ export default new BaseModel({
},
showPluginConfirmation: {
type: 'boolean',
format: data => isBoolean(data.showPluginConfirmation) ? data.showPluginConfirmation : true
format: data => typeof data.showPluginConfirmation === 'boolean' ? data.showPluginConfirmation : true
},
transactionTableRowCount: {
type: 'integer',
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/pages/Profile/ProfileAll.vue
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
</template>

<script>
import { map, mapValues, sortBy, uniqBy } from 'lodash'
import { mapValues, sortBy, uniqBy } from 'lodash'
import { ProfileAvatar, ProfileRemovalConfirmation } from '@/components/Profile'
export default {
Expand Down Expand Up @@ -147,7 +147,7 @@ export default {
})
}
const sorted = sortBy(balances, ['amount', 'formatted'])
return map(sorted, 'formatted').reverse()
return sorted.map(sort => sort.formatted).reverse()
}
},
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/services/plugin-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import dayjs from 'dayjs'
import * as fs from 'fs'
import * as fsExtra from 'fs-extra'
import got from 'got'
import { partition, upperFirst } from 'lodash'
import { partition } from 'lodash'
import { upperFirst } from '@/utils'
import * as path from 'path'
import semver from 'semver'
import trash from 'trash'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PLUGINS } from '@config'
import chunk from 'lodash/chunk'
import { chunk } from 'lodash'
import got from 'got'
import packageJson from 'package-json'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import isElement from 'lodash/isElement'
import { isElement } from 'lodash'

export function getSafeContext (vueContext, component) {
const context = vueContext._data || {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import cloneDeep from 'lodash/cloneDeep'
import { cloneDeep } from 'lodash'

export function create (walletApi, app) {
return () => {
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/services/plugin-manager/setup/themes-setup.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'path'
import fs from 'fs'
import { normalizeJson } from '../utils/normalize-json'
import { isEmpty, isString, isObject, isBoolean } from 'lodash'
import { isEmpty } from 'lodash'

export function create (plugin, pluginObject, sandbox, profileId) {
return async () => {
Expand All @@ -10,12 +10,12 @@ export function create (plugin, pluginObject, sandbox, profileId) {
}

const pluginThemes = normalizeJson(pluginObject.getThemes())
if (pluginThemes && isObject(pluginThemes)) {
if (pluginThemes && typeof pluginThemes === 'object') {
// Validate the configuration of each theme and ensure that their CSS exist
const themes = Object.keys(pluginThemes).reduce((valid, themeName) => {
const config = pluginThemes[themeName]

if (isBoolean(config.darkMode) && isString(config.cssPath)) {
if (typeof config.darkMode === 'boolean' && typeof config.cssPath === 'string') {
const cssPath = path.join(plugin.fullPath, 'src', config.cssPath)
if (!fs.existsSync(cssPath)) {
throw new Error(`No file found on \`${config.cssPath}\` for theme "${themeName}"`)
Expand Down
Loading

0 comments on commit 6554499

Please sign in to comment.