ObjUtil
A class with static util methods for working with objects.
Static Method Summary
Static Public Methods | ||
public static |
Performs a shallow comparison of two objects and returns an array containing the names of changed properties, or |
|
public static |
Like |
|
public static |
Returns a new object that contains only specific values of an original object. |
|
public static |
pojo(value: any): any Deeply converts an immutable or mixed value to a plain javascript object. |
|
public static |
registerImmutable(immutable: object) Register the |
|
public static |
Returns an object containing all properties except the ones specified via |
|
public static |
Returns an array containing all values of an object, like as |
Static Public Methods
public static diff(a: object, b: object, names: Array<String>): * source
Performs a shallow comparison of two objects and returns an array containing the names of changed properties, or null
if all values were strictly equal.
Works with both immutable and plain JS objects.
Can be used for shouldComponentUpdate, e.g. if (Obj.diff(this.props, nextProps, ['name', 'address'])) { ... }
is basically the same as if (this.props.name !== nextProps.name || this.props.address !== nextProps.address) { ... }
Return:
* |
public static keys(obj: object, options: object): object source
Like Object.keys
, but allows you to omit certain names.
Return:
object | A new object containing all keys (property names) of the object except the excluded ones |
Example:
Obj.keys(this.props, {not: ['onClick']})
public static pick(obj: object, keys: Array): object source
Returns a new object that contains only specific values of an original object. If the original object was immutable, the result will be immutable too.
public static pojo(value: any): any source
Deeply converts an immutable or mixed value to a plain javascript object.
If the given object itself was a primitive, undefined
or null
, it is returned as-is.
Params:
Name | Type | Attribute | Description |
value | any | A plain or immutable value |
Return:
any | A plain object or a primitive value. |
public static registerImmutable(immutable: object) source
Register the immutable.js
library.
This is only required by the pick()
method when used on immutable objects.
Params:
Name | Type | Attribute | Description |
immutable | object | The |
Example:
ObjUtil.registerImmutable(require('immutable'))