Commits

Boris FELD committed ad6c914

Add verification for callback and rename the file.

  • Participants
  • Parent commits a8b12d4

Comments (0)

Files changed (3)

 syntax: glob
 .DS_Store
+*.pyc

lib/core/EventDispacther.py

-class EventDispatcher:
-
-    self.events = {}
-
-    def attach(self, name, callback):
-        if not name in self.events.keys():
-            return False
-        self.events[name].append(callback)
-        return True
-
-    def detach(self, name, callback):
-        if not callback in self.events[name]:
-            return False
-        self.events[name].remove(callback)
-        return True
-
-    def declare(self, name):
-        if name in self.keys():
-            return False
-        self.events[name] = []

lib/core/EventDispatcher.py

+class EventDispatcher:
+
+    def __init__(self):
+        self.events = {}
+
+    def attach(self, name, callback):
+        if not name in self.events.keys():
+            return False
+        if not callable(callback):
+            return False
+        self.events[name].append(callback)
+        return True
+
+    def detach(self, name, callback):
+        if not callback in self.events[name]:
+            return False
+        self.events[name].remove(callback)
+        return True
+
+    def call(self, name):
+        if not name in self.events.keys():
+            return False
+        for callback in self.events[name]:
+            callback()
+
+    def declare(self, name):
+        if name in self.events.keys():
+            return False
+        self.events[name] = []