Utilizing _lodash.debounce() has been a bit of a challenge for me. While I have managed to get it working, I can't help but feel that there might be a better way to implement it. The examples provided on the lodash website are quite basic and don't involve passing parameters. Here's the code snippet in question:
$scope.parsePid = _.debounce(function () {
$scope.$apply(function () {
var pid = $scope.option.sPidRange;
if (pid == null || pid === "") {
$scope.pidLower = null;
$scope.pidUpper = null;
}
else if (pid.indexOf("-") > 0) {
pid = pid.split("-");
$scope.pidLower = parseInt(pid[0]);
$scope.pidUpper = parseInt(pid[1]);
}
else {
$scope.pidLower = parseInt(pid);
$scope.pidUpper = null;
}
});
}, 1500);
The function $scope.parsePid
above is debounced. However, I'd like to find a way to pass the parameter rather than retrieving it from $scope.option.SPidRange
.
To call the function, I use:
$scope.$watch("option.sPidRange", function (pid) {
if (pid !== null) {
$scope.parsePid();
}
});
In this case, the value of pid should match $scope.parsePid
.
I've attempted to pass the pid value into the debounced function directly without success. Is there a way to pass parameters into the debounced function $scope.parsePid()
?