Skip to content
This repository has been archived by the owner on May 5, 2020. It is now read-only.

Commit

Permalink
removed babel-plugin-transform-regenerator & replaced Object.assign w…
Browse files Browse the repository at this point in the history
…ith object rest spread operator
  • Loading branch information
JoJordens committed Mar 6, 2018
1 parent ea087d6 commit 06b7679
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"plugins": [ "transform-es2015-modules-commonjs", "transform-regenerator" ],
"plugins": [ "transform-es2015-modules-commonjs", "transform-object-rest-spread" ],
"presets": [ "react" ]
}
25 changes: 16 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"babel-core": "^6.26.0",
"babel-preset-react": "^6.24.1",
"babel-plugin-transform-es2015-modules-commonjs": "^6.23.0",
"babel-plugin-transform-regenerator": "^6.22.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babelify": "^8.0.0",
"browser-sync": "^2.18.5",
"browserify": "^16.1.0",
Expand Down
16 changes: 9 additions & 7 deletions src/app/js/components/messages/MessagesView.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@ class Messages extends Component {
* @return {Array} an array with the modified messages
*/
addColor (messages, event) {
const color = event.color
const coloredMessages = messages.map(m => Object.assign({}, m))
for ( let x = 0, l = coloredMessages.length; x < l; x++ )
Object.assign(coloredMessages[x], {color, eventName: event.name})

const color = event.color,
eventName = event.name
let coloredMessages = messages.map(m => ({...m}))
for ( let x = 0, l = coloredMessages.length; x < l; x++ ) {
coloredMessages[x].color = color
coloredMessages[x].eventName = eventName
}
return coloredMessages
}

Expand All @@ -92,7 +94,7 @@ class Messages extends Component {
const visibleEvents = events.filter(event => event.visible)

const mySentMessages = props.sentMessages.filter( m => m.socketId === id )
const sentMessages = mySentMessages.map( m => Object.assign( {}, m, {right: true} ) )
const sentMessages = mySentMessages.map( m => ({ ...m, right: true}) )

const allReceivedMessages = props.messages[id] || {}
const messages = [].concat(sentMessages, ...visibleEvents.map(event => this.addColor(allReceivedMessages[event.name] || [], event) || []))
Expand All @@ -109,7 +111,7 @@ class Messages extends Component {
* @return {Array} an array of sorted messages
*/
sortMessages (messages) {
const sortedMessages = messages.map(m => Object.assign({}, m))
const sortedMessages = messages.map(m => ({...m}))
for ( let x = 0, l = sortedMessages.length - 1; x < l; x++ )
for ( let y = x + 1, l = sortedMessages.length; y < l; y++ )
if ( sortedMessages[x].timestamp < sortedMessages[y].timestamp )
Expand Down
12 changes: 11 additions & 1 deletion src/app/js/icons/TemplateIcon.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import React from 'react'

const TemplateIcon = ({size, color, customStyle, viewBox, children}) =>
<svg style={Object.assign({height: size, fill: color}, customStyle)} version="1.1" x="0px" y="0px" viewBox={viewBox}>
<svg
style={{
height: size,
fill: color,
...customStyle
}}
version="1.1"
x="0px"
y="0px"
viewBox={viewBox}
>
{children}
</svg>

Expand Down
5 changes: 4 additions & 1 deletion src/app/js/reducers/colorPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ export default function colorPicker (state = defaultState, action) {
switch (action.type) {

case 'UPDATE_COLORPICKER':
return Object.assign({}, state, action.state)
return {
...state,
...action.state
}

default:
return state
Expand Down
8 changes: 4 additions & 4 deletions src/app/js/reducers/connections.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default function connections (state = defaultState, action) {
* Adds connection object to the store (this is where the information on a socket.io connection is kept)
*/
function addConnection (state, action) {
const connections = Object.assign({}, state.connections)
const connections = {...state.connections}

const id = action.id

Expand Down Expand Up @@ -139,7 +139,7 @@ function addEvent (state, action) {
* Removes an event that a connection should listen to
*/
function removeEvent (state, action) {
const list = state.list.map(t => Object.assign({}, t))
const list = state.list.map(t => ({...t}))

const id = action.id

Expand Down Expand Up @@ -184,7 +184,7 @@ function toggleEventVisibility (state, action) {
* Change the order in which the tabs at the top are shown
*/
function changeTabOrders (state, action) {
const list = state.list.map(t => Object.assign({}, t))
const list = state.list.map(t => ({...t}))

const originalOrder = list[state.connections[action.id].index].order
const newOrder = action.order
Expand Down Expand Up @@ -215,7 +215,7 @@ function changeTabOrders (state, action) {
* Sets the event color
*/
function setEventColor (state, action) {
const list = state.list.map(t => Object.assign({}, t))
const list = state.list.map(t => ({...t}))

const id = action.id

Expand Down
11 changes: 7 additions & 4 deletions src/app/js/reducers/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function addMessage (state, action) {
const id = action.id
const eventName = action.eventName

const socketCollection = Object.assign({}, state[id])
const socketCollection = {...state[id]}
const eventMessages = [].concat(socketCollection[eventName] || [])

eventMessages.push({message: action.message, timestamp: new Date().getTime()})
Expand All @@ -34,15 +34,18 @@ function addMessage (state, action) {

socketCollection[eventName] = eventMessages

return Object.assign({}, state, {[id]: socketCollection})
return {
...state,
[id]: socketCollection
}
}

/**
* Removes messages from the store
*/
function removeMessages (state, action) {
const newState = Object.assign({}, state)
const myMessages = Object.assign({}, newState[action.id])
const newState = {...state}
const myMessages = {...newState[action.id]}
delete myMessages[action.eventName]
newState[action.id] = myMessages
return newState
Expand Down
2 changes: 1 addition & 1 deletion src/app/js/reducers/send.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function send (state = defaultState, action) {
* Adds a message to the store (this is a message that was sent, not received)
*/
function addMessage (state, {id, eventName, message}=action) {
const newState = state.map(m => Object.assign({}, m))
const newState = state.map(m => ({...m}))

newState.push({socketId: id, eventName, message, timestamp: new Date().getTime()})

Expand Down

0 comments on commit 06b7679

Please sign in to comment.