Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
profileParamsToPopulate updated to work with multiple populate params
  • Loading branch information
fej-snikduj committed May 3, 2017
commit ba2be5c994cc234250ebab276bd4115d6e4d90d7
22 changes: 20 additions & 2 deletions src/actions/auth.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { omit, isArray, isString, isFunction, forEach, set, get } from 'lodash'
import {
omit,
isArray,
isString,
isFunction,
forEach,
set,
get,
mapValues
} from 'lodash'
import jwtDecode from 'jwt-decode'
import { actionTypes, defaultJWTProps } from '../constants'
import { promisesForPopulate, getPopulateObjs } from '../utils/populate'
Expand Down Expand Up @@ -105,7 +114,16 @@ export const watchUserProfile = (dispatch, firebase) => {
const populates = getPopulateObjs(profileParamsToPopulate)
const profile = snap.val()
forEach(populates, (p) => {
set(profile, p.child, get(data, `${p.root}.${snap.val()[p.child]}`))
const child = get(profile, p.child)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice use of get here, this will keep it so that dot notation can be used for child parameter of populate objects.

const populatedChild = mapValues(
child,
(value, key) => {
if (value) { // Only populate keys with truthy values
return get(data, `${p.root}.${key}`)
}
return value
})
set(profile, p.child, populatedChild)
})
dispatch({
type: SET_PROFILE,
Expand Down