##// END OF EJS Templates
Use ternary operator for callback registration
Jonathan Frederic -
Show More
@@ -50,10 +50,7 b' class EventfulDict(dict):'
50 The callback should have a signature of callback(key, value). The
50 The callback should have a signature of callback(key, value). The
51 callback should return a boolean True if the additon should be
51 callback should return a boolean True if the additon should be
52 canceled, False or None otherwise."""
52 canceled, False or None otherwise."""
53 if callable(callback):
53 self._add_callback = callback if callable(callback) else _void
54 self._add_callback = callback
55 else:
56 self._add_callback = _void
57
54
58 def on_del(self, callback):
55 def on_del(self, callback):
59 """Register a callback for when an item is deleted from the dict.
56 """Register a callback for when an item is deleted from the dict.
@@ -66,11 +63,8 b' class EventfulDict(dict):'
66 The callback should have a signature of callback(key). The
63 The callback should have a signature of callback(key). The
67 callback should return a boolean True if the deletion should be
64 callback should return a boolean True if the deletion should be
68 canceled, False or None otherwise."""
65 canceled, False or None otherwise."""
69 if callable(callback):
66 self._del_callback = callback if callable(callback) else _void
70 self._del_callback = callback
67
71 else:
72 self._del_callback = _void
73
74 def on_set(self, callback):
68 def on_set(self, callback):
75 """Register a callback for when an item is changed in the dict.
69 """Register a callback for when an item is changed in the dict.
76
70
@@ -82,11 +76,8 b' class EventfulDict(dict):'
82 The callback should have a signature of callback(key, value). The
76 The callback should have a signature of callback(key, value). The
83 callback should return a boolean True if the change should be
77 callback should return a boolean True if the change should be
84 canceled, False or None otherwise."""
78 canceled, False or None otherwise."""
85 if callable(callback):
79 self._set_callback = callback if callable(callback) else _void
86 self._set_callback = callback
80
87 else:
88 self._set_callback = _void
89
90 def pop(self, key):
81 def pop(self, key):
91 """Returns the value of an item in the dictionary and then deletes the
82 """Returns the value of an item in the dictionary and then deletes the
92 item from the dictionary."""
83 item from the dictionary."""
@@ -182,11 +173,8 b' class EventfulList(list):'
182 The callback should have a signature of callback(index, value). The
173 The callback should have a signature of callback(index, value). The
183 callback should return a boolean True if the insertion should be
174 callback should return a boolean True if the insertion should be
184 canceled, False or None otherwise."""
175 canceled, False or None otherwise."""
185 if callable(callback):
176 self._insert_callback = callback if callable(callback) else _void
186 self._insert_callback = callback
177
187 else:
188 self._insert_callback = _void
189
190 def on_del(self, callback):
178 def on_del(self, callback):
191 """Register a callback for item deletion.
179 """Register a callback for item deletion.
192
180
@@ -198,10 +186,7 b' class EventfulList(list):'
198 The callback should have a signature of callback(index). The
186 The callback should have a signature of callback(index). The
199 callback should return a boolean True if the deletion should be
187 callback should return a boolean True if the deletion should be
200 canceled, False or None otherwise."""
188 canceled, False or None otherwise."""
201 if callable(callback):
189 self._del_callback = callback if callable(callback) else _void
202 self._del_callback = callback
203 else:
204 self._del_callback = _void
205
190
206 def on_set(self, callback):
191 def on_set(self, callback):
207 """Register a callback for items are set.
192 """Register a callback for items are set.
@@ -215,10 +200,7 b' class EventfulList(list):'
215 The callback should have a signature of callback(index, value). The
200 The callback should have a signature of callback(index, value). The
216 callback should return a boolean True if the set should be
201 callback should return a boolean True if the set should be
217 canceled, False or None otherwise."""
202 canceled, False or None otherwise."""
218 if callable(callback):
203 self._set_callback = callback if callable(callback) else _void
219 self._set_callback = callback
220 else:
221 self._set_callback = _void
222
204
223 def on_reverse(self, callback):
205 def on_reverse(self, callback):
224 """Register a callback for list reversal.
206 """Register a callback for list reversal.
@@ -228,10 +210,7 b' class EventfulList(list):'
228 The callback should have a signature of callback(). The
210 The callback should have a signature of callback(). The
229 callback should return a boolean True if the reverse should be
211 callback should return a boolean True if the reverse should be
230 canceled, False or None otherwise."""
212 canceled, False or None otherwise."""
231 if callable(callback):
213 self._reverse_callback = callback if callable(callback) else _void
232 self._reverse_callback = callback
233 else:
234 self._reverse_callback = _void
235
214
236 def on_sort(self, callback):
215 def on_sort(self, callback):
237 """Register a callback for sortting of the list.
216 """Register a callback for sortting of the list.
@@ -242,10 +221,7 b' class EventfulList(list):'
242 method or `callback(*pargs, **kwargs)` as a catch all. The callback
221 method or `callback(*pargs, **kwargs)` as a catch all. The callback
243 should return a boolean True if the reverse should be canceled,
222 should return a boolean True if the reverse should be canceled,
244 False or None otherwise."""
223 False or None otherwise."""
245 if callable(callback):
224 self._sort_callback = callback if callable(callback) else _void
246 self._sort_callback = callback
247 else:
248 self._sort_callback = _void
249
225
250 def append(self, x):
226 def append(self, x):
251 """Add an item to the end of the list."""
227 """Add an item to the end of the list."""
General Comments 0
You need to be logged in to leave comments. Login now