initial commit
This commit is contained in:
@ -0,0 +1,16 @@
|
||||
/**
|
||||
* External dependencies
|
||||
*/
|
||||
import { has } from 'lodash';
|
||||
|
||||
/**
|
||||
* Utility for returning whether the given path exists in the state.
|
||||
*
|
||||
* @param {Object} state The state being checked
|
||||
* @param {Array} path The path to check
|
||||
*
|
||||
* @return {boolean} True means this exists in the state.
|
||||
*/
|
||||
export default function hasInState( state, path ) {
|
||||
return has( state, path );
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
export { default as hasInState } from './has-in-state';
|
||||
export { default as updateState } from './update-state';
|
@ -0,0 +1,17 @@
|
||||
/**
|
||||
* External dependencies
|
||||
*/
|
||||
import { setWith, clone } from 'lodash';
|
||||
|
||||
/**
|
||||
* Utility for updating state and only cloning objects in the path that changed.
|
||||
*
|
||||
* @param {Object} state The state being updated
|
||||
* @param {Array} path The path being updated
|
||||
* @param {*} value The value to update for the path
|
||||
*
|
||||
* @return {Object} The new state
|
||||
*/
|
||||
export default function updateState( state, path, value ) {
|
||||
return setWith( clone( state ), path, value, clone );
|
||||
}
|
Reference in New Issue
Block a user