Replace underscore by lodash

This commit is contained in:
Jerko Steiner 2019-11-13 22:16:34 -03:00
parent 9e8b353dea
commit b7f2b454ba
10 changed files with 33 additions and 57 deletions

33
package-lock.json generated
View File

@ -1933,12 +1933,6 @@
"@types/babel-types": "*"
}
},
"@types/bluebird": {
"version": "3.5.29",
"resolved": "https://registry.npmjs.org/@types/bluebird/-/bluebird-3.5.29.tgz",
"integrity": "sha512-kmVtnxTuUuhCET669irqQmPAez4KFnFVKvpleVRyfC3g+SHD1hIkFZcWLim9BVcwUBLO59o8VZE4yGCmTif8Yw==",
"dev": true
},
"@types/body-parser": {
"version": "1.17.1",
"resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.17.1.tgz",
@ -2076,6 +2070,12 @@
"integrity": "sha512-Il2DtDVRGDcqjDtE+rF8iqg1CArehSK84HZJCT7AMITlyXRBpuPhqGLDQMowraqqu1coEaimg4ZOqggt6L6L+A==",
"dev": true
},
"@types/lodash": {
"version": "4.14.147",
"resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.147.tgz",
"integrity": "sha512-+0zY1Axql6ru5T85Rh6aR6Zr0xT7c0USLqsHv01b3ID//dOrV3OvpXJGjm69+4QpxoZ0oMNEfmW1ltwXe2WVzQ==",
"dev": true
},
"@types/mime": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/@types/mime/-/mime-2.0.1.tgz",
@ -2266,12 +2266,6 @@
"@types/superagent": "*"
}
},
"@types/underscore": {
"version": "1.9.3",
"resolved": "https://registry.npmjs.org/@types/underscore/-/underscore-1.9.3.tgz",
"integrity": "sha512-SwbHKB2DPIDlvYqtK5O+0LFtZAyrUSw4c0q+HWwmH1Ve3KMQ0/5PlV3RX97+3dP7yMrnNQ8/bCWWvQpPl03Mug==",
"dev": true
},
"@types/uuid": {
"version": "3.4.6",
"resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-3.4.6.tgz",
@ -3396,11 +3390,6 @@
"inherits": "~2.0.0"
}
},
"bluebird": {
"version": "3.5.3",
"resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.3.tgz",
"integrity": "sha512-/qKPUQlaW1OyR51WeCPBvRnAlnZFUJkCSG5HzGnuIqhgyJtF+T94lFnn33eiazjRm2LAHVy2guNnaq48X9SJuw=="
},
"bn.js": {
"version": "4.11.8",
"resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.8.tgz",
@ -12654,11 +12643,6 @@
}
}
},
"seamless-immutable": {
"version": "7.1.4",
"resolved": "https://registry.npmjs.org/seamless-immutable/-/seamless-immutable-7.1.4.tgz",
"integrity": "sha512-XiUO1QP4ki4E2PHegiGAlu6r82o5A+6tRh7IkGGTVg/h+UoeX4nFBeCGPOhb4CYjvkqsfm/TUtvOMYC1xmV30A=="
},
"semver": {
"version": "5.6.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-5.6.0.tgz",
@ -14029,11 +14013,6 @@
"debug": "^2.2.0"
}
},
"underscore": {
"version": "1.9.1",
"resolved": "https://registry.npmjs.org/underscore/-/underscore-1.9.1.tgz",
"integrity": "sha512-5/4etnCkd9c8gwgowi5/om/mYO5ajCaOgdzj/oW+0eQV9WxKBDZw5+ycmKmeaTXjInS/W0BzpGLo2xR2aBwZdg=="
},
"unicode-canonical-property-names-ecmascript": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-1.0.4.tgz",

View File

@ -51,11 +51,9 @@
"author": "Jerko Steiner",
"license": "MIT",
"dependencies": {
"bluebird": "^3.3.4",
"classnames": "^2.2.5",
"config": "^3.0.0",
"express": "^4.13.3",
"prop-types": "^15.5.10",
"pug": "^2.0.0-rc.2",
"react": "^16.6.3",
"react-dom": "^16.6.3",
@ -64,11 +62,9 @@
"redux-logger": "^3.0.6",
"redux-promise-middleware": "^5.1.1",
"redux-thunk": "^2.2.0",
"seamless-immutable": "^7.1.2",
"simple-peer": "^9.1.2",
"socket.io": "^2.2.0",
"socket.io-client": "^2.2.0",
"underscore": "^1.8.3",
"uuid": "^3.3.2"
},
"devDependencies": {
@ -78,12 +74,12 @@
"@babel/polyfill": "^7.4.4",
"@babel/preset-env": "^7.5.0",
"@babel/preset-react": "^7.0.0",
"@types/bluebird": "^3.5.29",
"@types/classnames": "^2.2.9",
"@types/config": "0.0.36",
"@types/debug": "^4.1.5",
"@types/express": "^4.17.2",
"@types/jest": "^24.0.23",
"@types/lodash": "^4.14.147",
"@types/node": "^12.12.7",
"@types/react": "^16.9.11",
"@types/react-dom": "^16.9.4",
@ -97,7 +93,6 @@
"@types/socket.io": "^2.1.4",
"@types/socket.io-client": "^1.4.32",
"@types/supertest": "^2.0.8",
"@types/underscore": "^1.9.3",
"@types/uuid": "^3.4.6",
"@typescript-eslint/eslint-plugin": "^2.7.0",
"@typescript-eslint/parser": "^2.7.0",
@ -116,6 +111,7 @@
"eslint-plugin-standard": "^4.0.0",
"jest": "^24.9.0",
"jest-cli": "^24.8.0",
"lodash": "^4.17.15",
"node-sass": "^4.13.0",
"nodemon": "^1.18.8",
"react-transition-group": "^2.5.1",

View File

@ -1,6 +1,6 @@
import * as constants from '../constants'
import uniqueId from 'lodash/uniqueId'
import { Dispatch } from 'redux'
import _ from 'underscore'
import * as constants from '../constants'
import { ThunkResult } from '../store'
const TIMEOUT = 5000
@ -16,7 +16,7 @@ export type NotifyType = 'info' | 'warning' | 'error'
function notify(dispatch: Dispatch, type: NotifyType, args: string[]) {
const string = args[0] || ''
const message = format(string, Array.prototype.slice.call(args, 1))
const id = _.uniqueId('notification')
const id = uniqueId('notification')
const payload: Notification = { id, type, message }
setTimeout(() => {

View File

@ -3,7 +3,7 @@ import * as NotifyActions from '../actions/NotifyActions'
import * as StreamActions from '../actions/StreamActions'
import * as constants from '../constants'
import Peer from 'simple-peer'
import _ from 'underscore'
import forEach from 'lodash/forEach'
import _debug from 'debug'
import { play, iceServers } from '../window'
import { Dispatch, GetState } from '../store'
@ -215,7 +215,7 @@ export const sendMessage = (message: Message) =>
const { peers } = getState()
debug('Sending message type: %s to %s peers.',
message.type, Object.keys(peers).length)
_.each(peers, (peer, userId) => {
forEach(peers, (peer, userId) => {
switch (message.type) {
case 'file':
dispatch(ChatActions.addMessage({

View File

@ -1,7 +1,7 @@
import * as NotifyActions from '../actions/NotifyActions'
import * as PeerActions from '../actions/PeerActions'
import * as constants from '../constants'
import _ from 'underscore'
import keyBy from 'lodash/keyBy'
import _debug from 'debug'
import { SignalData } from 'simple-peer'
import { Dispatch, GetState } from '../store'
@ -62,8 +62,8 @@ class SocketHandler {
stream,
})(dispatch, getState))
const newUsersMap = _.indexBy(users, 'id')
_.keys(peers)
const newUsersMap = keyBy(users, 'id')
Object.keys(peers)
.filter(id => !newUsersMap[id])
.forEach(id => peers[id].destroy())
}

View File

@ -1,6 +1,6 @@
import map from 'lodash/map'
import React from 'react'
import Peer from 'simple-peer'
import _ from 'underscore'
import { Message } from '../actions/ChatActions'
import { Alert, Notification } from '../actions/NotifyActions'
import { TextMessage } from '../actions/PeerActions'
@ -99,7 +99,7 @@ export default class App extends React.PureComponent<AppProps, AppState> {
mirrored
/>
{_.map(peers, (_, userId) => (
{map(peers, (_, userId) => (
<Video
active={userId === active}
key={userId}

View File

@ -1,8 +1,8 @@
import * as NotifyActions from '../actions/NotifyActions'
import _ from 'underscore'
import { applyMiddleware, createStore, Store, bindActionCreators } from 'redux'
import { create } from '../middlewares'
import reducers from './index'
import values from 'lodash/values'
jest.useFakeTimers()
@ -76,7 +76,7 @@ describe('reducers/alerts', () => {
})
it('adds a notification', () => {
expect(_.values(store.getState().notifications)).toEqual([{
expect(values(store.getState().notifications)).toEqual([{
id: jasmine.any(String),
message: 'Hi John!',
type,

View File

@ -1,7 +1,8 @@
import * as constants from '../constants'
import _ from 'underscore'
import forEach from 'lodash/forEach'
import omit from 'lodash/omit'
import Peer from 'simple-peer'
import { PeerAction } from '../actions/PeerActions'
import * as constants from '../constants'
export type PeersState = Record<string, Peer.Instance>
@ -18,9 +19,9 @@ export default function peers(
[action.payload.userId]: action.payload.peer,
}
case constants.PEER_REMOVE:
return _.omit(state, [action.payload.userId])
return omit(state, [action.payload.userId])
case constants.PEERS_DESTROY:
_.each(state, peer => peer.destroy())
forEach(state, peer => peer.destroy())
return defaultState
default:
return state

View File

@ -1,8 +1,8 @@
import _ from 'underscore'
import { createObjectURL, revokeObjectURL } from '../window'
import _debug from 'debug'
import { AddStreamPayload, AddStreamAction, RemoveStreamAction, StreamAction } from '../actions/StreamActions'
import omit from 'lodash/omit'
import { AddStreamAction, AddStreamPayload, RemoveStreamAction, StreamAction } from '../actions/StreamActions'
import { STREAM_ADD, STREAM_REMOVE } from '../constants'
import { createObjectURL, revokeObjectURL } from '../window'
const debug = _debug('peercalls')
const defaultState = Object.freeze({})
@ -24,10 +24,10 @@ function addStream (state: StreamsState, action: AddStreamAction) {
const { userId, stream } = action.payload
return Object.freeze({
...state,
[userId]: Object.freeze({
[userId]: {
mediaStream: stream,
url: safeCreateObjectURL(stream),
}),
},
})
}
@ -37,7 +37,7 @@ function removeStream (state: StreamsState, action: RemoveStreamAction) {
if (stream && stream.url) {
revokeObjectURL(stream.url)
}
return Object.freeze(_.omit(state, [userId]))
return omit(state, [userId])
}
export default function streams (state = defaultState, action: StreamAction) {

View File

@ -1,6 +1,6 @@
'use strict'
import _debug from 'debug'
import _ from 'underscore'
import map from 'lodash/map'
import { Socket, Server } from 'socket.io'
const debug = _debug('peercalls:socket')
@ -34,7 +34,7 @@ export default function handleSocket(socket: SocketWithRoom, io: Server) {
})
function getUsers (roomName: string) {
return _.map(io.sockets.adapter.rooms[roomName].sockets, (_, id) => {
return map(io.sockets.adapter.rooms[roomName].sockets, (_, id) => {
return { id }
})
}