maccman/spine — Issue #205: cloning a clone produces inconsistencies
Author: hhuuggoo
Created: 2012-02-15 03:37:16+00:00
State: open

I ran into this problem because I was storing models in external datastructures so that I could create alternative indexes on my models. model events are called with clones, and as a result clones ended up in my structure. This is easy for me to work around now that I understand what is going on.

test('temp_test', function(){
TempModel = Spine.Model.sub({});
TempModel.configure('TempModel', 'title', 'data', 'columns');
var template = TempModel.create({'title':'a','data':1,'columns':['a','b']});
var clone, clone1, clone2
clone = template.clone();
clone.updateAttributes({'title':'a','data':2,'columns':['a','b']});
clone1 = clone.clone();
clone1.updateAttributes({'title':'a','data':3,'columns':['a','b']});
clone2 = clone1.clone();
clone2.updateAttributes({'title':'a','data':3,'columns':['a','b']});

ok(clone.data === template.data)
ok(clone1.data === template.data)
ok(clone2.data === template.data)
console.log(template.data)
console.log(clone.data)
console.log(clone1.data)
console.log(clone2.data)

the console output will be

3
2
3
3

updating a clone of a clone will propagate changes to the original, but not to the original clone!