Skip to content

Conversation

@tengla
Copy link

@tengla tengla commented Oct 5, 2016

It's better to clone 'hostOrCallback' to avoid side effects.

If you run r.connect more than one time with the same config object,
it gets mutated in case 'username' is set instead of 'user'.

Then, the second time you run r.connect, with the same config object,
the driver will complain that you can't use both 'username' and 'user'
at the same time.

Object.assign on 'hostOrCallback' will fix this issue.

It's better to clone 'hostOrCallback' to avoid side effects.

If you run r.connect more than one time with the same config object,
it(config) gets mutated in case 'username' is set instead of 'user'.

Then, the second time you run r.connect, with the same config object,
the driver will complain that you can't use both 'username' and 'user'
at the same time.

Object.assign on 'hostOrCallback' will fix this issue.
@AtnNn AtnNn added this to the 2.3.x milestone Oct 17, 2016
@srh
Copy link
Contributor

srh commented Jun 10, 2017

There's a bug here, yes. Object.assign is only supported by Node.js 4 and up. Might that be a problem? Anybody?

@marshall007
Copy link
Contributor

@srh Node v0.12.x and earlier (aka anything before v4.x) are well past their LTS lifecycle, so I have no objection to relying on newer runtimes.

@srh
Copy link
Contributor

srh commented Jun 10, 2017

A problem with this PR is that r.connect can take a string, and this breaks that behavior.

@marshall007
Copy link
Contributor

Yea we'll need to do something like:

if typeof hostOrCallback is 'function'
    callback = hostOrCallback
else if typeof hostOrCallback is 'string'
    host = hostOrCallback
else
    host = Object.assign {}, hostOrCallback

@tengla
Copy link
Author

tengla commented Jun 10, 2017

How about:

connect = varar 0, 2, () ->
    args = Array.prototype.slice.call arguments,0,2
    { host, callback } = ( (hostOrCallback,callback)->
        if typeof hostOrCallback == 'function'
            host: {}, callback: hostOrCallback
        else if typeof hostOrCallback == 'string'
            host: hostOrCallback, callback: callback
        else
            host: Object.assign({}, hostOrCallback), callback: callback
    ).apply(undefined, args)
    # connect Promise can happily mutate host
    # ....

@srh
Copy link
Contributor

srh commented Dec 22, 2017

Closing for #6575 which is just @marshall007's implementation.

@srh srh closed this Dec 22, 2017
@srh srh modified the milestones: 2.4, old-prs Dec 22, 2017
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.

4 participants