mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-07 13:22:07 -05:00
Only attempt to reuse object that importJSON() is called on, when its type matches the root of the imported data.
Closes #764
This commit is contained in:
parent
7888d1d107
commit
96d617a5ff
1 changed files with 6 additions and 5 deletions
|
@ -444,7 +444,7 @@ Base.inject(/** @lends Base# */{
|
||||||
// creation. This is used in #importJSON() to pass
|
// creation. This is used in #importJSON() to pass
|
||||||
// on insert = false to all items except layers.
|
// on insert = false to all items except layers.
|
||||||
if (create) {
|
if (create) {
|
||||||
res = create(type, args);
|
res = create(type, args, isRoot);
|
||||||
} else {
|
} else {
|
||||||
res = Base.create(type.prototype);
|
res = Base.create(type.prototype);
|
||||||
type.apply(res, args);
|
type.apply(res, args);
|
||||||
|
@ -476,10 +476,11 @@ Base.inject(/** @lends Base# */{
|
||||||
typeof json === 'string' ? JSON.parse(json) : json,
|
typeof json === 'string' ? JSON.parse(json) : json,
|
||||||
// Provide our own create function to handle target and
|
// Provide our own create function to handle target and
|
||||||
// insertion.
|
// insertion.
|
||||||
function(ctor, args) {
|
function(ctor, args, isRoot) {
|
||||||
// If a target is provided and its of the right type,
|
// If a target is provided and its of the right type
|
||||||
// import right into it.
|
// for the root item, import right into it.
|
||||||
var useTarget = target && target.constructor === ctor,
|
var useTarget = isRoot && target
|
||||||
|
&& target.constructor === ctor,
|
||||||
obj = useTarget ? target
|
obj = useTarget ? target
|
||||||
: Base.create(ctor.prototype),
|
: Base.create(ctor.prototype),
|
||||||
// When reusing an object, try to initialize it
|
// When reusing an object, try to initialize it
|
||||||
|
|
Loading…
Reference in a new issue