Make variadic options more explicit

This commit is contained in:
Alasdair Smith 2017-09-21 16:55:49 +01:00
parent 790b9ea8ed
commit 3966e2f85b

View file

@ -85,17 +85,22 @@ module.exports = Router =
# doc_id, options, callback # doc_id, options, callback
# doc_id, fromVersion, options, callback # doc_id, fromVersion, options, callback
client.on "joinDoc", (doc_id, fromVersion, options, callback) -> client.on "joinDoc", (doc_id, fromVersion, options, callback) ->
if typeof fromVersion == "function" if typeof fromVersion == "function" and !options
fromVersion = -1
options = {}
callback = fromVersion callback = fromVersion
else if typeof fromVersion == "object"
fromVersion = -1 fromVersion = -1
options = fromVersion
callback = options
if typeof options == "function"
options = {} options = {}
else if typeof fromVersion == "number" and typeof options == "function"
callback = options callback = options
options = {}
else if typeof fromVersion == "object" and typeof options == "function"
callback = options
options = fromVersion
fromVersion = -1
else if typeof fromVersion == "number" and typeof options == "object"
# Called with 4 args, things are as expected
else
logger.error { arguments: arguments }, "unexpected arguments"
return {} # ????
WebsocketController.joinDoc client, doc_id, options, fromVersion, (err, args...) -> WebsocketController.joinDoc client, doc_id, options, fromVersion, (err, args...) ->
if err? if err?