fixes to dotSet & dotGet which allow getting / setting deep paths that don't exist

This commit is contained in:
Tyler Renelle
2013-09-17 13:45:30 -04:00
parent ae4f3a6481
commit fc23bdb7c8
2 changed files with 22 additions and 62 deletions
+2 -2
View File
@@ -155,7 +155,7 @@ module.exports =
_.reduce arr, (curr, next, index) ->
if (arr.length - 1) == index
curr[next] = val
curr[next]
(curr[next] ?= {})
, obj
catch err
console.error {err, path, val, _id:obj._id}
@@ -163,7 +163,7 @@ module.exports =
dotGet: (path, obj) ->
return undefined if ~path.indexOf('undefined')
try
_.reduce path.split('.'), ((curr, next) -> curr[next]), obj
_.reduce path.split('.'), ((curr, next) -> curr?[next]), obj
catch err
console.error {err, path, val, _id:obj._id}