Commit ae3ec0c9 authored by Robert Knight's avatar Robert Knight

Remove digest triggering in AnnotationUISync

This is no longer needed following the addition of middleware to the
Redux store which triggers a digest following a UI state change if
necessary.

Also add a comment in the WebSocket code that we will be able to remove
the $apply() call once session state has been moved to the Redux store.
parent b42d717b
...@@ -58,20 +58,10 @@ function AnnotationUISync($rootScope, $window, annotationUI, bridge) { ...@@ -58,20 +58,10 @@ function AnnotationUISync($rootScope, $window, annotationUI, bridge) {
} }
}; };
// Because the channel events are all outside of the angular framework we
// need to inform Angular that it needs to re-check it's state and re-draw
// any UI that may have been affected by the handlers.
var ensureDigest = function (fn) {
return function () {
fn.apply(this, arguments);
$rootScope.$digest();
};
};
for (var channel in channelListeners) { for (var channel in channelListeners) {
if (Object.prototype.hasOwnProperty.call(channelListeners, channel)) { if (Object.prototype.hasOwnProperty.call(channelListeners, channel)) {
var listener = channelListeners[channel]; var listener = channelListeners[channel];
bridge.on(channel, ensureDigest(listener)); bridge.on(channel, listener);
} }
} }
......
...@@ -128,9 +128,12 @@ function connect($rootScope, annotationMapper, groups, session, settings) { ...@@ -128,9 +128,12 @@ function connect($rootScope, annotationMapper, groups, session, settings) {
}); });
socket.on('message', function (event) { socket.on('message', function (event) {
// wrap message dispatches in $rootScope.$apply() so that // Wrap message dispatches in $rootScope.$apply() so that
// scope watches on app state affected by the received message // scope watches on app state affected by the received message
// are updated // are updated
//
// Note: The use of $apply() here will no longer be needed once session
// state is moved to the Redux store in `annotationUI`.
$rootScope.$apply(function () { $rootScope.$apply(function () {
var message = JSON.parse(event.data); var message = JSON.parse(event.data);
if (!message) { if (!message) {
......
...@@ -6,7 +6,6 @@ var annotationUIFactory = require('../annotation-ui'); ...@@ -6,7 +6,6 @@ var annotationUIFactory = require('../annotation-ui');
describe('AnnotationUISync', function () { describe('AnnotationUISync', function () {
var sandbox = sinon.sandbox.create(); var sandbox = sinon.sandbox.create();
var $digest;
var publish; var publish;
var fakeBridge; var fakeBridge;
var annotationUI; var annotationUI;
...@@ -23,7 +22,6 @@ describe('AnnotationUISync', function () { ...@@ -23,7 +22,6 @@ describe('AnnotationUISync', function () {
beforeEach(angular.mock.module('h')); beforeEach(angular.mock.module('h'));
beforeEach(angular.mock.inject(function (AnnotationUISync, $rootScope) { beforeEach(angular.mock.inject(function (AnnotationUISync, $rootScope) {
$digest = sandbox.stub($rootScope, '$digest');
var listeners = {}; var listeners = {};
publish = function (method) { publish = function (method) {
var args = [].slice.apply(arguments); var args = [].slice.apply(arguments);
...@@ -96,12 +94,6 @@ describe('AnnotationUISync', function () { ...@@ -96,12 +94,6 @@ describe('AnnotationUISync', function () {
publish('showAnnotations', ['tag1', 'tag-for-a-new-annotation']); publish('showAnnotations', ['tag1', 'tag-for-a-new-annotation']);
assert.calledWith(annotationUI.selectAnnotations, ['id1']); assert.calledWith(annotationUI.selectAnnotations, ['id1']);
}); });
it('triggers a digest', function () {
createAnnotationUISync();
publish('showAnnotations', ['tag1', 'tag2', 'tag3']);
assert.called($digest);
});
}); });
describe('on "focusAnnotations" event', function () { describe('on "focusAnnotations" event', function () {
...@@ -114,12 +106,6 @@ describe('AnnotationUISync', function () { ...@@ -114,12 +106,6 @@ describe('AnnotationUISync', function () {
tag3: true, tag3: true,
}); });
}); });
it('triggers a digest', function () {
createAnnotationUISync();
publish('focusAnnotations', ['tag1', 'tag2', 'tag3']);
assert.called($digest);
});
}); });
describe('on "toggleAnnotationSelection" event', function () { describe('on "toggleAnnotationSelection" event', function () {
...@@ -129,12 +115,6 @@ describe('AnnotationUISync', function () { ...@@ -129,12 +115,6 @@ describe('AnnotationUISync', function () {
publish('toggleAnnotationSelection', ['tag1', 'tag2', 'tag3']); publish('toggleAnnotationSelection', ['tag1', 'tag2', 'tag3']);
assert.calledWith(annotationUI.toggleSelectedAnnotations, ['id1', 'id2', 'id3']); assert.calledWith(annotationUI.toggleSelectedAnnotations, ['id1', 'id2', 'id3']);
}); });
it('triggers a digest', function () {
createAnnotationUISync();
publish('toggleAnnotationSelection', ['tag1', 'tag2', 'tag3']);
assert.called($digest);
});
}); });
describe('on "setVisibleHighlights" event', function () { describe('on "setVisibleHighlights" event', function () {
...@@ -149,11 +129,5 @@ describe('AnnotationUISync', function () { ...@@ -149,11 +129,5 @@ describe('AnnotationUISync', function () {
publish('setVisibleHighlights', true); publish('setVisibleHighlights', true);
assert.calledWith(fakeBridge.call, 'setVisibleHighlights', true); assert.calledWith(fakeBridge.call, 'setVisibleHighlights', true);
}); });
it('triggers a digest of the application state', function () {
createAnnotationUISync();
publish('setVisibleHighlights', true);
assert.called($digest);
});
}); });
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment