[Groonga-commit] droonga/express-droonga at b63af12 [master] Don't register handler if the command is not defined

Back to archive index

YUKI Hiroshi null+****@clear*****
Thu Oct 17 16:21:51 JST 2013


YUKI Hiroshi	2013-10-17 16:21:51 +0900 (Thu, 17 Oct 2013)

  New Revision: b63af12ca26af0fdf81a06ac4ac53db955bf20e4
  https://github.com/droonga/express-droonga/commit/b63af12ca26af0fdf81a06ac4ac53db955bf20e4

  Message:
    Don't register handler if the command is not defined

  Modified files:
    lib/adapter/socket.io.js

  Modified: lib/adapter/socket.io.js (+23 -19)
===================================================================
--- lib/adapter/socket.io.js    2013-10-17 16:15:48 +0900 (518d82d)
+++ lib/adapter/socket.io.js    2013-10-17 16:21:51 +0900 (130b8c6)
@@ -35,6 +35,9 @@ exports.register = function(application, server, params) {
 
   function createClientMessageHandler(commandName, socket, onResponseCallback) {
     var commandDefinition = unifiedCommandSet[commandName];
+    if (!commandDefinition)
+      return;
+
     var defaultParameters = {};
 
     var droongaMessageOptions = {
@@ -60,9 +63,6 @@ exports.register = function(application, server, params) {
     }
 
     return (function(data, clientOptions) {
-      if (!commandDefinition)
-        return;
-
       clientOptions = clientOptions || {};
 
       if (command.PublishSubscribe.isInstance(commandDefinition))  {
@@ -175,20 +175,23 @@ exports.register = function(application, server, params) {
         var notificationEvent = registeredCommand.name + '.notification';
         var notificationHandler = createNotificationHandler(notificationEvent, socket);
 
-        socket.on(subscribeEvent,
-                  createClientMessageHandler(subscribeEvent, socket, function() {
-                    if (handlers[notificationEvent])
-                      return;
-                    connection.on(notificationEvent, notificationHandler);
-                    handlers[notificationEvent] = notificationHandler;
-                  }));
-        socket.on(unsubscribeEvent,
-                  createClientMessageHandler(unsubscribeEvent, socket, function() {
-                    if (!handlers[notificationEvent])
-                      return;
-                    connection.removeListener(notificationEvent, notificationHandler);
-                    delete handlers[notificationEvent];
-                  }));
+        var subscriveHandler = createClientMessageHandler(subscribeEvent, socket, function() {
+          if (handlers[notificationEvent])
+            return;
+          connection.on(notificationEvent, notificationHandler);
+          handlers[notificationEvent] = notificationHandler;
+        });
+        if (subscriveHandler)
+          socket.on(subscribeEvent, subscriveHandler);
+
+        var unsubscribeHandler = createClientMessageHandler(unsubscribeEvent, socket, function() {
+          if (!handlers[notificationEvent])
+            return;
+          connection.removeListener(notificationEvent, notificationHandler);
+          delete handlers[notificationEvent];
+        });
+        if (unsubscribeHandler)
+          socket.on(unsubscribeEvent, unsubscribeHandler);
 
         unifiedCommandSet[subscribeEvent] = registeredCommand.definition;
         unifiedCommandSet[unsubscribeEvent] = registeredCommand.definition;
@@ -196,8 +199,9 @@ exports.register = function(application, server, params) {
 
         events.push(notificationEvent);
       } else {
-        socket.on(registeredCommand.name,
-                  createClientMessageHandler(registeredCommand.name, socket));
+        var handler = createClientMessageHandler(registeredCommand.name, socket);
+        if (handler)
+          socket.on(registeredCommand.name, handler);
       }
     });
 
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index