Skip to content

JS Editor: add missing block coverage Phase 3 (Heap)#5899

Open
zealot-zew wants to merge 1 commit intosugarlabs:masterfrom
zealot-zew:Missing-JsEditor-blocks-3
Open

JS Editor: add missing block coverage Phase 3 (Heap)#5899
zealot-zew wants to merge 1 commit intosugarlabs:masterfrom
zealot-zew:Missing-JsEditor-blocks-3

Conversation

@zealot-zew
Copy link
Contributor

This PR introduces full support for Heap blocks within the JavaScript Editor. Users can now manage dynamic lists of data directly via JavaScript, with seamless "round-trip" conversion back to visual blocks. This includes new getters for heap state and methods for manipulating stored data.


Newly Supported Heap Blocks

The following blocks are now fully wired into the JS export/runtime and the conversion pipeline:

Data Getters (Values)

Block JavaScript Equivalent Description
Heap mouse.HEAP Returns the entire heap as a JSON string.
Heap Length mouse.HEAPLENGTH Returns the number of items currently in the heap.
Heap Empty? mouse.HEAPEMPTY Returns a boolean (true/false) if the heap is empty.

Action Blocks (Methods)

Block JavaScript Equivalent Description
Push await mouse.push(value) Adds a new value to the end of the heap.
Set Heap Entry await mouse.setHeapEntry(index, value) Updates or adds a value at a specific index (1–1000).
Empty Heap await mouse.emptyHeap() Clears all data from the turtle's heap.
Reverse Heap await mouse.reverseHeap() Reverses the order of items in the heap in place.

Images:
image

Previous Works:
PR #5834
PR #5898

This PR introduces full support for Heap (Data Storage) blocks within the JavaScript Editor. Users can now manage dynamic lists of data directly via JavaScript, with seamless "round-trip" conversion back to visual blocks. This includes new getters for heap state and methods for manipulating stored data.
@github-actions
Copy link
Contributor

✅ All Jest tests passed! This PR is ready to merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant