Make it easy to "segment" namespace handlers.
Pomax opened this issue · comments
There is no real way to specify something like:
class Server {
constructor(...) { ... }
admin: {
async registerClient() { ... }
}
user: {
async setName(data) { ... },
async getUserList() { ... },
}
}
so it would be nice to figure out a way to make it easier to specify separated handlers for separate namespaces.
The main reason to do this would be that traditional namespacing thing: making it possible for multiple functions with the same name, under different namespaces. E.g. admin.register
vs lobby.register
vs game.register
Fun fact: this is entirely legal:
class X {
async "admin.test"(data) {
console.log(data);
}
}
But may be a little too esoteric... ?
One option is to use the namespace as a function prefix, so that if the API defines admin: endpoint: ['register']
that endpoint would need to implement a function async adminRegister
, but this can lead to really terrible function names, and I'm not sure "shitty code" is a goal I'd want to aim for.
This should probably be "use the namespaced function if it exists, otherwise omit the namespace and call that function, if it exists, otherwise throw an error"
This has been added as fall-through option:
- use
namespace$name
if that exists, - if not, use
namespace:name
if that exists, - if not, use
name
if that exists, - if not, throw a "missing function" error