2017-09-26 69 views
2

我一堆效用函數的我把整個項目重新創建這個樣子:Lodash utils a la`mapArrayToObj`和它的反向?

export function objectToArray(obj){ 
    return Object.keys(obj).map(key => obj[key]); 
} 

export function mapArrayToObj(arr) { 
    return addArrayToObj({}, arr); 
} 

export function addArrayToObj(obj, arr) { 
    arr.forEach((elem) => obj[elem._id] = elem); // '_id' would be a param 
    return obj; 
} 

export function patchExisting(existingEntitiesDict, newEntitiesDict) { 
    return Object.assign(existingEntitiesDict, newEntitiesDict); 
} 

這實質上有些與normalizr重疊的,但我想知道是否有在lodash一些功能,我可以用它代替重新創建這些映射函數。

回答