From 96d617a5ffd4565f66afa324f081e66b77efc6d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Wed, 3 Feb 2016 09:47:49 +0100 Subject: [PATCH] Only attempt to reuse object that importJSON() is called on, when its type matches the root of the imported data. Closes #764 --- src/core/Base.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/core/Base.js b/src/core/Base.js index cb57c047..dbd7b10b 100644 --- a/src/core/Base.js +++ b/src/core/Base.js @@ -444,7 +444,7 @@ Base.inject(/** @lends Base# */{ // creation. This is used in #importJSON() to pass // on insert = false to all items except layers. if (create) { - res = create(type, args); + res = create(type, args, isRoot); } else { res = Base.create(type.prototype); type.apply(res, args); @@ -476,10 +476,11 @@ Base.inject(/** @lends Base# */{ typeof json === 'string' ? JSON.parse(json) : json, // Provide our own create function to handle target and // insertion. - function(ctor, args) { - // If a target is provided and its of the right type, - // import right into it. - var useTarget = target && target.constructor === ctor, + function(ctor, args, isRoot) { + // If a target is provided and its of the right type + // for the root item, import right into it. + var useTarget = isRoot && target + && target.constructor === ctor, obj = useTarget ? target : Base.create(ctor.prototype), // When reusing an object, try to initialize it