haxball / haxball-issues

115 stars 43 forks source link

room callbacks' placeholders #600

Open olehmisar opened 5 years ago

olehmisar commented 5 years ago

Hey, basro. I am currently making haxball API wrapper for better development. I use custom class which contains _room property that references original RoomObject. To delegate methods I use something like this:

_.forOwn(this._room, (value, key) => {
  this[key] = value
})

This code delegates methods like setPlayerAdmin or setPlayerTeam.

I also need to delegate callbacks. But it is impossible now because callbacks don't exist on RoomObject by default.

I am asking you to add default callbacks on RoomObject. It can be null or some_unique_value if you don't want it to be a function. So, I will be able to delegate callbacks too:


_.forOwn(this._room, (value, key) => {
  if (value === null) {
    // Register callback
  } else {
    this[key] = value
  }
})
olehmisar commented 5 years ago

You can use Symbol class to make unique value

saviola777 commented 5 years ago

Possibly related projects:

https://github.com/morko/haxroomie-EventTrapper https://github.com/saviola777/haxball-headless-manager

These projects use JavaScript Proxies to intercept / delegate calls.

olehmisar commented 5 years ago

@saviola777 Proxies is a bad choice because they are very slow. I just need to get list of all callbacks to register them.