Mixin intended to be used with _.mixin.
const Mixins = require('utils/underscore-mixins');
_.mixin(Mixins);Methods
-
<static> changed(obj1, obj2)
-
Performs a deep-diff comparison between two objects and returns a hash mapping all keys from
obj1andobj2to whether or not they were changed. (A key is mapped totrueif there are differences,falseotherwise).It does not matter which order you pass the parameters in; the returned object will remain the same.
Example:
var newModelAttributes = { a: 1, b: {create: true, edit: false}, c: 'test', d: {a: 'b', c: {d: true}} }; var oldModelAttributes = { a: 1, b: {create: true}, c: undefined, e: [1, 2] }; _.changed(newModelAttributes, oldModelAttributes); // {a: false, b: true, c: true, d: true, e: true}Parameters:
Name Type Description obj1Object The first of two objects to diff between.
obj2Object The second of two objects to diff between.
Returns:
The hash of differences between
obj1andobj2. Returnsundefinedifobj1andobj2are empty.- Type
- Object | undefined
-
<static> isEmptyValue(value)
-
Checks to see if a value is empty.
Returns true if:
- value is
undefinedornull - value is an empty string
- value is an empty object
- value is an empty array
All other values return false.
Parameters:
Name Type Description valueboolean | number | string | Object | Array The value to check.
Returns:
trueif given an empty value;falseotherwise.- Type
- boolean
- value is