UNPKG

azure-devops-ui

Version:

React components for building web UI in Azure DevOps

49 lines (48 loc) 1.24 kB
const CURRENT_ID_PROPERTY = "__currentIdProp__"; const DEFAULT_ID_STRING = "id__"; const global = (typeof window !== "undefined" && window) || process; if (global[CURRENT_ID_PROPERTY] === undefined) { global[CURRENT_ID_PROPERTY] = 0; } function checkProperties(a, b) { for (const propName in a) { if (a.hasOwnProperty(propName)) { if (!b.hasOwnProperty(propName) || b[propName] !== a[propName]) { return false; } } } return true; } /** * Generates a unique id in the global scope (this spans across duplicate copies of the same library.) * * @public */ export function getId(prefix) { const index = global[CURRENT_ID_PROPERTY]++; return (prefix || DEFAULT_ID_STRING) + index; } /** * Resets id counter to an (optional) number. * * @public */ export function resetIds(counter = 0) { global[CURRENT_ID_PROPERTY] = counter; } /** * Compares a to b and b to a. * * @public */ export function shallowCompare(a, b) { // Handle the same object if (a === b) { return true; } if (!a || !b) { return false; } return checkProperties(a, b) && checkProperties(b, a); }