-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Open
Labels
Milestone
Description
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_CASEand, 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.jsshould be replace by a getter/setter pair to provide backward compatibility.
- They should be renamed so as not to be
- Groups of related constants should become a suitably named
@enumwhere appropriate.
Specific recommendations
OPPOSITE_TYPEshould be moved toconnection_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 inCONSTANT_CASE.)- …