-
Notifications
You must be signed in to change notification settings - Fork 619
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: Block Collections #1360
Comments
I would have use for such collections and see workspace analysis performance as the main benefit. But I'm not sure if it should be part of Blockly or be left to projects to add if needed. Updating collections could be handled outside Blockly by a workspace event listener. |
So, wrt to solution 1 above, if you are just iterating through plain old JS objects (ie. not DOM) then it should be perfectly fine performance wise, even when the block count reaches 1k or more. Performance problems usually only surface when DOM (or other non-JS API) interactions are involved. But, what you propose sounds like indexing of blocks by a tag, so why not just use an object of key -> array of blocks. |
An object like {key, [blocks]} is indeed the basic idea. The proposal just adds some utility functions to make things easier. Using utility functions allows us to save information about where the block is stored to the block. We need to know where the block is stored so that when we dispose of the block we can remove it from all collections. If it gets left in a collection we'll get detached nodes :/ So |
@BeksOmega How do you feel about moving this to samples? Rachel and I discussed and we don't think this belongs in core-
|
Problem Statement
Often you want to access all the blocks with a specific "tag". For example: all procedure blocks, all call blocks for a specific procedure, all blocks of a particular type, all top blocks, etc.
Currently there are two ways of doing this:
Both of these approaches have problems. 1 is not very efficient, and 2 is not very extendable.
Proposal
Create functions on the workspace to support adding blocks to and accessing blocks from dynamic collections based on tags.
The structure for the collections object will be a dictionary of string keys that point to arrays of blocks. Each collection can have multiple blocks, and each block can be in multiple collections.
Add a function to the workspace named
addBlockToCollection(block, collection)
.This function will:
Add a function to the workspace named
removeBlockFromCollection(block, collection)
.This function will (all of this is dependent on how addBlockToCollection works):
Add a function to the workspace named
removeBlockFromAllCollections(block/bindData)
.This function will:
Add a function to the workspace named
getBlocksInCollection(collection)
.This function will:
If this proposal is accepted I think it may also be useful to set up some naming conventions for the tags. Maybe something like general category:specific tag. E.g. position:top, position:orphan, type:controls_if, caller:do_something.
Use Cases
I think this would be a useful addition to the blockly core because it would make the procedure code more efficient, but I also think it would be useful to outside developers.
Here are some use cases:
Plus the things that are already provided i.e. top blocks, all blocks, and blocks by type, this just makes it more extendable and dynamic.
The text was updated successfully, but these errors were encountered: