Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ES6 proxy client #32

Closed
wants to merge 1 commit into from
Closed

Add ES6 proxy client #32

wants to merge 1 commit into from

Conversation

SomeoneWeird
Copy link
Member

import ht from 'hudson-taylor'

let transport = new ht.Transports.Local()
let service = new ht.Service(transport)
let client = new ht.Client({
  account: transport
})

service.on('getRandomAccount', function (data, callback) {
  return callback(null, {
    id: 4,
    name: 'you'
  })
})

let newClient = ht.proxy(client)

newClient.account.getRandomAccount(function (err, data) {
  ...
})

oooo yeaaa

@coveralls
Copy link

coveralls commented Sep 8, 2016

Coverage Status

Coverage remained the same at 100.0% when pulling cbef8ad on proxy-client into ba4b029 on master.

@jasonk000
Copy link
Contributor

nice

does anything prevent me from doing the below?

let accountSvc = newClient.account

accountSvc.getRandomAccount(function (err, data) { ... })

}

const serviceProxy = new Proxy({}, {
get: function (target, name) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only question here is, does this work with try/catch and our previous double callback issues etc? I'm not familiar with Proxy

@jasonk000
Copy link
Contributor

lgtm, do we need to add any test coverage?

@SomeoneWeird
Copy link
Member Author

Looks like it should work:

> let { s: myService } = ht.proxy(c)
undefined
> myService.echo('hello!', console.log)
null 'hello!'

And yes! I thought I added tests, obviously not - will do.

@SomeoneWeird SomeoneWeird deleted the proxy-client branch May 18, 2021 06:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants