Browse Source

perf(bundle-size): remove lodash dependency

Shaves 34.57k of final renderer.prod.js bundle size.
renovate/lint-staged-8.x
Tom Kirkpatrick 7 years ago
parent
commit
ba34367750
No known key found for this signature in database GPG Key ID: 72203A8EC5967EA8
  1. 3
      app/components/Contacts/ContactModal.js
  2. 5
      app/components/Contacts/Network.js
  3. 3
      app/components/Form/Pay.js
  4. 3
      app/lnd/methods/channelController.js
  5. 3
      app/reducers/channels.js
  6. 11
      app/reducers/contactsform.js
  7. 8
      app/reducers/payform.js
  8. 3
      app/routes/activity/components/components/Payment/Payment.js
  9. 1
      package.json

3
app/components/Contacts/ContactModal.js

@ -1,6 +1,5 @@
import React from 'react' import React from 'react'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import find from 'lodash/find'
import ReactModal from 'react-modal' import ReactModal from 'react-modal'
import FaCircle from 'react-icons/lib/fa/circle' import FaCircle from 'react-icons/lib/fa/circle'
import MdClose from 'react-icons/lib/md/close' import MdClose from 'react-icons/lib/md/close'
@ -47,7 +46,7 @@ const ContactModal = ({
} }
// the remote node for the channel // the remote node for the channel
const node = find(channelNodes, { pub_key: channel.remote_pubkey }) const node = channelNodes.find(node => node.pub_key === channel.remote_pubkey)
return ( return (
<ReactModal <ReactModal

5
app/components/Contacts/Network.js

@ -1,6 +1,5 @@
import React, { Component } from 'react' import React, { Component } from 'react'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import find from 'lodash/find'
import Isvg from 'react-inlinesvg' import Isvg from 'react-inlinesvg'
import FaExternalLink from 'react-icons/lib/fa/external-link' import FaExternalLink from 'react-icons/lib/fa/external-link'
import FaCircle from 'react-icons/lib/fa/circle' import FaCircle from 'react-icons/lib/fa/circle'
@ -108,7 +107,7 @@ class Network extends Component {
} }
const displayNodeName = displayedChannel => { const displayNodeName = displayedChannel => {
const node = find(nodes, n => displayedChannel.remote_pubkey === n.pub_key) const node = nodes.find(n => displayedChannel.remote_pubkey === n.pub_key)
if (node && node.alias.length) { if (node && node.alias.length) {
return node.alias return node.alias
@ -213,7 +212,7 @@ class Network extends Component {
{loadingChannelPubkeys.length && {loadingChannelPubkeys.length &&
loadingChannelPubkeys.map(loadingPubkey => { loadingChannelPubkeys.map(loadingPubkey => {
// TODO(jimmymow): refactor this out. same logic is in displayNodeName above // TODO(jimmymow): refactor this out. same logic is in displayNodeName above
const node = find(nodes, n => loadingPubkey === n.pub_key) const node = nodes.find(n => loadingPubkey === n.pub_key)
const nodeDisplay = () => { const nodeDisplay = () => {
if (node && node.alias.length) { if (node && node.alias.length) {
return node.alias return node.alias

3
app/components/Form/Pay.js

@ -1,6 +1,5 @@
import React, { Component } from 'react' import React, { Component } from 'react'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import find from 'lodash/find'
import Isvg from 'react-inlinesvg' import Isvg from 'react-inlinesvg'
import paperPlane from 'icons/paper_plane.svg' import paperPlane from 'icons/paper_plane.svg'
@ -59,7 +58,7 @@ class Pay extends Component {
} = this.props } = this.props
const displayNodeName = pubkey => { const displayNodeName = pubkey => {
const node = find(nodes, n => n.pub_key === pubkey) const node = nodes.find(n => n.pub_key === pubkey)
if (node && node.alias.length) { if (node && node.alias.length) {
return node.alias return node.alias

3
app/lnd/methods/channelController.js

@ -1,10 +1,9 @@
import find from 'lodash/find'
import { listPeers, connectPeer } from './peersController' import { listPeers, connectPeer } from './peersController'
import pushopenchannel from '../push/openchannel' import pushopenchannel from '../push/openchannel'
function ensurePeerConnected(lnd, pubkey, host) { function ensurePeerConnected(lnd, pubkey, host) {
return listPeers(lnd).then(({ peers }) => { return listPeers(lnd).then(({ peers }) => {
const peer = find(peers, { pub_key: pubkey }) const peer = peers.find(candidatePeer => candidatePeer.pub_key === pubkey)
if (peer) { if (peer) {
return peer return peer
} }

3
app/reducers/channels.js

@ -1,6 +1,5 @@
import { createSelector } from 'reselect' import { createSelector } from 'reselect'
import { ipcRenderer } from 'electron' import { ipcRenderer } from 'electron'
import filter from 'lodash/filter'
import { btc } from 'utils' import { btc } from 'utils'
import { showNotification } from 'notifications' import { showNotification } from 'notifications'
import { requestSuggestedNodes } from '../api' import { requestSuggestedNodes } from '../api'
@ -483,7 +482,7 @@ channelsSelectors.channelNodes = createSelector(
(channels, nodes) => { (channels, nodes) => {
const chanPubkeys = channels.map(channel => channel.remote_pubkey) const chanPubkeys = channels.map(channel => channel.remote_pubkey)
return filter(nodes, node => chanPubkeys.includes(node.pub_key)) return nodes.filter(node => chanPubkeys.includes(node.pub_key))
} }
) )

11
app/reducers/contactsform.js

@ -1,6 +1,4 @@
import { createSelector } from 'reselect' import { createSelector } from 'reselect'
import filter from 'lodash/filter'
import isEmpty from 'lodash/isEmpty'
import { tickerSelectors } from './ticker' import { tickerSelectors } from './ticker'
import { btc } from '../utils' import { btc } from '../utils'
@ -234,10 +232,9 @@ contactFormSelectors.filteredNetworkNodes = createSelector(
const query = searchQuery.includes('@') ? searchQuery.split('@')[0] : searchQuery const query = searchQuery.includes('@') ? searchQuery.split('@')[0] : searchQuery
// list of the nodes // list of the nodes
const list = filter( const list = nodes
nodes, .filter(node => node.alias.includes(query) || node.pub_key.includes(query))
node => node.alias.includes(query) || node.pub_key.includes(query) .sort(contactableFirst)
).sort(contactableFirst)
// if we don't limit the nodes returned then we take a huge performance hit // if we don't limit the nodes returned then we take a huge performance hit
// rendering thousands of nodes potentially, so we just render 20 for the time being // rendering thousands of nodes potentially, so we just render 20 for the time being
@ -270,7 +267,7 @@ contactFormSelectors.manualFormIsValid = createSelector(manualSearchQuerySelecto
} }
return { return {
errors, errors,
isValid: isEmpty(errors) isValid: Object.keys(errors).length === 0
} }
}) })

8
app/reducers/payform.js

@ -1,8 +1,6 @@
import { createSelector } from 'reselect' import { createSelector } from 'reselect'
import bitcoin from 'bitcoinjs-lib' import bitcoin from 'bitcoinjs-lib'
import isEmpty from 'lodash/isEmpty'
import { setFormType } from './form' import { setFormType } from './form'
import { tickerSelectors } from './ticker' import { tickerSelectors } from './ticker'
import { infoSelectors } from './info' import { infoSelectors } from './info'
@ -267,9 +265,9 @@ payFormSelectors.payFormIsValid = createSelector(
return { return {
errors, errors,
amountIsValid: isEmpty(errors.amount), amountIsValid: !errors.amount,
payInputIsValid: isEmpty(errors.payInput), payInputIsValid: !errors.payInput,
isValid: isEmpty(errors) isValid: Object.keys(errors).length === 0
} }
} }
) )

3
app/routes/activity/components/components/Payment/Payment.js

@ -1,6 +1,5 @@
import React from 'react' import React from 'react'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import find from 'lodash/find'
import Moment from 'react-moment' import Moment from 'react-moment'
import { btc } from 'utils' import { btc } from 'utils'
@ -9,7 +8,7 @@ import styles from '../Activity.scss'
const Payment = ({ payment, ticker, currentTicker, showActivityModal, nodes, currencyName }) => { const Payment = ({ payment, ticker, currentTicker, showActivityModal, nodes, currencyName }) => {
const displayNodeName = pubkey => { const displayNodeName = pubkey => {
const node = find(nodes, n => pubkey === n.pub_key) const node = nodes.find(n => pubkey === n.pub_key)
if (node && node.alias.length) { if (node && node.alias.length) {
return node.alias return node.alias

1
package.json

@ -229,7 +229,6 @@
"electron-store": "^2.0.0", "electron-store": "^2.0.0",
"font-awesome": "^4.7.0", "font-awesome": "^4.7.0",
"history": "^4.6.3", "history": "^4.6.3",
"lodash": "^4.17.10",
"moment": "^2.22.2", "moment": "^2.22.2",
"prop-types": "^15.5.10", "prop-types": "^15.5.10",
"qrcode.react": "0.8.0", "qrcode.react": "0.8.0",

Loading…
Cancel
Save