Import only lodash set and defaults deep
This commit is contained in:
committed by
Adam Butterworth
parent
a3b7999627
commit
2efdc78ace
10
package-lock.json
generated
10
package-lock.json
generated
@@ -12744,6 +12744,11 @@
|
||||
"resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz",
|
||||
"integrity": "sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8="
|
||||
},
|
||||
"lodash.defaultsdeep": {
|
||||
"version": "4.6.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.defaultsdeep/-/lodash.defaultsdeep-4.6.0.tgz",
|
||||
"integrity": "sha1-vsECT4WxvZbL6kBbI8FK1kQ6b4E="
|
||||
},
|
||||
"lodash.difference": {
|
||||
"version": "4.5.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.difference/-/lodash.difference-4.5.0.tgz",
|
||||
@@ -12834,6 +12839,11 @@
|
||||
"integrity": "sha1-0uPuv/DZ05rVD1y9G1KnvOa7YRs=",
|
||||
"dev": true
|
||||
},
|
||||
"lodash.set": {
|
||||
"version": "4.3.2",
|
||||
"resolved": "https://registry.npmjs.org/lodash.set/-/lodash.set-4.3.2.tgz",
|
||||
"integrity": "sha1-2HV7HagH3eJIFrDWqEvqGnYjCyM="
|
||||
},
|
||||
"lodash.sortby": {
|
||||
"version": "4.7.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.sortby/-/lodash.sortby-4.7.0.tgz",
|
||||
|
||||
@@ -44,7 +44,8 @@
|
||||
"font-awesome": "^4.7.0",
|
||||
"history": "^4.7.2",
|
||||
"i18n-iso-countries": "^3.7.8",
|
||||
"lodash": "^4.17.11",
|
||||
"lodash.defaultsdeep": "^4.6.0",
|
||||
"lodash.set": "^4.3.2",
|
||||
"prop-types": "^15.5.10",
|
||||
"query-string": "^5.1.1",
|
||||
"react": "^16.2.0",
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user