Skip to content
This repository was archived by the owner on Jun 14, 2019. It is now read-only.

Commit 43a9d2a

Browse files
committed
release 0.6
1 parent 05af5ca commit 43a9d2a

File tree

5 files changed

+223
-59
lines changed

5 files changed

+223
-59
lines changed

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
<a name="v0.6.0"></a>
2+
## v0.6.0 (2014-05-19)
3+
4+
5+
#### Bug Fixes
6+
7+
* **vertxEventBusProvider:**
8+
* avoid default options object mutations ([031871cf](http://github.com/knalli/angular-vertxbus/commit/031871cf345cdfc375b5a81c41a2ab1142fb5642))
9+
* make config functions chainable ([7b02eab6](http://github.com/knalli/angular-vertxbus/commit/7b02eab6124bd5fb5e4b0cd2fe433b1af787ff74))
10+
* **vertxEventBusService:**
11+
* on registerHandler, return function to unregister this handler ([1f1b6bd7](http://github.com/knalli/angular-vertxbus/commit/1f1b6bd7394ad1a4716db8fc3703a5e9c337b2c2))
12+
* on unregistering a handler, the callback was called accidently itself ([2dfcd112](http://github.com/knalli/angular-vertxbus/commit/2dfcd1128d250b587496f6fb33d5419cd9b69e29))
13+
14+
15+
#### Features
16+
17+
* **vertxEventBusService:** add opt-in feature buffering messages ([de0e1345](http://github.com/knalli/angular-vertxbus/commit/de0e1345687fa21a94cc40e7b2fef783b312a4b2))
18+
119
<a name="v0.5.0"></a>
220
## v0.5.0 (2014-03-17)
321

dist/angular-vertxbus-0.5.0.min.js

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 102 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! angular-vertxbus - v0.5.0 - 2014-03-17
1+
/*! angular-vertxbus - v0.6.0 - 2014-05-19
22
* http://github.com/knalli/angular-vertxbus
33
* Copyright (c) 2014 ; Licensed */
44
(function () {
@@ -12,7 +12,8 @@
1212
reconnectEnabled: true,
1313
sockjsStateInterval: 10000,
1414
sockjsReconnectInterval: 10000,
15-
sockjsOptions: {}
15+
sockjsOptions: {},
16+
messageBuffer: 0
1617
};
1718
/*
1819
An AngularJS wrapper for projects using the VertX Event Bus
@@ -29,7 +30,7 @@
2930
* sockjsReconnectInterval (default 10000 ms): defines the wait time for a reconnect after a disconnect has been recognized
3031
* sockjsOptions (default {}): optional SockJS options (new SockJS(url, undefined, options))
3132
*/
32-
module = angular.module('knalli.angular-vertxbus', ['ng']).constant('angularVertxbusOptions', DEFAULT_OPTIONS).provider('vertxEventBus', [
33+
module = angular.module('knalli.angular-vertxbus', ['ng']).constant('angularVertxbusOptions', angular.extend({}, DEFAULT_OPTIONS)).provider('vertxEventBus', [
3334
'angularVertxbusOptions',
3435
function (angularVertxbusOptions) {
3536
this.enable = function (value) {
@@ -51,42 +52,56 @@
5152
value = DEFAULT_OPTIONS.prefix;
5253
}
5354
angularVertxbusOptions.prefix = value;
55+
return this;
5456
};
5557
this.useUrlServer = function (value) {
5658
if (value == null) {
5759
value = DEFAULT_OPTIONS.urlServer;
5860
}
5961
angularVertxbusOptions.urlServer = value;
62+
return this;
6063
};
6164
this.useUrlPath = function (value) {
6265
if (value == null) {
6366
value = DEFAULT_OPTIONS.urlPath;
6467
}
6568
angularVertxbusOptions.urlPath = value;
69+
return this;
6670
};
6771
this.useReconnect = function (value) {
6872
if (value == null) {
6973
value = DEFAULT_OPTIONS.reconnectEnabled;
7074
}
7175
angularVertxbusOptions.reconnectEnabled = value;
76+
return this;
7277
};
7378
this.useSockJsStateInterval = function (value) {
7479
if (value == null) {
7580
value = DEFAULT_OPTIONS.sockjsStateInterval;
7681
}
7782
angularVertxbusOptions.sockjsStateInterval = value;
83+
return this;
7884
};
7985
this.useSockJsReconnectInterval = function (value) {
8086
if (value == null) {
8187
value = DEFAULT_OPTIONS.sockjsReconnectInterval;
8288
}
8389
angularVertxbusOptions.sockjsReconnectInterval = value;
90+
return this;
8491
};
8592
this.useSockJsOptions = function (value) {
8693
if (value == null) {
8794
value = DEFAULT_OPTIONS.sockjsOptions;
8895
}
8996
angularVertxbusOptions.sockjsOptions = value;
97+
return this;
98+
};
99+
this.useMessageBuffer = function (value) {
100+
if (value == null) {
101+
value = DEFAULT_OPTIONS.messageBuffer;
102+
}
103+
angularVertxbusOptions.messageBuffer = value;
104+
return this;
90105
};
91106
/*
92107
A stub representing the VertX Event Bus (core functionality)
@@ -160,7 +175,10 @@
160175
return eventBus.publish(address, message);
161176
},
162177
registerHandler: function (address, handler) {
163-
return eventBus.registerHandler(address, handler);
178+
eventBus.registerHandler(address, handler);
179+
return function () {
180+
stub.unregisterHandler(address, handler);
181+
};
164182
},
165183
unregisterHandler: function (address, handler) {
166184
return eventBus.unregisterHandler(address, handler);
@@ -207,12 +225,39 @@
207225
'vertxEventBus',
208226
'angularVertxbusOptions',
209227
function ($rootScope, $q, $interval, $timeout, vertxEventBus, angularVertxbusOptions) {
210-
var api, connectionState, debugEnabled, enabled, prefix, reconnectEnabled, sockjsOptions, sockjsReconnectInterval, sockjsStateInterval, urlPath, urlServer, util, wrapped, _ref, _ref1;
211-
_ref = angular.extend({}, DEFAULT_OPTIONS, angularVertxbusOptions), enabled = _ref.enabled, debugEnabled = _ref.debugEnabled, prefix = _ref.prefix, urlServer = _ref.urlServer, urlPath = _ref.urlPath, reconnectEnabled = _ref.reconnectEnabled, sockjsStateInterval = _ref.sockjsStateInterval, sockjsReconnectInterval = _ref.sockjsReconnectInterval, sockjsOptions = _ref.sockjsOptions;
228+
var MessageQueueHolder, api, connectionState, debugEnabled, enabled, ensureOpenConnection, messageBuffer, messageQueueHolder, prefix, reconnectEnabled, sockjsOptions, sockjsReconnectInterval, sockjsStateInterval, urlPath, urlServer, util, wrapped, _ref, _ref1;
229+
MessageQueueHolder = function () {
230+
function MessageQueueHolder(maxSize) {
231+
this.maxSize = maxSize != null ? maxSize : 10;
232+
this.items = [];
233+
}
234+
MessageQueueHolder.prototype.push = function (item) {
235+
this.items.push(item);
236+
return this.recalibrateBufferSize();
237+
};
238+
MessageQueueHolder.prototype.recalibrateBufferSize = function () {
239+
while (this.items.length > this.maxSize) {
240+
this.first();
241+
}
242+
return this;
243+
};
244+
MessageQueueHolder.prototype.last = function () {
245+
return this.items.pop();
246+
};
247+
MessageQueueHolder.prototype.first = function () {
248+
return this.items.shift(0);
249+
};
250+
MessageQueueHolder.prototype.size = function () {
251+
return this.items.length;
252+
};
253+
return MessageQueueHolder;
254+
}();
255+
_ref = angular.extend({}, DEFAULT_OPTIONS, angularVertxbusOptions), enabled = _ref.enabled, debugEnabled = _ref.debugEnabled, prefix = _ref.prefix, urlServer = _ref.urlServer, urlPath = _ref.urlPath, reconnectEnabled = _ref.reconnectEnabled, sockjsStateInterval = _ref.sockjsStateInterval, sockjsReconnectInterval = _ref.sockjsReconnectInterval, sockjsOptions = _ref.sockjsOptions, messageBuffer = _ref.messageBuffer;
212256
connectionState = vertxEventBus != null ? (_ref1 = vertxEventBus.EventBus) != null ? _ref1.CLOSED : void 0 : void 0;
257+
messageQueueHolder = new MessageQueueHolder(messageBuffer);
213258
if (enabled && vertxEventBus) {
214259
vertxEventBus.onopen = function () {
215-
var address, callback, callbacks, _i, _len, _ref2;
260+
var address, callback, callbacks, fn, _i, _len, _ref2;
216261
wrapped.getConnectionState(true);
217262
$rootScope.$broadcast('' + prefix + 'system.connected');
218263
_ref2 = wrapped.handlers;
@@ -225,13 +270,32 @@
225270
util.registerHandler(address, callback);
226271
}
227272
}
228-
return $rootScope.$digest();
273+
$rootScope.$digest();
274+
if (messageBuffer && messageQueueHolder.size()) {
275+
while (messageQueueHolder.size()) {
276+
fn = messageQueueHolder.first();
277+
if (typeof fn === 'function') {
278+
fn();
279+
}
280+
}
281+
$rootScope.$digest();
282+
}
229283
};
230284
vertxEventBus.onclose = function () {
231285
wrapped.getConnectionState(true);
232286
return $rootScope.$broadcast('' + prefix + 'system.disconnected');
233287
};
234288
}
289+
ensureOpenConnection = function (fn) {
290+
if (wrapped.getConnectionState() === vertxEventBus.EventBus.OPEN) {
291+
fn();
292+
return true;
293+
} else if (messageBuffer) {
294+
messageQueueHolder.push(fn);
295+
return true;
296+
}
297+
return false;
298+
};
235299
util = {
236300
registerHandler: function (address, callback) {
237301
if (typeof callback !== 'function') {
@@ -255,30 +319,39 @@
255319
return vertxEventBus.unregisterHandler(address, callback);
256320
},
257321
send: function (address, message, expectReply, timeout) {
258-
var deferred;
322+
var deferred, dispatched;
259323
if (timeout == null) {
260324
timeout = 10000;
261325
}
262326
if (expectReply) {
263327
deferred = $q.defer();
264328
}
265-
vertxEventBus.send(address, message, function (reply) {
329+
dispatched = ensureOpenConnection(function () {
330+
vertxEventBus.send(address, message, function (reply) {
331+
if (deferred) {
332+
deferred.resolve(reply);
333+
}
334+
if (typeof expectReply === 'function') {
335+
return expectReply(reply);
336+
}
337+
});
266338
if (deferred) {
267-
deferred.resolve(reply);
268-
}
269-
if (typeof expectReply === 'function') {
270-
return expectReply(reply);
339+
return $timeout(function () {
340+
return deferred.reject();
341+
}, timeout);
271342
}
272343
});
273-
if (deferred) {
274-
$timeout(function () {
275-
return deferred.reject();
276-
}, timeout);
344+
if (deferred && !dispatched) {
345+
deferred.reject();
277346
}
278347
return deferred != null ? deferred.promise : void 0;
279348
},
280349
publish: function (address, message) {
281-
return vertxEventBus.publish(address, message);
350+
var dispatched;
351+
dispatched = ensureOpenConnection(function () {
352+
return vertxEventBus.publish(address, message);
353+
});
354+
return dispatched;
282355
}
283356
};
284357
wrapped = {
@@ -289,12 +362,15 @@
289362
}
290363
wrapped.handlers[address].push(callback);
291364
if (connectionState === vertxEventBus.EventBus.OPEN) {
292-
return util.registerHandler(address, callback);
365+
util.registerHandler(address, callback);
293366
}
367+
return function () {
368+
wrapped.unregisterHandler(address, callback);
369+
};
294370
},
295371
unregisterHandler: function (address, callback) {
296372
var index;
297-
if (wrapped.handlers[address] && callback(wrapped.handlers[address])) {
373+
if (wrapped.handlers[address]) {
298374
index = wrapped.handlers[address].indexOf(callback);
299375
if (index > -1) {
300376
wrapped.handlers[address].splice(index, 1);
@@ -308,16 +384,10 @@
308384
if (timeout == null) {
309385
timeout = 10000;
310386
}
311-
if (connectionState === vertxEventBus.EventBus.OPEN) {
312-
return util.send(address, message, expectReply, timeout);
313-
} else {
314-
return $q.reject('unknown');
315-
}
387+
return util.send(address, message, expectReply, timeout);
316388
},
317389
publish: function (address, message) {
318-
if (connectionState === vertxEventBus.EventBus.OPEN) {
319-
return util.publish(address, message);
320-
}
390+
return util.publish(address, message);
321391
},
322392
getConnectionState: function (immediate) {
323393
if (vertxEventBus != null ? vertxEventBus.EventBus : void 0) {
@@ -348,6 +418,9 @@
348418
readyState: wrapped.getConnectionState,
349419
isEnabled: function () {
350420
return enabled;
421+
},
422+
getBufferCount: function () {
423+
return messageQueueHolder.size();
351424
}
352425
};
353426
return api;

0 commit comments

Comments
 (0)