Allow nested objects in the `getResourceName()` identifier.

This commit is contained in:
Jeff Stieler 2018-12-03 20:01:23 -07:00
parent 736d927ead
commit cfd4462941
1 changed files with 15 additions and 1 deletions

View File

@ -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 }`;
}