Skip to content

Commit

Permalink
expose a copy of the custom block as "caller" to input slot reaction …
Browse files Browse the repository at this point in the history
…scripts inside custom block definitions
  • Loading branch information
jmoenig committed Nov 11, 2024
1 parent 559b074 commit af31340
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
5 changes: 5 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Snap! (BYOB) History

## in development:
* **New Features:**
* expose a copy of the custom block as "caller" to input slot reaction scripts inside custom block definitions

### 2024-11-11
* threads: expose a copy of the custom block as "caller" to input slot reaction scripts inside custom block definitions

## 10.2.2:
* **Notable Changes:**
Expand Down
2 changes: 1 addition & 1 deletion snap.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<script src="src/symbols.js?version=2024-09-13"></script>
<script src="src/widgets.js?version=2024-07-24"></script>
<script src="src/blocks.js?version=2024-11-10"></script>
<script src="src/threads.js?version=2024-11-10"></script>
<script src="src/threads.js?version=2024-11-11"></script>
<script src="src/objects.js?version=2024-11-10"></script>
<script src="src/scenes.js?version=2024-05-28"></script>
<script src="src/gui.js?version=2024-11-10"></script>
Expand Down
8 changes: 7 additions & 1 deletion src/threads.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ StagePickerMorph, CustomBlockDefinition, CommentMorph, BooleanSlotMorph*/

/*jshint esversion: 11, bitwise: false, evil: true*/

modules.threads = '2024-November-10';
modules.threads = '2024-November-11';

var ThreadManager;
var Process;
Expand Down Expand Up @@ -1983,6 +1983,12 @@ Process.prototype.mergeVariables = function () {
Symbol.for('block'),
this.context.expression.block // expression is an InputList
);
// bind a copy of the block instance to "this caller"
// not entirely convinced about the benefits, but let's play with it
this.context.outerContext.variables.addVar(
Symbol.for('caller'),
this.context.expression.block.fullCopy().reify()
);
this.context.expression.names.forEach((name, i) =>
this.context.outerContext.variables.addVar(name, this.context.inputs[i])
);
Expand Down

0 comments on commit af31340

Please sign in to comment.