remove object rest spread
This commit is contained in:
parent
1d801f036f
commit
689ac34584
3 changed files with 33 additions and 49 deletions
4
.babelrc
4
.babelrc
|
@ -5,8 +5,6 @@
|
||||||
],
|
],
|
||||||
"plugins": [
|
"plugins": [
|
||||||
"lodash",
|
"lodash",
|
||||||
"transform-class-properties",
|
"transform-class-properties"
|
||||||
"transform-es2015-destructuring",
|
|
||||||
"transform-object-rest-spread"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,8 +24,6 @@
|
||||||
"babel-loader": "6.2.5",
|
"babel-loader": "6.2.5",
|
||||||
"babel-plugin-lodash": "^3.2.9",
|
"babel-plugin-lodash": "^3.2.9",
|
||||||
"babel-plugin-transform-class-properties": "6.11.5",
|
"babel-plugin-transform-class-properties": "6.11.5",
|
||||||
"babel-plugin-transform-es2015-destructuring": "^6.16.0",
|
|
||||||
"babel-plugin-transform-object-rest-spread": "^6.16.0",
|
|
||||||
"babel-preset-es2015": "6.14.0",
|
"babel-preset-es2015": "6.14.0",
|
||||||
"babel-preset-react": "6.11.1",
|
"babel-preset-react": "6.11.1",
|
||||||
"backbone": "1.0.0",
|
"backbone": "1.0.0",
|
||||||
|
|
|
@ -11,7 +11,7 @@ const IN_CONVERSATION = 1
|
||||||
|
|
||||||
const addMapperToMap = (map, userId) => { return { ...map, [userId]: NOT_IN_CONVERSATION }}
|
const addMapperToMap = (map, userId) => { return { ...map, [userId]: NOT_IN_CONVERSATION }}
|
||||||
|
|
||||||
module.exports = { reducer: (state = { connectedPeople: {}, liveMaps: {} }, action) => {
|
const reducer = (state = { connectedPeople: {}, liveMaps: {} }, action) => {
|
||||||
const { type, payload } = action
|
const { type, payload } = action
|
||||||
const { connectedPeople, liveMaps } = state
|
const { connectedPeople, liveMaps } = state
|
||||||
const map = payload && liveMaps[payload.mapid]
|
const map = payload && liveMaps[payload.mapid]
|
||||||
|
@ -20,68 +20,56 @@ module.exports = { reducer: (state = { connectedPeople: {}, liveMaps: {} }, acti
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case JOIN_MAP:
|
case JOIN_MAP:
|
||||||
return {
|
return Object.assign({}, state, {
|
||||||
connectedPeople: {
|
connectedPeople: Object.assign({}, connectedPeople, {
|
||||||
...connectedPeople,
|
|
||||||
[payload.userid]: {
|
[payload.userid]: {
|
||||||
id: payload.userid,
|
id: payload.userid,
|
||||||
username: payload.username,
|
username: payload.username,
|
||||||
avatar: payload.avatar
|
avatar: payload.avatar
|
||||||
}
|
}
|
||||||
},
|
}),
|
||||||
liveMaps: {
|
liveMaps: Object.assign({}, liveMaps, {
|
||||||
...liveMaps,
|
|
||||||
[payload.mapid]: addMapperToMap(map || {}, payload.userid)
|
[payload.mapid]: addMapperToMap(map || {}, payload.userid)
|
||||||
}
|
})
|
||||||
}
|
})
|
||||||
case LEAVE_MAP:
|
case LEAVE_MAP:
|
||||||
|
// if the map will empty, remove it from liveMaps, if the map will not empty, just remove the mapper
|
||||||
|
const newLiveMaps = mapWillEmpty
|
||||||
|
? omit(liveMaps, payload.mapid)
|
||||||
|
: Object.assign({}, liveMaps, { [payload.mapid]: omit(map, payload.userid) })
|
||||||
|
|
||||||
return {
|
return {
|
||||||
connectedPeople: omit(connectedPeople, payload.userid),
|
connectedPeople: omit(connectedPeople, payload.userid),
|
||||||
// if the map will empty, remove it from liveMaps, if the map will not empty, just remove the mapper
|
liveMaps: omitBy(newLiveMaps, isNil)
|
||||||
liveMaps: omitBy(mapWillEmpty ? omit(liveMaps, payload.mapid) : { ...liveMaps, [payload.mapid]: omit(liveMaps[payload.mapid], payload.userid) }, isNil)
|
|
||||||
}
|
}
|
||||||
case JOIN_CALL:
|
case JOIN_CALL:
|
||||||
return {
|
// update the user (payload.id is user id) in the given map to be marked in the conversation
|
||||||
// connectedPeople stays the same
|
return Object.assign({}, state, {
|
||||||
connectedPeople,
|
liveMaps: Object.assign({}, liveMaps, {
|
||||||
liveMaps: {
|
[payload.mapid]: Object.assign({}, map, {
|
||||||
// liveMaps stays the same, except for
|
|
||||||
...liveMaps,
|
|
||||||
// the map in question
|
|
||||||
[payload.mapid]: {
|
|
||||||
// which stays the same, except for
|
|
||||||
...map,
|
|
||||||
// the user in question, which is now marked as being in a conversation
|
|
||||||
[payload.id]: IN_CONVERSATION
|
[payload.id]: IN_CONVERSATION
|
||||||
}
|
})
|
||||||
}
|
})
|
||||||
}
|
})
|
||||||
case LEAVE_CALL:
|
case LEAVE_CALL:
|
||||||
return {
|
const newMap = callWillFinish
|
||||||
// connectedPeople stays the same
|
? mapValues(map, () => NOT_IN_CONVERSATION)
|
||||||
connectedPeople,
|
: Object.assign({}, map, { [payload.userid]: NOT_IN_CONVERSATION })
|
||||||
liveMaps: {
|
|
||||||
// liveMaps stays the same, except for
|
return Object.assign({}, state, {
|
||||||
...liveMaps,
|
liveMaps: Object.assign({}, liveMaps, { map: newMap })
|
||||||
// the map in question
|
})
|
||||||
[payload.mapid]: callWillFinish ? mapValues(map, () => NOT_IN_CONVERSATION) : {
|
|
||||||
// which stays the same, except for
|
|
||||||
...map,
|
|
||||||
// the user in question, which is now marked as being NOT in conversation
|
|
||||||
[payload.userid]: NOT_IN_CONVERSATION
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case 'DISCONNECT':
|
case 'DISCONNECT':
|
||||||
const mapWithoutUser = omit(map, payload.userid)
|
const mapWithoutUser = omit(map, payload.userid)
|
||||||
const newMap = callWillFinish ? mapValues(mapWithoutUser, () => NOT_IN_CONVERSATION) : mapWithoutUser
|
const newMap = callWillFinish ? mapValues(mapWithoutUser, () => NOT_IN_CONVERSATION) : mapWithoutUser
|
||||||
|
const newLiveMaps = mapWillEmpty ? omit(liveMaps, payload.mapid) : Object.assign({}, liveMaps, { [payload.mapid]: newMap })
|
||||||
return {
|
return {
|
||||||
connectedPeople: omit(connectedPeople, payload.userid),
|
connectedPeople: omit(connectedPeople, payload.userid),
|
||||||
// if the map will empty, remove it from liveMaps, if the map will not empty, just remove the mapper
|
liveMaps: omitBy(newLiveMaps, isNil)
|
||||||
liveMaps: omitBy(mapWillEmpty ? omit(liveMaps, payload.mapid) :
|
|
||||||
{ ...liveMaps, [payload.mapid]: newMap }, isNil)
|
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return state
|
return state
|
||||||
}
|
}
|
||||||
} }
|
}
|
||||||
|
|
||||||
|
module.exports = reducer
|
||||||
|
|
Loading…
Add table
Reference in a new issue