Blockly extension

167 views
Skip to first unread message

Naveen Chandar

unread,
Mar 2, 2021, 6:33:10 AM3/2/21
to Blockly
Hi,
Is there any way to check the blockly extensions are regisered or not ?

let eventStart = {
  "type": "event_start",
  "message0": "%1",
  "args0": [
    {
      "type": "input_dummy",
      "name": "INPUT"
    }
  ],
  "inputsInline": true,
  "nextStatement": null,
  // "colour": 230,
  "tooltip": "",
  "helpUrl": "",
  "extensions": ["setcomponentAndEvents"],
  "style":"event_start_block"
};

//props data -> fetch from api
let componentId= 'path';

const componentEvent = [["click", "click"], ["change", "change"], ["blur", "blur"], ["focus", "focus"],
        ["keyDown", "keyDown"], ["keyPress", "keyPress"], ["keyUp", "keyUp"], ["Selected", "Selected"],
        ["Scanned", "Scanned"], ["PullToRefresh", "PullToRefresh"]];
        if (componentName?.toLowerCase() === 'page' || (this.props.matchParams?.PageId == componentId)) {
            pageEvent = [["onPageShow", "onPageShow"], ["onPageCreate", "onPageCreate"], ["onPageHide", "onPageHide"],
            ["onPageChange", "onPageChange"]];
        } else {
            pageEvent = [];
        }

 Blockly.Extensions.register('setcomponentAndEvents',
            function () {
                this.getInput('INPUT')
                    .appendField(new Blockly.FieldImage("/jsbuilder/Fill.svg", 15, 15, { alt: "*", flipRtl: "FALSE" }))
                    .appendField("When")
                    .appendField(new Blockly.FieldDropdown([[componentId, componentId]]), "component")
                    .appendField("is");
                if (pageEvent.length > 0)
                    this.getInput('INPUT').appendField(new Blockly.FieldDropdown(pageEvent), "event");
                else
                    this.getInput('INPUT').appendField(new Blockly.FieldDropdown(componentEvent), "event");
                this.appendStatementInput("NAME").setCheck(null);
            });

I have called this function in componentwillmount. But its showing error as extension 'setcomponentAndEvents' is not found.
If i'm calling this function in componentdidmount then its showing error as extnsion setcomponentAndEvents already registered.

So, Is there any way to check extension is registerd or not. 

Thanks,
Naveen

Beka Westberg

unread,
Mar 2, 2021, 5:54:40 PM3/2/21
to blo...@googlegroups.com
Hello Naveen,

Huh those errors sound really weird! From giving it a quick look it seems like you're doing everything correctly, so I'm not sure what's going on :/

If you want to check if an extension is registered for debugging purposes you can check the Blockly.Extensions.ALL_ object. But I don't recommend doing this in production because it is a private property (which means it could change at any time)!

Sorry I can't be more help :/ Best of luck on your project!
--Beka

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/blockly/097379cc-a5f6-43ba-835f-c8d18db27f4dn%40googlegroups.com.

feni...@google.com

unread,
Mar 3, 2021, 6:49:33 PM3/3/21
to Blockly
I agree with Beka for debugging: check out Blockly.Extensions.ALL_.

Is it possible that you are trying to create the block before calling Blockly.Extensions.register('setcomponentAndEvents', ...)? If that were the case, the first time around you would get an error on the block creation because there would be no registered extension, and the second time around the block creation would work fine but the extension registration would ail.

Rachel

feni...@google.com

unread,
Mar 3, 2021, 6:51:52 PM3/3/21
to Blockly
I've also filed an issue to add a function for checking if an extension is registered.
Reply all
Reply to author
Forward
0 new messages