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

Removing (most) Closure from BlockFactory #1925

Merged
merged 20 commits into from
Jun 15, 2018

Conversation

AnmAtAnm
Copy link
Contributor

@AnmAtAnm AnmAtAnm commented Jun 15, 2018

The basics

  • I branched from develop
  • My pull request is against develop
  • My code follows the style guide

The details

Resolves

#668 (partially)

Proposed Changes

Replacing all Closure goog. library calls from BlockFactory, with the exception of the ColorPicker and the test for the warning about running without Closure. This includes (almost) all goog.provide and goog.require statements.

Final status:

$ grep -rF "goog." .
./index.html:      Add it only if you need it.  See also goog.require in blockly.js.
./app_controller.js:goog.require('goog.dom.xml');  // Used to detect Closure
./app_controller.js:  if (!window.goog.dom.xml) {
./workspacefactory/wfactory_init.js:goog.require('goog.ui.PopupColorPicker');
./workspacefactory/wfactory_init.js:goog.require('goog.ui.ColorPicker');
./workspacefactory/wfactory_init.js:  var colourPicker = new goog.ui.ColorPicker();
./workspacefactory/wfactory_init.js:  var popupPicker = new goog.ui.PopupColorPicker(null, colourPicker);
./workspacefactory/wfactory_init.js:  goog.events.listen(popupPicker, 'change', function(e) {

I'll remove the ColorPicker and warning in a follow-up PR.

Reason for Changes

Recent changes in Closure have been breaking BlockFactory, which uses Closure libraries but was not compiled by the Closure Compiler. This also simplifies use for people host their own BlockFactory, or running the local file from the repo.

Test Coverage

Every changed function and class was run at least once (manual testing), verifying I did not break its primary behavior. Most changes are trivial.

Tested on:

  • Desktop Chrome

@AnmAtAnm AnmAtAnm requested a review from picklesrus June 15, 2018 01:02
BlockDefinitionExtractor.newDomElement_('value', {name: 'COLOUR'});
colourInputValue.append(colourBlock);
factoryBaseEl.append(colourInputValue);
var colour_hue = block.getHue(); // May be null if not set via hue.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these TODOs actually done now?

Copy link
Contributor Author

@AnmAtAnm AnmAtAnm Jun 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#1247 was solved by #1293, which added the .getHue() method.

* @param {!BlockLibraryStorage} blockLibStorage Block Library Storage object.
* @return {!Element} XML representation of the toolbox.
*/
BlockExporterTools.prototype.generateToolboxFromLibrary
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was this unused?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

// goog.global is synonymous to window, and allows for flexibility
// between browsers.
var object = goog.global.localStorage[this.name];
var object = localStorage[this.name];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

none of the browsers require this to be window.?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

window is the global scope in a browser context: https://stackoverflow.com/a/12660102/152543

var option = document.createElement('a');
option.id ='dropdown_' + blockType;
option.classList.add('blockLibOpt');
option.innerHTML = blockType;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we try and avoid innerHtml. What is this? can it be option.textNode = blockType (or whatever it actually is)

}, this.blockType);
var labelText = document.createElement('p');
labelText.id = this.blockType + '_text';
labelText.innerHTML = this.blockType;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same innerHtml comment here.

Copy link
Contributor Author

@AnmAtAnm AnmAtAnm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced all .innerHTML assignments with .textContent.

BlockDefinitionExtractor.newDomElement_('value', {name: 'COLOUR'});
colourInputValue.append(colourBlock);
factoryBaseEl.append(colourInputValue);
var colour_hue = block.getHue(); // May be null if not set via hue.
Copy link
Contributor Author

@AnmAtAnm AnmAtAnm Jun 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#1247 was solved by #1293, which added the .getHue() method.

* @param {!BlockLibraryStorage} blockLibStorage Block Library Storage object.
* @return {!Element} XML representation of the toolbox.
*/
BlockExporterTools.prototype.generateToolboxFromLibrary
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

// goog.global is synonymous to window, and allows for flexibility
// between browsers.
var object = goog.global.localStorage[this.name];
var object = localStorage[this.name];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

window is the global scope in a browser context: https://stackoverflow.com/a/12660102/152543

*/

/**
* @fileoverview Color picker used to select the color of a toolbox category.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you mean to add this file in this commit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ummm... what file? 👀

(removed)

@picklesrus
Copy link
Contributor

LGTM

@AnmAtAnm AnmAtAnm merged commit b4cfe26 into google:develop Jun 15, 2018
@AnmAtAnm AnmAtAnm deleted the no-goog-devtools branch June 18, 2018 18:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants