Blockly.Events.utils.setRecordUndo(false); in umd way throw Uncaught TypeError: Cannot read properties of undefined (reading 'setRecordUndo')

30 views
Skip to first unread message

m lz

unread,
May 28, 2024, 7:10:34 PMMay 28
to Blockly
I checkout blockly v9.2.1 in /core/events/utils.ts code
/**
 * Sets whether events should be added to the undo stack.
 *
 * @param newValue True if events should be added to the undo stack.
 * @alias Blockly.Events.utils.setRecordUndo
 */
export function setRecordUndo(newValue: boolean) {
  recordUndo = newValue;
}
so I want to use  Blockly.Events.utils.setRecordUndo(false) at codepen.io which use  umd way,but it will throw error as bellows:

pen.js:3814  Uncaught TypeError: Cannot read properties of undefined (reading 'setRecordUndo')
    at BlockSvg$$module$build$src$core$block_svg.updateShape_ (pen.js:3814:28)
    at BlockSvg$$module$build$src$core$block_svg.setProcedureParameters_ (pen.js:3495:10)
    at BlockSvg$$module$build$src$core$block_svg.domToMutation (pen.js:3928:10)
    at HTMLInputElement.<anonymous> (pen.js:4439:20)
    at HTMLInputElement.dispatch (jquery.min.js:2:40035)
    at v.handle (jquery.min.js:2:38006)


The reason why I want to use this code is I want customize some action in redo stack.any advice is preferred,thanks.

Christopher Allen

unread,
May 29, 2024, 7:29:01 AMMay 29
to blo...@googlegroups.com
Hi Frederick,

I want to use  Blockly.Events.utils.setRecordUndo(false) at codepen.io which use  umd way,but it will throw error as bellows:

pen.js:3814  Uncaught TypeError: Cannot read properties of undefined (reading 'setRecordUndo')
    at BlockSvg$$module$build$src$core$block_svg.updateShape_ (pen.js:3814:28)
    at BlockSvg$$module$build$src$core$block_svg.setProcedureParameters_ (pen.js:3495:10)
    at BlockSvg$$module$build$src$core$block_svg.domToMutation (pen.js:3928:10)
    at HTMLInputElement.<anonymous> (pen.js:4439:20)
    at HTMLInputElement.dispatch (jquery.min.js:2:40035)
    at v.handle (jquery.min.js:2:38006)

So the error "cannot read properties of undefined (reading 'setRecordUndo') means, in the context of a call x.y.z.setRecordUndo(…)that z (but not x or y) is undefined.  So if the call is Blockly.Events.utils.setRecordUndo(false) then there is no (non-undefined) .utils property on Blockly.Events, which is surprising as (as you noted) that function definitely exists in Blockly 9.2.1.

Here are some things to check:
  • Are you sure your codepen is actually getting Blockly v9.2.1, and not some other (much different) version?
  • Does Blockly.Events.utils exist, and if so what is its value?
If you're still stuck after that then do write back.  Some things that would help us to help you would be:
  • The source code of updateShape_ (including in particular the call to setRecordUndo), or
  • A link to the codepen.

Best wishes,

Christopher

Maribeth Moffatt

unread,
May 29, 2024, 2:15:37 PMMay 29
to Blockly
Hi Frederick,

This function is exported under the `Blockly.Events` namespace, not `Blockly.Events.utils`. The locations in code don't always match the exported location of a function. You can always check our reference documentation if you're not sure. In this case the function can be accessed as `Blockly.Events.setRecordUndo`.

Best,
Maribeth

Reply all
Reply to author
Forward
0 new messages