(val, createMode=false)
| 89 | } |
| 90 | |
| 91 | export function prepareData(val, createMode=false) { |
| 92 | if(_.isPlainObject(val)) { |
| 93 | _.forIn(val, function (el) { |
| 94 | if (_.isObject(el)) { |
| 95 | prepareData(el, createMode); |
| 96 | } |
| 97 | }); |
| 98 | } else if(_.isArray(val)) { |
| 99 | val.forEach(function(el) { |
| 100 | if (_.isPlainObject(el)) { |
| 101 | /* The each row in collection need to have an id to identify them uniquely |
| 102 | This helps in easily getting what has changed */ |
| 103 | /* Nested collection rows may or may not have idAttribute. |
| 104 | So to decide whether row is new or not set, the cid starts with |
| 105 | nn (not new) for existing rows. Newly added will start with 'c' (created) |
| 106 | */ |
| 107 | el['cid'] = createMode ? _.uniqueId('c') : _.uniqueId('nn'); |
| 108 | prepareData(el, createMode); |
| 109 | } |
| 110 | }); |
| 111 | } |
| 112 | return val; |
| 113 | } |
| 114 | |
| 115 | export const flatternObject = (obj, base=[]) => Object.keys(obj).sort((a, b)=>a.localeCompare(b)).reduce( |
| 116 | (r, k) => { |
no outgoing calls
no test coverage detected