all files / src/ fieldValue.js

100% Statements 12/12
100% Branches 7/7
100% Functions 3/3
100% Lines 9/9
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 1238×   617×               574×   617×     630×    
const flag = '_isFieldValue';
const isObject = object => typeof object === 'object';
 
export function makeFieldValue(object) {
  if (object && isObject(object)) {
    // This flag has to be enumerable, because otherwise it is not possible
    // to serialize object with this field.
    // The consequence is you lose information that particular field is
    // field or nested group of fields, so you're not able to fetch
    // field value from state when it has been affected in some way
    // by serializing/using immutable and so on.
    // @fixme marking field as leaf should be made in other way
    Object.defineProperty(object, flag, {value: true, enumerable: true});
  }
  return object;
}
 
export function isFieldValue(object) {
  return !!(object && isObject(object) && object[flag]);
}