mattstyles / koa-socket

Sugar for connecting socket.io to a koa instance
242 stars 50 forks source link

Use ES6 generator as listener handler, add namespace support #1

Closed hbpoison closed 8 years ago

hbpoison commented 10 years ago
    socket.on('todo:get', function *(data) {
        var res = yield todos.get;
        this.emit('todo:get', res);
    });
hbpoison commented 10 years ago
mattstyles commented 10 years ago

Sorry for the lack of response, been away for a few days. Will look tonight! Cheers!

mattstyles commented 10 years ago

This is certainly something that is on my todo list, thanks for the contribution.

However, it changes the public API exposed by the library. Although I havent implemented test cases yet (sorry about that, most unhelpful I know) I'm basically using a test repo, any PR would certainly have to run there. The npm start command in that repo uses nvm, if you're not using that (or have a different version of 0.11) then alter bin/start to get it going. It's a pretty straight-forward chat application, nothing incredible but I think it uses most of the API defined in 0.3.0.

One thing that does immediately strike me, any namespace implementation would probably have to be transparent, so that socket.on( ... ) would work seamlessly without knowledge of the underlying architecture. Should be simple enough to just expose the default '/' route for this purpose and maintain the defined API whilst adding namespace support should you need it in whatever app you're using koa-socket in. I certainly wouldnt want namespacing to be mandatory.