MCPcopy Index your code
hub / github.com/plotly/plotly.py / createDeltaObject

Function createDeltaObject

js/src/widget.ts:1943–2015  ·  view source on GitHub ↗

* Return object that contains all properties in fullObj that are not * identical to the corresponding properties in removeObj * * Properties of fullObj and removeObj may be objects or arrays of objects * * Returned object is a deep clone of the properties of the input objects * * @param {Obje

(fullObj: any, removeObj: any)

Source from the content-addressed store, hash-verified

1941 *
1942 */
1943function createDeltaObject(fullObj: any, removeObj: any) {
1944 // Initialize result as object or array
1945 var res: any;
1946 if (Array.isArray(fullObj)) {
1947 res = new Array(fullObj.length);
1948 } else {
1949 res = {};
1950 }
1951
1952 // Initialize removeObj to empty object if not specified
1953 if (removeObj === null || removeObj === undefined) {
1954 removeObj = {};
1955 }
1956
1957 // Iterate over object properties or array indices
1958 for (var p in fullObj) {
1959 if (
1960 p[0] !== "_" && // Don't consider private properties
1961 fullObj.hasOwnProperty(p) && // Exclude parent properties
1962 fullObj[p] !== null // Exclude cases where fullObj doesn't
1963 // have the property
1964 ) {
1965 // Compute object equality
1966 var props_equal;
1967 props_equal = _.isEqual(fullObj[p], removeObj[p]);
1968
1969 // Perform recursive comparison if props are not equal
1970 if (!props_equal || p === "uid") {
1971 // Let uids through
1972
1973 // property has non-null value in fullObj that doesn't
1974 // match the value in removeObj
1975 var fullVal = fullObj[p];
1976 if (removeObj.hasOwnProperty(p) && typeof fullVal === "object") {
1977 // Recurse over object properties
1978 if (Array.isArray(fullVal)) {
1979 if (fullVal.length > 0 && typeof fullVal[0] === "object") {
1980 // We have an object array
1981 res[p] = new Array(fullVal.length);
1982 for (var i = 0; i < fullVal.length; i++) {
1983 if (!Array.isArray(removeObj[p]) || removeObj[p].length <= i) {
1984 res[p][i] = fullVal[i];
1985 } else {
1986 res[p][i] = createDeltaObject(fullVal[i], removeObj[p][i]);
1987 }
1988 }
1989 } else {
1990 // We have a primitive array or typed array
1991 res[p] = fullVal;
1992 }
1993 } else {
1994 // object
1995 var full_obj = createDeltaObject(fullVal, removeObj[p]);
1996 if (Object.keys(full_obj).length > 0) {
1997 // new object is not empty
1998 res[p] = full_obj;
1999 }
2000 }

Callers 2

_sendLayoutDeltaMethod · 0.85
_sendTraceDeltasMethod · 0.85

Calls 1

keysMethod · 0.45

Tested by

no test coverage detected