Destroying Blockly

1,170 views
Skip to first unread message

Chris Jackson

unread,
Jun 4, 2015, 2:49:13 PM6/4/15
to blo...@googlegroups.com
Blockly creates some of the overlays directly into the HTML body (eg Toolbox div and Widget div at least). What is the recommended way to destroy these - from what I can tell, Blockly doesn't destroy these divs anywhere which means in a single page app, we can end up with multiple elements...

I'm interested in why these are created directly on the body rather than into their respective parent?

Thanks
Chris

Neil Fraser

unread,
Jun 4, 2015, 3:11:09 PM6/4/15
to blo...@googlegroups.com
Good catch.  The toolbox should be disposed of when the workspace is disposed.  Fixed.  Now you can just call workspace.dispose() and it will get rid of the toolbox too.

There are two divs that are still orphaned.  blocklyWidgetDiv and blocklyTooltipDiv are abandoned on the page.  Both should be hidden and empty.  Both will be reused if you create a new Blockly workspace.  I'm of the opinion that this is fine, but feel free to push back.

--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Chris Jackson

unread,
Jun 4, 2015, 3:35:25 PM6/4/15
to blo...@googlegroups.com
Thanks Neil,
I’ll give your fix a look. I’m certainly seeing multiple divs in my app, which is under AngularJS so they don’t appear to being reused…

I’ll take another look and report back.

Cheers
Chris

Chris Jackson

unread,
Jun 4, 2015, 3:42:19 PM6/4/15
to blo...@googlegroups.com
The toolbox div is now being reused, so it looks like this fix sorted both issues :)

Thanks
Chris

Neil Fraser

unread,
Jun 4, 2015, 3:42:55 PM6/4/15
to blo...@googlegroups.com
The relevant singleton code for tooltip and widgetdiv is:
Blockly.Tooltip.createDom = function() {
  if (Blockly.Tooltip.DIV) {
    return;  // Already created.
  }
  ...

Blockly.WidgetDiv.createDom = function() {
  if (Blockly.WidgetDiv.DIV) {
    return;  // Already created.
  }
  ...

If you are seeing multiple instances, then I'd be interested to know how it is getting past those checks.  Maybe the Blockly variable is getting wiped?


Chris

--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

map venice

unread,
Sep 1, 2015, 11:10:39 AM9/1/15
to Blockly, ro...@neil.fraser.name
I'm having the same problem as described here.  I downloaded Blockly on 8/22/2015 so, I assume whatever fix to remove the toolbox was posted to https://github.com/google/blockly/zipball/master.

Assume breakpoint in Chrome Console with Blockly loaded...

> Blockly.Workspace.dispose()  //returns error dispose is not a function

then I tried...

> x=Blockly.Workspace
> x.dispose() // returns error dispose is not a function
> x.prototype //shows there is a dispose function

Clearly, I'm doing something wrong but I have no clue what it could be?

On a side note, I wish someone would post a simple demo of Blockly being integrated into AngularJS.  By simple I mean to say, take Blockly demo and inject it into an AngularJS application.  The AngularJS application should also be a simple one page demo so novices like myself can follow along without trying to understand application specific complications.

Thanks in advance for any help anyone can provide.

Тарас З

unread,
Oct 9, 2015, 2:59:12 AM10/9/15
to Blockly, ro...@neil.fraser.name
When you initializing your blockly instance, you get it in variable like so:

var workspace = Blockly.inject('blocklyDiv' ,
      {toolbox: document.getElementById('toolbox')});

or you can use another one way to get instance:

var workspace = Blockly.getMainWorkspace('blocklyDiv');

after, you can call dispose on your workspace:

workspace.dispose()

It is all fine, except of two divs .blocklyWidgetDiv and .blocklyTooltipDiv that stay in the DOM anyway. It is a question to developers.


вівторок, 1 вересня 2015 р. 18:10:39 UTC+3 користувач map venice написав:
Reply all
Reply to author
Forward
0 new messages