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
obj1
andobj2
to whether or not they were changed. (A key is mapped totrue
if there are differences,false
otherwise).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 obj1
Object The first of two objects to diff between.
obj2
Object The second of two objects to diff between.
Returns:
The hash of differences between
obj1
andobj2
. Returnsundefined
ifobj1
andobj2
are empty.- Type
- Object | undefined
-
<static> isEmptyValue(value)
-
Checks to see if a value is empty.
Returns true if:
- value is
undefined
ornull
- value is an empty string
- value is an empty object
- value is an empty array
All other values return false.
Parameters:
Name Type Description value
boolean | number | string | Object | Array The value to check.
Returns:
true
if given an empty value;false
otherwise.- Type
- boolean
- value is