Allow nested objects in the `getResourceName()` identifier.
This commit is contained in:
parent
736d927ead
commit
cfd4462941
|
@ -1,7 +1,21 @@
|
|||
/** @format */
|
||||
/**
|
||||
* External dependencies
|
||||
*/
|
||||
import { isObject } from 'lodash';
|
||||
|
||||
export function getResourceName( prefix, identifier ) {
|
||||
const identifierString = JSON.stringify( identifier, Object.keys( identifier ).sort() );
|
||||
const keyList = [];
|
||||
Object.keys( identifier ).forEach( key => {
|
||||
keyList.push( key );
|
||||
|
||||
// whitelist nested object keys
|
||||
if ( isObject( identifier[ key ] ) ) {
|
||||
Array.prototype.push.apply( keyList, Object.keys( identifier[ key ] ) );
|
||||
}
|
||||
} );
|
||||
|
||||
const identifierString = JSON.stringify( identifier, keyList.sort() );
|
||||
return `${ prefix }:${ identifierString }`;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue