Skip to content

Commit

Permalink
Clarify duplication behaviors
Browse files Browse the repository at this point in the history
  • Loading branch information
apple502j committed Jul 1, 2020
1 parent e8e0821 commit 0f211b7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/engine/target.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Target extends EventEmitter {
/**
* @param {Runtime} runtime Reference to the runtime.
* @param {?Blocks} blocks Blocks instance for the blocks owned by this target.
* @param {?Object.<string, *>} comments Array of comments owned by this target.
* @param {?Object.<string, Comment>} comments Array of comments owned by this target.
* @constructor
*/
constructor (runtime, blocks, comments) {
Expand Down
15 changes: 11 additions & 4 deletions src/sprites/sprite.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Sprite {
/**
* Dictionary of comments for this target.
* Key is the comment id.
* @type {Object.<string,*>}
* @type {Object.<string, Comment>}
*/
this.comments = {};
}
Expand Down Expand Up @@ -157,14 +157,17 @@ class Sprite {
Object.keys(this.comments).forEach(commentId => {
const comment = this.comments[commentId];
const newComment = new Comment(
null, // use new comment id
null, // generate new comment id
comment.text,
comment.x,
comment.y,
comment.width,
comment.height,
comment.minimized
);
// If the comment is attached to a block, it has a blockId property for the block it's attached to.
// Because we generate new block IDs for all the duplicated blocks, change all the comments' attached-block
// IDs from the old block IDs to the new ones.
if (comment.blockId) {
const newBlockId = oldToNew[comment.blockId];
if (newBlockId) {
Expand All @@ -173,10 +176,14 @@ class Sprite {
if (newBlock) {
newBlock.comment = newComment.id;
} else {
log.warn(`Could not find block with id ${newBlockId
} associated with comment ${newComment.id}`);
log.warn(`Could not find block with id ${newBlockId} associated with comment ${newComment.id}`);
}
} else {
// Comments did not get deleted when the block got deleted
// Such comments have blockId, but because the block is deleted
// oldToNew mapping does not include that blockId
// Handle it as workspace comment
// TODO do not load such comments when deserializing
log.warn(`Could not find block with id ${comment.blockId
} associated with comment ${comment.id} in the block ID mapping`);
}
Expand Down

0 comments on commit 0f211b7

Please sign in to comment.