I've question about Blockly.Xml.textToDom function

148 views
Skip to first unread message

남승인

unread,
Nov 25, 2022, 3:56:41 AM11/25/22
to Blockly
hello, Im Jeremy. glad to you~

suddenly, in during my project, I have a question about Blockly.Xml.textToDom function.

I try to change shadow of my blocks in toolbox at runtime. whenever I get some UI value update event-

so I maked function via Blockly.Xml.textToDom to javascript.
 
var connection = targetField.connection;
connection.setShadowDom(null);
            connection.disconnect();
following : var dom = Blockly.Xml.textToDom(
          '<xml>' +
          '  <shadow type="math_number"><field name="NUM">'+ this.transform.position[keys[index]] +'</field></shadow>' +
          '</xml>').children[0];
connection.setShadowDom(dom);
          connection.respawnShadow_();


but that is worked has bug.

whenever I trigged change value events, paramters input of my blocks to twinkle~*twinkle~*

what I incorrect used? please reply-

thanks regard :)

남승인

unread,
Nov 26, 2022, 4:08:52 AM11/26/22
to Blockly
KakaoTalk_20221126_180734481.gif

2022년 11월 25일 금요일 오후 5시 56분 41초 UTC+9에 남승인님이 작성:

Christopher Allen

unread,
Nov 26, 2022, 8:01:50 AM11/26/22
to blo...@googlegroups.com
Hi Jeremy,

Regrettably I'm not as familiar with shadow blocks as some of my colleagues, and in addition to that I am not certain I entirely understand your questions, but I will do my best to give you some helpful information, and I would invite you to please reply with additional information so that we can try to help you further.

suddenly, in during my project, I have a question about Blockly.Xml.textToDom function.

I read the rest of your message, and actually I am not sure what your question about Blockly.Xml.textToDom might be.  In fact it appears to me that you are using this function correctly, although I note that there might be a better way of doing what you want to do.
 
I try to change shadow of my blocks in toolbox at runtime. whenever I get some UI value update event-

Nice.  I like this.
 
so I maked function via Blockly.Xml.textToDom to javascript.
 
var connection = targetField.connection;
connection.setShadowDom(null);
            connection.disconnect();
following : var dom = Blockly.Xml.textToDom(
          '<xml>' +
          '  <shadow type="math_number"><field name="NUM">'+ this.transform.position[keys[index]] +'</field></shadow>' +
          '</xml>').children[0];
connection.setShadowDom(dom);
          connection.respawnShadow_();


but that is worked has bug.

whenever I trigged change value events, paramters input of my blocks to twinkle~*twinkle~*

Here are my thoughts:
  • I'm not actually sure what you mean by "paramters input of my blocks to twinkle~*twinkle~*".  I see you added a screenshot, but your use of the word "twinkle" makes me think it is some kind of unwanted animation effect.  If so, maybe a little video would help us understand better?
  • Connection.prototype.setShadowDom calls .setShadowDomInternal_ which then makes calls to .respawnShadow_ in certain circumstances, so it looks like you probably don't need to call respawnShadow_—and since it is marked protected, you probably shouldn't.  Is it possible that calling respawnShadow_ unnecessarily is causing the "twinkling", as the shadow block is created and then deleted and recreated again?
  • This code looks like it could probably be simplified—and the call to textToDom avoided completely—by using the new JSON-base serialisation instead of the XML one.  I think the new code would look something like:

    const shadowState = {
      type: 'math_number',
      fields: {NUM: this.transform.position[keys[index]]},
    };
    targetField.connection.setShadowState(shadowState);


    (N.B. I have not tested this and I am not certain that I've got the format of shadowState correct.)

I hope this helps you; do please write back and let us know if you were able to solve the problem—and if not, do give us additional information about the problem so that we might be better able to understand.

Best wishes,

Christopher

Message has been deleted

Christopher Allen

unread,
Nov 28, 2022, 11:45:08 AM11/28/22
to Blockly
Hi Jeremy,

I saw you sent a message that you were still having difficulty with "twinkling"—but it looks like you deleted that message?  Anyway, if you are still having an issue then it might be a bug, and we'd really appreciate it if you could provide:
  • A video of the "twinkling" effect you are seeing, and
  • Code and/or instructions to reproduce it ourselves.

Thanks,

Christopher

Reply all
Reply to author
Forward
0 new messages