Use targetWasCreated event to clone pen state

Remove explicit cloning of `_customState` in favor of smarter,
state-specific cloning.
This commit is contained in:
Christopher Willis-Ford 2017-06-16 14:22:51 -07:00
parent 04871e24d6
commit 06d5994a32
4 changed files with 43 additions and 1 deletions
src/engine

View file

@ -968,6 +968,16 @@ class Runtime extends EventEmitter {
return this._cloneCounter < Runtime.MAX_CLONES;
}
/**
* Report that a new target has been created, possibly by cloning an existing target.
* @param {Target} newTarget - the newly created target.
* @param {Target} [sourceTarget] - the target used as a source for the new clone, if any.
* @fires Runtime#targetWasCreated
*/
fireTargetWasCreated (newTarget, sourceTarget) {
this.emit('targetWasCreated', newTarget, sourceTarget);
}
/**
* Get a target representing the Scratch stage, if one exists.
* @return {?Target} The target, if found.
@ -1014,4 +1024,12 @@ class Runtime extends EventEmitter {
}
}
/**
* Event fired after a new target has been created, possibly by cloning an existing target.
*
* @event Runtime#targetWasCreated
* @param {Target} newTarget - the newly created target.
* @param {Target} [sourceTarget] - the target used as a source for the new clone, if any.
*/
module.exports = Runtime;