Created
January 2, 2016 13:06
-
-
Save mattcollier/c87853a818726737be93 to your computer and use it in GitHub Desktop.
lodash assign test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var _ = require('lodash'); | |
var history = { | |
BYZ: {someData: 'original'}, | |
ABC: {someData: 'originalABC'} | |
}; | |
var revision = { | |
BYZ: {someData: 'revisedBYZ'}, | |
ABC: {someData: 'revisedABC'}, | |
CBA: {someData: 'revisdeNOP'} | |
}; | |
// _.assign(history, revision); | |
// _.assign(history, revision, function(objVal, sourceVal) { | |
// // console.log(objVal, key, object, source); | |
// return _.isUndefined(objVal) ? sourceVal : objVal; | |
// }); | |
_.assign(history, revision, function(objVal, sourceVal, key) { | |
// console.log(objVal, key, object, source); | |
if(_.isUndefined(objVal)) { | |
var newObj = {}; | |
newObj[key] = sourceVal; | |
console.log('EMIT', newObj); | |
return sourceVal; | |
} | |
console.log('HISTORY COLLISION:', key); | |
return objVal; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment