Skip to main content

Class: BlockSuggestor

Defined in: index.js:24

Class that tracks all blocks created in a workspace and suggests future blocks to use.

Properties index​

PropertyDescription
defaultJsonForBlockLookupSaves the full JSON data for each block type the first time it's used. This helps store what initial configuration / sub-blocks each block type would be expected to have.
generateBlockDataConverts a list of block types to a full-fledge list of block data, limited to the specified size of the category
getMostUsedGenerates a list of the most frequently used blocks, in order. Includes a secondary sort by most recent blocks.
getRecentlyUsedGenerates a list of the most recently used blocks, in order, starting from the most recent.
numBlocksPerCategoryConfig parameter which sets the size of the toolbox categories.
recentlyUsedBlocksList of recently used block types in order, starting from the most recent
workspaceHasFinishedLoadingChecks if the workspace is finished loading, to avoid taking action on all the BLOCK_CREATE events during workspace loading.

Methods index​

MethodDescription
clearPriorBlockDataResets the internal state of this object.
eventListenerCallback for when the workspace sends out events.
loadFromSerializedDataLoads the state of this object from a serialized JSON.
saveToSerializedDataSaves the state of this object to a serialized JSON.

Constructors​

Constructor​

new BlockSuggestor(numBlocksPerCategory): BlockSuggestor;

Defined in: index.js:29

Constructs a BlockSuggestor object.

Parameters​

ParameterTypeDescription
numBlocksPerCategorynumberthe size of each toolbox category

Returns​

BlockSuggestor

Properties​

defaultJsonForBlockLookup​

defaultJsonForBlockLookup: object;

Defined in: index.js:35

Saves the full JSON data for each block type the first time it's used. This helps store what initial configuration / sub-blocks each block type would be expected to have.


generateBlockData​

generateBlockData: (blockTypeList) => JSON[];

Defined in: index.js:53

Converts a list of block types to a full-fledge list of block data, limited to the specified size of the category

Parameters​

ParameterTypeDescription
blockTypeListstring[]the list of block types

Returns​

JSON[]

the block data list


getMostUsed​

getMostUsed: () => BlockInfo[];

Defined in: index.js:51

Generates a list of the most frequently used blocks, in order. Includes a secondary sort by most recent blocks.

Returns​

BlockInfo[]

A list of block JSON


getRecentlyUsed​

getRecentlyUsed: () => object[];

Defined in: index.js:52

Generates a list of the most recently used blocks, in order, starting from the most recent.

Returns​

object[]

A list of block JSON objects


numBlocksPerCategory​

numBlocksPerCategory: number;

Defined in: index.js:48

Config parameter which sets the size of the toolbox categories.


recentlyUsedBlocks​

recentlyUsedBlocks: any[];

Defined in: index.js:39

List of recently used block types in order, starting from the most recent


workspaceHasFinishedLoading​

workspaceHasFinishedLoading: boolean;

Defined in: index.js:44

Checks if the workspace is finished loading, to avoid taking action on all the BLOCK_CREATE events during workspace loading.

Methods​

clearPriorBlockData()​

clearPriorBlockData(): void;

Defined in: index.js:150

Resets the internal state of this object.

Returns​

void


eventListener()​

eventListener(e): void;

Defined in: index.js:159

Callback for when the workspace sends out events.

Parameters​

ParameterTypeDescription
eAbstractthe event object

Returns​

void


loadFromSerializedData()​

loadFromSerializedData(data): void;

Defined in: index.js:131

Loads the state of this object from a serialized JSON.

Parameters​

ParameterTypeDescription
dataobjectthe serialized data payload to load from

Returns​

void


saveToSerializedData()​

saveToSerializedData(): object;

Defined in: index.js:140

Saves the state of this object to a serialized JSON.

Returns​

object

a serialized data object including this object's state