Skip to content

Break up and remove core/internal_constants.js and core/constants.js #5158

@cpcallen

Description

@cpcallen

Background

#5140 is an important precursor to finishing the first pass of migrating goog.provides to goog.module by removing side effects from core/constants.js, which previously modified the Blockly object by adding a large number of assorted @constant properties to it.

In order not to advertise any new API surface, these constants have been redeclared in core/internal_constants.js (rather than core/contstants.js), which is marked @package to prevent their use outside of core.

Proposal

  • All constants should be moved out of this file and to the file(s) containing the code to which they relate.
  • Where they are only used in a single module, they should become unexported, module-local constants in that file.
  • Consideration should be given as to whether they could be renamed to improve readability.
  • Where they are intended to be user-configurable parameters:
    • They should be renamed so as not to be CONSTANT_CASE and, to comply with style guide rules forbidding mutable exports, and either be
      • moved to an exported options object, or
      • replaced with pairs of get/set functions that modify an unexported local variable.
    • The current alias in core/blockly.js should be replace by a getter/setter pair to provide backward compatibility.
  • Groups of related constants should become a suitably named @enum where appropriate.

Specific recommendations

  • OPPOSITE_TYPE should be moved to connection_type.js—and possibly also be renamed to make code that uses it is more readable—e.g., let x = oppositeConnectionType[y] instead of … = OPPOSITE_TYPE[y]. (There's no rule that requires objects that happen never to be mutated to be declared in CONSTANT_CASE.)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions