Skip to content
This repository was archived by the owner on Feb 2, 2025. It is now read-only.

Commit cbd2d43

Browse files
committed
Update angular-datatables.instances.js
1 parent 0eb8288 commit cbd2d43

File tree

1 file changed

+18
-26
lines changed

1 file changed

+18
-26
lines changed

src/angular-datatables.instances.js

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ angular.module('datatables.instances', [])
88
function dtInstances($q) {
99
var _instances = {};
1010
// Promise for fetching the last DT instance
11-
var _deferLastDTInstances = null;
11+
var _deferLastDTInstance = $q.defer();
1212
var _lastDTInstance = null;
1313
// Promise for fetching the list of DT instances
14-
var _deferDTInstances = null;
14+
var _deferDTInstances = $q.defer();
1515
var _dtInstances = null;
1616
return {
1717
register: register,
@@ -25,46 +25,38 @@ function dtInstances($q) {
2525
dtInstance.dataTable = result.dataTable;
2626

2727
_instances[dtInstance.id] = dtInstance;
28-
if (_deferLastDTInstances) {
29-
_deferLastDTInstances.resolve(dtInstance);
30-
}
31-
if (_deferDTInstances) {
32-
_deferDTInstances.resolve(_instances);
33-
}
28+
_lastDTInstance = dtInstance;
29+
30+
//previous promise
31+
_deferDTInstances.resolve(_instances);
32+
_deferLastDTInstance.resolve(_lastDTInstance);
33+
34+
//new promise
35+
_deferDTInstances = $q.defer();
36+
_deferLastDTInstance = $q.defer();
37+
38+
_deferDTInstances.resolve(_instances);
39+
_deferLastDTInstance.resolve(_lastDTInstance);
40+
3441
return dtInstance;
3542
}
3643

3744
function getLast() {
3845
var defer = $q.defer();
39-
if (!_lastDTInstance) {
40-
_deferLastDTInstances = $q.defer();
41-
_lastDTInstance = _deferLastDTInstances.promise;
42-
}
43-
_lastDTInstance.then(function(dtInstance) {
44-
defer.resolve(dtInstance);
45-
// Reset the promise
46-
_deferLastDTInstances = null;
47-
_lastDTInstance = null;
46+
_deferLastDTInstance.promise.then(function (lastInstance) {
47+
defer.resolve(lastInstance);
4848
});
4949
return defer.promise;
5050
}
5151

5252
function getList() {
5353
var defer = $q.defer();
54-
if (!_dtInstances) {
55-
_deferDTInstances = $q.defer();
56-
_dtInstances = _deferDTInstances.promise;
57-
}
58-
_dtInstances.then(function(instances) {
54+
_deferDTInstances.promise.then(function (instances) {
5955
defer.resolve(instances);
60-
// Reset the promise
61-
_deferDTInstances = null;
62-
_dtInstances = null;
6356
});
6457
return defer.promise;
6558
}
6659
}
67-
6860
function dtInstanceFactory() {
6961
var DTInstance = {
7062
reloadData: reloadData,

0 commit comments

Comments
 (0)