Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamically typed variable getters and setters #1281

Closed
rachel-fenichel opened this issue Aug 17, 2017 · 2 comments
Closed

Dynamically typed variable getters and setters #1281

rachel-fenichel opened this issue Aug 17, 2017 · 2 comments
Labels
component: developer apis component: variables help wanted External contributions actively solicited issue: feature request Describes a new feature and why it should be added

Comments

@rachel-fenichel
Copy link
Collaborator

rachel-fenichel commented Aug 17, 2017

Blockly should provide two additional blocks: variables_get_dynamic and variables_set_dynamic. These blocks should dynamically change the types on their output/input connections based on the type of the currently selected variable.

We should also provide a custom tag for toolbox categories that populates the toolbox with the dynamic variable blocks instead of the standard ones. Probably VARIABLES_DYNAMIC.

Why: It is now possible to create variables with different types, and to get the type of the currently selected variable. In general on blocks with typed variable fields we can't infer the type of the output statically, but we can infer it dynamically for the general getter and setter blocks. This saves developers from having to make separate getters and setters for each variable type they create. (They still may want to in order to be explicit about their types.)

Why create new blocks instead of changing variables_get and variables_set: backwards compatibility.

These blocks will have the same shape as the variables_get and variables_set blocks:
image

They will have the same basic definitions as the variables_get and variables_set blocks (see below) but have onchange handlers to set their connection types appropriately.

// Block for variable getter.
  {
    "type": "variables_get",
    "message0": "%1",
    "args0": [
      {
        "type": "field_variable",
        "name": "VAR",
        "variable": "%{BKY_VARIABLES_DEFAULT_NAME}"
      }
    ],
    "output": null,
    "colour": "%{BKY_VARIABLES_HUE}",
    "helpUrl": "%{BKY_VARIABLES_GET_HELPURL}",
    "tooltip": "%{BKY_VARIABLES_GET_TOOLTIP}",
    "extensions": ["contextMenu_variableSetterGetter"]
  },
  // Block for variable setter.
  {
    "type": "variables_set",
    "message0": "%{BKY_VARIABLES_SET}",
    "args0": [
      {
        "type": "field_variable",
        "name": "VAR",
        "variable": "%{BKY_VARIABLES_DEFAULT_NAME}"
      },
      {
        "type": "input_value",
        "name": "VALUE"
      }
    ],
    "previousStatement": null,
    "nextStatement": null,
    "colour": "%{BKY_VARIABLES_HUE}",
    "tooltip": "%{BKY_VARIABLES_SET_TOOLTIP}",
    "helpUrl": "%{BKY_VARIABLES_SET_HELPURL}",
    "extensions": ["contextMenu_variableSetterGetter"]
  }
@rachel-fenichel rachel-fenichel changed the title Dynamically typed variable blocks Dynamically typed variable getters and setters Aug 17, 2017
@rachel-fenichel rachel-fenichel added the help wanted External contributions actively solicited label Sep 12, 2017
@rachel-fenichel
Copy link
Collaborator Author

@duzc2 is going to implement this.

I suggest two PRs: one to make the blocks, and a separate one to make the toolbox category.

#1312 is a followup that we're keeping separate because it's a UX question.

#1199 is an outstanding issue with variables. I don't think it'll impact this work. If you run into it, let me know but don't worry about fixing it--that's on my plate right now.

@duzc2
Copy link
Contributor

duzc2 commented Nov 25, 2017

#1481

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: developer apis component: variables help wanted External contributions actively solicited issue: feature request Describes a new feature and why it should be added
Projects
None yet
Development

No branches or pull requests

3 participants