|
1 |
| -/*! angular-vertxbus - v0.7.1 - 2014-09-19 |
| 1 | +/*! angular-vertxbus - v0.8.0 - 2014-10-16 |
2 | 2 | * http://github.com/knalli/angular-vertxbus
|
3 | 3 | * Copyright (c) 2014 ; Licensed */
|
4 | 4 | (function () {
|
|
219 | 219 | Note the additional configuration of the module itself.
|
220 | 220 | */
|
221 | 221 | angular.module('knalli.angular-vertxbus').provider('vertxEventBusService', function () {
|
222 |
| - var DEFAULT_OPTIONS, MessageQueueHolder, options; |
| 222 | + var DEFAULT_OPTIONS, MessageQueueHolder, SimpleMap, options; |
223 | 223 | DEFAULT_OPTIONS = {
|
224 | 224 | loginRequired: false,
|
225 | 225 | loginBlockForSession: false,
|
|
251 | 251 | };
|
252 | 252 | return MessageQueueHolder;
|
253 | 253 | }();
|
| 254 | + SimpleMap = function () { |
| 255 | + SimpleMap.prototype.keys = null; |
| 256 | + SimpleMap.prototype.values = null; |
| 257 | + function SimpleMap() { |
| 258 | + this.keys = []; |
| 259 | + this.values = []; |
| 260 | + } |
| 261 | + SimpleMap.prototype.put = function (key, value) { |
| 262 | + var idx; |
| 263 | + idx = this._indexForKey(key); |
| 264 | + if (idx > -1) { |
| 265 | + this.values[idx] = value; |
| 266 | + } else { |
| 267 | + this.keys.push(key); |
| 268 | + this.values.push(value); |
| 269 | + } |
| 270 | + return this; |
| 271 | + }; |
| 272 | + SimpleMap.prototype._indexForKey = function (key) { |
| 273 | + var i, k, _i, _len, _ref; |
| 274 | + _ref = this.keys; |
| 275 | + for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) { |
| 276 | + k = _ref[i]; |
| 277 | + if (key === k) { |
| 278 | + return i; |
| 279 | + } |
| 280 | + } |
| 281 | + return -1; |
| 282 | + }; |
| 283 | + SimpleMap.prototype._indexForValue = function (value) { |
| 284 | + var i, v, _i, _len, _ref; |
| 285 | + _ref = this.values; |
| 286 | + for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) { |
| 287 | + v = _ref[i]; |
| 288 | + if (value === v) { |
| 289 | + return i; |
| 290 | + } |
| 291 | + } |
| 292 | + return -1; |
| 293 | + }; |
| 294 | + SimpleMap.prototype.containsKey = function (key) { |
| 295 | + var idx; |
| 296 | + idx = this._indexForKey(key); |
| 297 | + return idx > -1; |
| 298 | + }; |
| 299 | + SimpleMap.prototype.containsValue = function (value) { |
| 300 | + var idx; |
| 301 | + idx = this._indexForValue(value); |
| 302 | + return idx > -1; |
| 303 | + }; |
| 304 | + SimpleMap.prototype.get = function (key) { |
| 305 | + var idx; |
| 306 | + idx = this._indexForKey(key); |
| 307 | + if (idx > -1) { |
| 308 | + return this.values[idx]; |
| 309 | + } |
| 310 | + return void 0; |
| 311 | + }; |
| 312 | + SimpleMap.prototype.remove = function (key) { |
| 313 | + var idx; |
| 314 | + idx = this._indexForKey(key); |
| 315 | + if (idx > -1) { |
| 316 | + this.keys[idx] = void 0; |
| 317 | + this.values[idx] = void 0; |
| 318 | + } |
| 319 | + return void 0; |
| 320 | + }; |
| 321 | + SimpleMap.prototype.clear = function () { |
| 322 | + this.keys = []; |
| 323 | + this.values = []; |
| 324 | + return this; |
| 325 | + }; |
| 326 | + return SimpleMap; |
| 327 | + }(); |
254 | 328 | options = angular.extend({}, DEFAULT_OPTIONS);
|
255 | 329 | this.requireLogin = function (value) {
|
256 | 330 | if (value == null) {
|
|
286 | 360 | validSession = false;
|
287 | 361 | loginPromise = null;
|
288 | 362 | messageQueueHolder = new MessageQueueHolder(messageBuffer);
|
289 |
| - fnWrapperMap = {}; |
| 363 | + fnWrapperMap = new SimpleMap(); |
290 | 364 | if (enabled && vertxEventBus) {
|
291 | 365 | vertxEventBus.onopen = function () {
|
292 | 366 | var address, callback, callbacks, fn, _i, _len, _ref2;
|
|
353 | 427 | if (debugEnabled) {
|
354 | 428 | console.debug('[VertX EB Service] Register handler for ' + address);
|
355 | 429 | }
|
356 |
| - if (fnWrapperMap[callback]) { |
357 |
| - return fnWrapperMap[callback]; |
| 430 | + if (fnWrapperMap.containsKey(callback)) { |
| 431 | + return fnWrapperMap.get(callback); |
358 | 432 | }
|
359 |
| - fnWrapperMap[callback] = function (message, replyTo) { |
| 433 | + fnWrapperMap.put(callback, function (message, replyTo) { |
360 | 434 | callback(message, replyTo);
|
361 | 435 | return $rootScope.$digest();
|
362 |
| - }; |
363 |
| - return vertxEventBus.registerHandler(address, fnWrapperMap[callback]); |
| 436 | + }); |
| 437 | + return vertxEventBus.registerHandler(address, fnWrapperMap.get(callback)); |
364 | 438 | },
|
365 | 439 | unregisterHandler: function (address, callback) {
|
366 | 440 | if (typeof callback !== 'function') {
|
|
369 | 443 | if (debugEnabled) {
|
370 | 444 | console.debug('[VertX EB Service] Unregister handler for ' + address);
|
371 | 445 | }
|
372 |
| - vertxEventBus.unregisterHandler(address, fnWrapperMap[callback]); |
373 |
| - fnWrapperMap[callback] = void 0; |
| 446 | + vertxEventBus.unregisterHandler(address, fnWrapperMap.get(callback)); |
| 447 | + fnWrapperMap.remove(callback); |
374 | 448 | },
|
375 | 449 | send: function (address, message, timeout) {
|
376 | 450 | var deferred, dispatched;
|
|
0 commit comments