Proposal for extensible input/field types from the JSON block definition
See original GitHub issueProblem statement
Adding or modifying an input or field type in the block JSON definition requires customisation of the Blockly.Block.prototype.interpolate_
function - adding or changing a case
in the switch
statement … https://github.com/google/blockly/blob/master/core/block.js#L1143
Proposal
I’d like to suggest replacing the switch with a object of input/field handlers, into which we can add new types or override existing types.
Blockly.Block.jsonInputTypes = {
input_value: function(element) {
return this.appendValueInput(element['name']);
},
...
};
Blockly.Block.jsonFieldTypes = {
field_label: function(element) {
return Blockly.Block.newFieldLabelFromJson_(element);
},
...
};
and replace the switch with:
var inputType = Blockly.Block.jsonInputTypes[element['type']]
var fieldType = Blockly.Block.jsonFieldTypes[element['type']]
if (inputType) {
input = inputType.call(this, element)
} else if (fieldType) {
field = fieldType.call(this, element)
}
// The input/field fn may return null so it falls back to the 'alt' definition
if (!input && !field && element['alt']) {
element = element['alt'];
altRepeat = true;
}
if its something that you think could be accepted into the codebase I’d be more than happy to prepare a PR and sign the CLA.
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (6 by maintainers)
Top Results From Across the Web
Define Blocks | Blockly - Google Developers
A block has one or more inputs, where each input is a sequence of labels and fields that may end in a connection....
Read more >Designing a framework for expressing Function Block ...
First, the main JSON data types are identified which the format consists of. Thereafter, the proposed JSON framework for FBDs is presented ...
Read more >OpenAPI Specification - Version 3.0.3 - Swagger
The OpenAPI Specification defines a standard interface to RESTful APIs which allows both humans and computers to understand service capabilities without ...
Read more >Web of Things (WoT) Thing Description - W3C
JSON -LD keyword to define short-hand names called terms that are used throughout a TD document. mandatory, anyURI or Array. @type, JSON-LD ...
Read more >OpenAPI Specification v3.0.3 | Introduction, Definitions, & More
The Schema Object allows the definition of input and output data types. These types can be objects, but also primitives and arrays. This...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I have a preference for API calls so that it’s less painful if we need to change the implementation in the future.
@rachel-fenichel thanks for the quick turn around on #1592, now that’s merged I’ve submitted a proper PR for this ^