Skip to content

Commit

Permalink
Refactor duplicated function call
Browse files Browse the repository at this point in the history
  • Loading branch information
robertknight committed Dec 22, 2015
1 parent 3cbb3bc commit f86814a
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions h/static/scripts/directive/annotation.js
Expand Up @@ -349,7 +349,7 @@ function AnnotationController(
// log in.
saveNewHighlight();

updateViewModel($scope, time, domainModel, vm, permissions);
updateView(domainModel);

// If this annotation is not a highlight and if it's new (has just been
// created by the annotate button) or it has edits not yet saved to the
Expand All @@ -361,9 +361,13 @@ function AnnotationController(
}
}

function updateView(domainModel) {
updateViewModel($scope, time, domainModel, vm, permissions);
}

function onAnnotationUpdated(event, updatedDomainModel) {
if (updatedDomainModel.id === domainModel.id) {
updateViewModel($scope, time, updatedDomainModel, vm, permissions);
updateView(updatedDomainModel);
}
}

Expand Down Expand Up @@ -417,7 +421,7 @@ function AnnotationController(
domainModel.permissions = permissions.private();
domainModel.$create().then(function() {
$rootScope.$emit('annotationCreated', domainModel);
updateViewModel($scope, time, domainModel, vm, permissions);
updateView(domainModel);
});
} else {
// User isn't logged in, save to drafts.
Expand Down Expand Up @@ -617,7 +621,7 @@ function AnnotationController(
if (vm.action === 'create') {
$rootScope.$emit('annotationDeleted', domainModel);
} else {
updateViewModel($scope, time, domainModel, vm, permissions);
updateView(domainModel);
view();
}
};
Expand Down Expand Up @@ -649,7 +653,7 @@ function AnnotationController(

var onFulfilled = function() {
$rootScope.$emit('annotationCreated', domainModel);
updateViewModel($scope, time, domainModel, vm, permissions);
updateView(domainModel);
view();
drafts.remove(domainModel);
};
Expand Down

0 comments on commit f86814a

Please sign in to comment.