Blockly.Events.fromJson is used still get deprecated warning

40 views
Skip to first unread message

Koen Van Wijk

unread,
Feb 4, 2023, 4:29:51 PM2/4/23
to Blockly
Hi,

Eventhough I use the Blockly.Events.fromJson in the super of some super I still end up in core\events\events_abstract.ts: static fromJson(json: AbstractEventJson, workspace: Workspace, event: any):
That creates the warning. Is this intended?

Regards,
Koen

Neil Fraser

unread,
Feb 7, 2023, 5:37:56 AM2/7/23
to blo...@googlegroups.com
Am Sa., 4. Feb. 2023 um 22:29 Uhr schrieb 'Koen Van Wijk' via Blockly <blo...@googlegroups.com>:
Eventhough I use the Blockly.Events.fromJson in the super of some super I still end up in core\events\events_abstract.ts: static fromJson(json: AbstractEventJson, workspace: Workspace, event: any):
That creates the warning. Is this intended?

I agree this looks wrong.  Specifically, every event subclass defines a non-static fromJson which is deprecated with the identifier "Blockly.Events.Xyz.prototype.fromJson", but the abstract event defines a static fromJson whichis deprecated with the identifier "Blockly.Events.Abstract.prototype.fromJson".  Beka, can you clarify the intended behaviour here?  This appears to be the relevant change.

This was a hard question, I wrote no less than seven replies, then deleted each as I discovered it was wrong.
--
Neil Fraser, Switzerland
https://neil.fraser.name

Beka Westberg

unread,
Feb 7, 2023, 11:24:32 AM2/7/23
to Blockly
Hello :D

Ah yep, the deprecation warning in the static `fromJson` method was erroneous, it should have been in the instance `fromJson` method of the Abstract event class.

The intended behavior is that all new events have:
  • A `fromJson` static method
  • No empty constructors
  • No `fromJson` instance methods
  • No nullable properties
And it is intended that to construct an event from JSON you call `Blockly.Events.fromJson`. See https://github.com/google/blockly/issues/6607 for more context =)

I've filed a bug for moving the incorrect location of the deprecation warning: https://github.com/google/blockly/issues/6830

Best wishes, and thank you for finding this!
--Beka

Reply all
Reply to author
Forward
0 new messages