Currently, I am developing a client-side JavaScript SDK that simplifies requests to an external API.
However, there is one issue when using this SDK within Angular. Developers have to manually add $scope.apply() in order to update the DOM correctly.
SDK.getUser(function(response) {
// This extra step of calling $scope.$apply due to SDK's asynchronous nature can be cumbersome
$scope.$apply(function() {
$rootScope.user = response.user;
});
}, function(error) {
console.log('Error Fetching User From SDK: ', error);
});
I am exploring ways to improve this situation. Is it possible to modify the SDK so that developers do not need to write $scope.apply() after each async call?
Could passing the $scope into the SDK and handling the apply internally be a feasible solution?