Closed happilymarrieddad closed 6 years ago
@happilymarrieddad Great. This is a good start and I agree that the time has come to bring promises to the socketcluster-client, but we should have a discussion about it before we merge any code into the master branch since this is going to be a major change. Here are some of my thoughts:
About this new feature:
callback
AND promise.then(...)
style in different parts of their code. If we want to support promises, I think that we shouldn't support the old callback style at the same time.Because of the two points above, we should consider either:
es6
release branch for the ES6/Promise client inside this socketcluster-client
repo - Then we can deploy this new ES6 client to npm alongside the current client under a different package name (for a while at least).About your code:
mocha
test suite to socketcluster-client
(see test/
directory), if you get the latest version of the repo, you can run it with npm test
- We're moving away from ad-hock testing so we should adapt your test logic to the mocha
format and start using describe
, it
and assert
.Promise.toString().indexOf("[native code]")
tends to be problematic; I think it's better to avoid this kind of feature detection if possible because it's rarely 100% reliable (when doing feature detection for socketcluster-client, I often find myself fixing issues with React Native, Cordova, IE, Android WebView, Opera browser, ... or some other weird JavaScript engine); so I think it's better to let the developer use different clients for different environments and not do any automatic feature detection (currently the client only does feature detection for native WebSockets
vs ws
but it's been a major pain). Also we don't want to keep adding if (self.allowPromises) ...
in every single function.sift
on the command line)... Or when doing automatic search and replace.--
Let me know what you think about branching vs forking the current code to make the new ES6 client then we can proceed to the next stepa and merge some of your code (after modifications have been made).
@jondubois Thanks so much for providing all that information. I'm going to close this pull request and attempt to recreate a full promise version of sc-client from scratch. Hopefully, I can get something together after a little while. Thanks again!
@happilymarrieddad I created a new repo (forked from the current one) so you can do your PRs against that one instead https://github.com/socketcluster/socketcluster-es6-client - The main difference is that when you add promise support for a method, you should also remove callback support from that method. Also since this client/repo isn't live yet, you can do multiple small PRs against master branch (you can convert just emit
function to promises - Unlike socketcluster-client
, we don't have to keep it in a clean development state at this point).
Small PRs are actually better; that way we can discuss as we go.
I added promise support to the client-side emit event. I could really use this for V4 of our app. It will allow us to integrate Async/Await with our app more easily without having to use a wrapper.
is so much better than using a wrapper. Thanks!
If this gets approved, I am going to attempt to add promises throughout SC and hopefully at some point that it will be available all over the API. Thanks!
to test it.