Import only lodash set and defaults deep

This commit is contained in:
Adam Butterworth
2019-02-21 13:49:23 -05:00
committed by Adam Butterworth
parent a3b7999627
commit 2efdc78ace
5 changed files with 22 additions and 7 deletions

View File

@@ -1,3 +1,5 @@
import defaultsDeep from 'lodash.defaultsdeep';
import {
FETCH_PREFERENCES,
SAVE_PREFERENCES,
@@ -41,10 +43,10 @@ const profile = (state = initialState, action) => {
savePreferencesState: 'pending',
};
case SAVE_PREFERENCES.SUCCESS:
// defaults deep used because our preferences/state object is multi-dimensional
return {
...state,
...defaultsDeep({}, action.preferences, state),
savePreferencesState: 'complete',
...action.preferences,
};
case SAVE_PREFERENCES.FAILURE:
return {

View File

@@ -1,6 +1,5 @@
import camelcaseKeys from 'camelcase-keys';
import snakecaseKeys from 'snakecase-keys';
import _ from 'lodash';
import apiClient from '../data/apiClient';
import { configuration } from '../config';
@@ -20,7 +19,10 @@ const clientServerKeyMap = {
languageProficiencies: 'language_proficiencies',
accountPrivacy: 'account_privacy',
};
const serverClientKeyMap = _.invert(clientServerKeyMap);
const serverClientKeyMap = Object.entries(clientServerKeyMap).reduce((acc, [key, value]) => {
acc[value] = key;
return acc;
}, {});
export function getProfile(username) {

View File

@@ -1,10 +1,10 @@
import _ from 'lodash';
import set from 'lodash.set';
export function unflattenAndTransformKeys(obj, transformer) {
const newObj = {};
Object.entries(obj).forEach(([key, value]) => {
_.set(newObj, key.split('.').map(transformer), value);
set(newObj, key.split('.').map(transformer), value);
});
return newObj;