Skip to content

Commit

Permalink
Merge pull request #4 from ef-ctx/unsubscribe_fix
Browse files Browse the repository at this point in the history
feat(session): unsubscribe returns a promise
  • Loading branch information
JaimeBeneytez committed Dec 8, 2015
2 parents abb4d45 + c8e702b commit 6015452
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 14 deletions.
25 changes: 21 additions & 4 deletions dist/ngAutobahn.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,12 +490,15 @@
***************************************************************/

function unsubscribeBroker(brokerFacade) {
var broker;

if (!brokerFacade) {
throw new Error('ngAutobahnSession.unsubscribeBroker error. No broker provided');
} else {
var broker = _getBrokerByBrokerFacade(brokerFacade);
_unsubscribeBroker(broker);
delete _brokers[broker.subscription.id];
broker = _getBrokerByBrokerFacade(brokerFacade);

return _unsubscribeBroker(broker)
.then(_deleteBroker);
}
}

Expand Down Expand Up @@ -588,8 +591,22 @@
* HELPERS
***************************************************************/

function _deleteBroker(broker) {
delete _brokers[broker.subscription.id];
}

function _unsubscribeBroker(broker) {
_session.unsubscribe(broker.subscription);
var defer = $q.defer();

_session.unsubscribe(broker.subscription)
.then(_resolveBroker, defer.reject);

return defer.promise;

function _resolveBroker() {
defer.resolve(broker);
}

}

function _unsubscribeAllBrokers() {
Expand Down
2 changes: 1 addition & 1 deletion dist/ngAutobahn.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 21 additions & 4 deletions src/lib/ngAutobahn/session/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,15 @@
***************************************************************/

function unsubscribeBroker(brokerFacade) {
var broker;

if (!brokerFacade) {
throw new Error('ngAutobahnSession.unsubscribeBroker error. No broker provided');
} else {
var broker = _getBrokerByBrokerFacade(brokerFacade);
_unsubscribeBroker(broker);
delete _brokers[broker.subscription.id];
broker = _getBrokerByBrokerFacade(brokerFacade);

return _unsubscribeBroker(broker)
.then(_deleteBroker);
}
}

Expand Down Expand Up @@ -203,8 +206,22 @@
* HELPERS
***************************************************************/

function _deleteBroker(broker) {
delete _brokers[broker.subscription.id];
}

function _unsubscribeBroker(broker) {
_session.unsubscribe(broker.subscription);
var defer = $q.defer();

_session.unsubscribe(broker.subscription)
.then(_resolveBroker, defer.reject);

return defer.promise;

function _resolveBroker() {
defer.resolve(broker);
}

}

function _unsubscribeAllBrokers() {
Expand Down
10 changes: 5 additions & 5 deletions src/lib/ngAutobahn/session/session.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ describe('ngAutobahnSession', function () {
defer.resolve();
return defer.promise;
},
unsubscribe: function () {}
unsubscribe: function () {
var defer = $q.defer();
defer.resolve();
return defer.promise;
}
}
},
handlers = {
Expand Down Expand Up @@ -371,10 +375,6 @@ describe('ngAutobahnSession', function () {
$timeout.flush();
}));

it('SHOULD be a function', function () {
expect(typeof _session.unsubscribeBroker).toBe('function');
});

describe('IF a broker is provided', function () {
it('SHOULD invoke autobahn.session.unsubscribe with the broker´s subscription', function () {
_session.unsubscribeBroker(_broker);
Expand Down

0 comments on commit 6015452

Please sign in to comment.