From 3966e2f85bcfd3fcbf742d331af55eb3c2a9b939 Mon Sep 17 00:00:00 2001 From: Alasdair Smith Date: Thu, 21 Sep 2017 16:55:49 +0100 Subject: [PATCH] Make variadic options more explicit --- services/real-time/app/coffee/Router.coffee | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/services/real-time/app/coffee/Router.coffee b/services/real-time/app/coffee/Router.coffee index a55147bfb2..b3d6ffeb16 100644 --- a/services/real-time/app/coffee/Router.coffee +++ b/services/real-time/app/coffee/Router.coffee @@ -85,17 +85,22 @@ module.exports = Router = # doc_id, options, callback # doc_id, fromVersion, options, callback client.on "joinDoc", (doc_id, fromVersion, options, callback) -> - if typeof fromVersion == "function" - fromVersion = -1 - options = {} + if typeof fromVersion == "function" and !options callback = fromVersion - else if typeof fromVersion == "object" fromVersion = -1 - options = fromVersion - callback = options - if typeof options == "function" options = {} + else if typeof fromVersion == "number" and typeof options == "function" 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...) -> if err?