From dafdd0ae28046d3a9b8bfc7f947087ecf88e9f66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Sun, 13 Apr 2014 16:44:00 +0200 Subject: [PATCH] Avoid double-insertion of root layer when importing JSON directly into it. --- src/core/Base.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/core/Base.js b/src/core/Base.js index 41a1d4ce..fd1d7445 100644 --- a/src/core/Base.js +++ b/src/core/Base.js @@ -381,8 +381,7 @@ Base.inject(/** @lends Base# */{ * first */ deserialize: function(json, create, _data) { - var res = json, - isRoot = !_data; + var res = json; // A _data side-car to deserialize that can hold any kind of // 'global' data across a deserialization. It's currently only used // to hold dictionary definitions. @@ -416,7 +415,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, isRoot); + res = create(type, args); } else { res = Base.create(type.prototype); type.apply(res, args); @@ -442,7 +441,7 @@ Base.inject(/** @lends Base# */{ typeof json === 'string' ? JSON.parse(json) : json, // Provide our own create function to handle target and // insertion - function(type, args, isRoot) { + function(type, args) { // If a target is provided and its of the right type, // import right into it. var obj = target && target.constructor === type @@ -453,8 +452,8 @@ Base.inject(/** @lends Base# */{ // we want these to be created on the fly in the active // project into which we're importing (except for if // it's a preexisting target layer). - if (!isRoot && args.length === 1 && obj instanceof Item - && (!(obj instanceof Layer) || isTarget)) { + if (args.length === 1 && obj instanceof Item + && (isTarget || !(obj instanceof Layer))) { var arg = args[0]; if (Base.isPlainObject(arg)) arg.insert = false;