Hi Everyone
I have an issue with how to represent a called back function with parameters - essentially, I am trying to Blockify (?!) a call to an http request handler.
I'm using a 'simplified' block generation library that I am developing for a specific project - where the developers aren't blockly knowledgeable, so I've used a defineRule below as a helper (factory) function to create blocks - the javascript function is a standard blockly function that is injected into the generated block.
var STATEMENT = 'STATEMENT';
defineRule({
name: 'When UI Message', next:false, previous:false,
interface: [ {statement:STATEMENT} ],
javascript: function(block) {
var statement = getStatement(block, STATEMENT);
var result = "quando.whenHttpRequest('update', function(params, response) {\n"
+ statement
+ "});\n";
return result;
}
});
The problem I have is with the use of the callback parameters (i.e. params and response) by the statement blocks. I could add two new blocks (or variables) to represent params and response - but if I do this, they will also be available within other blocks as well - but the code they generate will fail at run time.
Alternatively I can wrap the parameters with run time functions - e.g. so I could put a 'Respond' block - this could fail at run time when not appropriate... But again this is a run time issue.
Is there any way to have the scope of the block allow a 'sort' of mutator like aspect to offer 'local' parameters JUST within the block.
Or would this be done (instead) by validating the use of the parameters as 'invalid' when used in other blocks?
Hope this makes sense
Best wishes
Andy