DeepCopy not copying objects


#1

This post was flagged by the community and is temporarily hidden.


#2

I made another update to the deepCopy() function to handle arrays. I think this deepCopy function is working with child objects and arrays now:

function deepCopy(target, source, i) {
  	  i = i || 0;
  		console.log(i + ". deepCopy(" + JSON.stringify(target) + ", " + JSON.stringify(source));
  		for (var name in source) {
  			var tval = target[name], 
  			    sval = source[name];
  			if (tval !== sval) {
  				if (sval && typeof sval === 'object') {
  					console.log(i + ". source is an object: " + JSON.stringify(sval));
  					if (Object.prototype.toString.call(sval) === '[object Date]') { // use this date test to handle crossing frame boundaries
  						target[name] = new Date(sval);
  					} else if (Array.isArray(sval)) {
   						  console.log(i + ". source is array: " + JSON.stringify(sval));
   						  target[name] = deepCopyArray(sval);
  					} else {
  						if (tval && typeof tval === 'object') {
  						  console.log(i + ". target is object: " + JSON.stringify(tval));
  							deepCopy(tval, sval, i++);
  						} else {
  						  console.log(i + ". target is NOT object: " + JSON.stringify(tval));
  							target[name] = deepCopy({}, sval, i++);
  						}
  					}
  				} else {
  					console.log(i + ". source is NOT object: " + JSON.stringify(sval));
  					target[name] = sval;
  				}
  			}
  		}
  		console.log(i + ". returning: " + JSON.stringify(target));
  		return target;
  	}
  	
  	function deepCopyArray(source) {
  console.log("deepCopyArray(" + JSON.stringify(source) + ")");
  var clonedArray = [];
 	    source.forEach(function(svalItem) {
 	      if (typeof svalItem === 'object') {
 	        clonedArray.push(deepCopy({}, svalItem));
 	      } else {
 	        clonedArray.push(svalItem);
 	      }
 	    });
  console.log("deepCopyArray return: " + JSON.stringify(clonedArray));
 	    return clonedArray;
  	}

I have also updated the example at http://plnkr.co/edit/Ee3zqUemvKfFVqI3mo73 Should this be updated in dojo/request/util?


#3

Probably… care to open a pull request for review?


#4

I think I created a ticket (#293) and followed the steps to create a pull request. Let me know if you can see it, and if you see any issues with it.

Thanks

Nathan


#5

I see the ticket, but not the pull request… could you provide a link here to where you think the pull request is?


#6

I was afraid of that. I think I missed a couple steps in creating the pull request. I’m pretty sure I have it created now and associated with the ticket: https://github.com/dojo/dojo/pull/294

Let me know if you see any issues.


#7

I think I have submitted the pull request correctly and I believe I have signed the CLA, but it looks like the CLA warning is still in the thread. Do I need to resubmit the changes or is there something else I still need to do with the pull request?