|
127 | 127 | listeners[_listening.id] = _listening; |
128 | 128 | // Allow the listening to use a counter, instead of tracking |
129 | 129 | // callbacks for library interop |
130 | | - _listening.backbone = true; |
| 130 | + _listening.interop = false; |
131 | 131 | } |
132 | 132 |
|
133 | 133 | return this; |
|
154 | 154 |
|
155 | 155 | if (error) throw error; |
156 | 156 | // If the target obj is not Backbone.Events, track events manually. |
157 | | - if (!listening.backbone) listening.on(name, callback); |
| 157 | + if (listening.interop) listening.on(name, callback); |
158 | 158 |
|
159 | 159 | return this; |
160 | 160 | }; |
|
210 | 210 | if (!listening) break; |
211 | 211 |
|
212 | 212 | listening.obj.off(name, callback, this); |
213 | | - if (!listening.backbone) listening.off(name, callback); |
| 213 | + if (listening.interop) listening.off(name, callback); |
214 | 214 | } |
215 | 215 | return this; |
216 | 216 | }; |
|
343 | 343 | this.id = listener._listenId; |
344 | 344 | this.listener = listener; |
345 | 345 | this.obj = obj; |
346 | | - this.backbone = false; |
| 346 | + this.interop = true; |
347 | 347 | this.count = 0; |
348 | 348 | this._events = void 0; |
349 | 349 | }; |
|
356 | 356 | // library interop. |
357 | 357 | Listening.prototype.off = function(name, callback) { |
358 | 358 | var cleanup; |
359 | | - if (this.backbone) { |
360 | | - this.count--; |
361 | | - cleanup = this.count === 0; |
362 | | - } else { |
| 359 | + if (this.interop) { |
363 | 360 | this._events = eventsApi(offApi, this._events, name, callback, { |
364 | 361 | context: void 0, |
365 | 362 | listeners: void 0 |
366 | 363 | }); |
367 | 364 | cleanup = !this._events; |
| 365 | + } else { |
| 366 | + this.count--; |
| 367 | + cleanup = this.count === 0; |
368 | 368 | } |
369 | 369 | if (cleanup) this.cleanup(); |
370 | 370 | }; |
371 | 371 |
|
372 | 372 | // Cleans up memory bindings between the listener and the listenee. |
373 | 373 | Listening.prototype.cleanup = function() { |
374 | 374 | delete this.listener._listeningTo[this.obj._listenId]; |
375 | | - if (this.backbone) delete this.obj._listeners[this.id]; |
| 375 | + if (!this.interop) delete this.obj._listeners[this.id]; |
376 | 376 | }; |
377 | 377 |
|
378 | 378 | // Proxy Underscore methods to a Backbone class' prototype using a |
|
0 commit comments