Skip to content

Commit fcd8862

Browse files
authored
chore: Remove unnecessary code, clarify comments for suggested-blocks plugin (#2592)
1 parent 1e11730 commit fcd8862

1 file changed

Lines changed: 8 additions & 11 deletions

File tree

plugins/suggested-blocks/src/index.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class BlockSuggestor {
3131
*/
3232
this.defaultJsonForBlockLookup = {};
3333
/**
34-
* List of reently used block types
34+
* List of recently used block types in order, starting from the most recent
3535
*/
3636
this.recentlyUsedBlocks = [];
3737
/**
@@ -51,7 +51,7 @@ export class BlockSuggestor {
5151
}
5252

5353
/**
54-
* Generates a list of the 10 most frequently used blocks, in order.
54+
* Generates a list of the most frequently used blocks, in order.
5555
* Includes a secondary sort by most recent blocks.
5656
* @returns {!Array<!Blockly.utils.toolbox.BlockInfo>}A list of block JSON
5757
*/
@@ -83,23 +83,20 @@ export class BlockSuggestor {
8383
};
8484

8585
/**
86-
* Generates a list of the 10 most recently used blocks.
86+
* Generates a list of the most recently used blocks, in order, starting from
87+
* the most recent.
8788
* @returns {Array <object>} A list of block JSON objects
8889
*/
8990
getRecentlyUsed = function () {
91+
// recentlyUsedBlocks sorted from most recent and spec requires sets
92+
// preserve insertion order
9093
const uniqueRecentBlocks = [...new Set(this.recentlyUsedBlocks)];
91-
const recencyMap = new Map();
92-
for (const [index, key] of this.recentlyUsedBlocks.entries()) {
93-
if (!recencyMap.has(key)) {
94-
recencyMap.set(key, index + 1);
95-
}
96-
}
97-
uniqueRecentBlocks.sort((a, b) => recencyMap[a] - recencyMap[b]);
9894
return this.generateBlockData(uniqueRecentBlocks);
9995
};
10096

10197
/**
102-
* Converts a list of block types to a full-fledge list of block data.
98+
* Converts a list of block types to a full-fledge list of block data, limited
99+
* to the specified size of the category
103100
* @param {Array<string>} blockTypeList the list of block types
104101
* @returns {Array<JSON>} the block data list
105102
*/

0 commit comments

Comments
 (0)