cocos / cocos-engine

Cocos simplifies game creation and distribution with Cocos Creator, a free, open-source, cross-platform game engine. Empowering millions of developers to create high-performance, engaging 2D/3D games and instant web entertainment.
https://www.cocos.com/en/creator
Other
8.23k stars 1.94k forks source link

Unify the event style of engine #14823

Open shrinktofit opened 1 year ago

shrinktofit commented 1 year ago

Re: https://discord.gg/cocos-simplify-game-development-634690911896469525

shrinktofit commented 1 year ago

In discussion with @PPpro , we prefer the on() style registering:

class A extends EventTarget {
  on(type: "event-a", (callback_signature_of_event_a) => void): void;
  on(type: "event-b", (callback_signature_of_event_b) => void): void;
  on(type: string, callback: (...args: unknown[]) => void) {
    super.on(type, callback); // Forward to `super.on`
  }
}
pandamicro commented 1 year ago

@lealzhan please check the event callbacks in physics module @holycanvas please check the event callbacks in 2D & UI module

PPpro commented 1 year ago

some developers also have some feedback for event registration on Spine module @zhakesi https://forum.cocos.org/t/topic/148276/64?u=_pp