question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proposal for extensible input/field types from the JSON block definition

See original GitHub issue

Problem 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:closed
  • Created 6 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
RoboErikGcommented, Feb 7, 2018

I have a preference for API calls so that it’s less painful if we need to change the implementation in the future.

0reactions
jollytoadcommented, Feb 7, 2018

@rachel-fenichel thanks for the quick turn around on #1592, now that’s merged I’ve submitted a proper PR for this ^

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found