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

Commit 783aecd

Browse files
committed
Merge branch 'miguelqvd-master' into dev
Conflicts: dist/angular-datatables.min.js
2 parents d76137c + 386d269 commit 783aecd

File tree

2 files changed

+36
-52
lines changed

2 files changed

+36
-52
lines changed

dist/angular-datatables.js

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -411,11 +411,10 @@ angular.module('datatables.instances', [])
411411
function dtInstances($q) {
412412
var _instances = {};
413413
// Promise for fetching the last DT instance
414-
var _deferLastDTInstances = null;
414+
var _deferLastDTInstance = $q.defer();
415415
var _lastDTInstance = null;
416416
// Promise for fetching the list of DT instances
417-
var _deferDTInstances = null;
418-
var _dtInstances = null;
417+
var _deferDTInstances = $q.defer();
419418
return {
420419
register: register,
421420
getLast: getLast,
@@ -428,41 +427,34 @@ function dtInstances($q) {
428427
dtInstance.dataTable = result.dataTable;
429428

430429
_instances[dtInstance.id] = dtInstance;
431-
if (_deferLastDTInstances) {
432-
_deferLastDTInstances.resolve(dtInstance);
433-
}
434-
if (_deferDTInstances) {
435-
_deferDTInstances.resolve(_instances);
436-
}
430+
_lastDTInstance = dtInstance;
431+
432+
//previous promise
433+
_deferDTInstances.resolve(_instances);
434+
_deferLastDTInstance.resolve(_lastDTInstance);
435+
436+
//new promise
437+
_deferDTInstances = $q.defer();
438+
_deferLastDTInstance = $q.defer();
439+
440+
_deferDTInstances.resolve(_instances);
441+
_deferLastDTInstance.resolve(_lastDTInstance);
442+
437443
return dtInstance;
438444
}
439445

440446
function getLast() {
441447
var defer = $q.defer();
442-
if (!_lastDTInstance) {
443-
_deferLastDTInstances = $q.defer();
444-
_lastDTInstance = _deferLastDTInstances.promise;
445-
}
446-
_lastDTInstance.then(function(dtInstance) {
447-
defer.resolve(dtInstance);
448-
// Reset the promise
449-
_deferLastDTInstances = null;
450-
_lastDTInstance = null;
448+
_deferLastDTInstance.promise.then(function(lastInstance) {
449+
defer.resolve(lastInstance);
451450
});
452451
return defer.promise;
453452
}
454453

455454
function getList() {
456455
var defer = $q.defer();
457-
if (!_dtInstances) {
458-
_deferDTInstances = $q.defer();
459-
_dtInstances = _deferDTInstances.promise;
460-
}
461-
_dtInstances.then(function(instances) {
456+
_deferDTInstances.promise.then(function(instances) {
462457
defer.resolve(instances);
463-
// Reset the promise
464-
_deferDTInstances = null;
465-
_dtInstances = null;
466458
});
467459
return defer.promise;
468460
}

src/angular-datatables.instances.js

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +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;
15-
var _dtInstances = null;
14+
var _deferDTInstances = $q.defer();
1615
return {
1716
register: register,
1817
getLast: getLast,
@@ -25,41 +24,34 @@ function dtInstances($q) {
2524
dtInstance.dataTable = result.dataTable;
2625

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

3743
function getLast() {
3844
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;
45+
_deferLastDTInstance.promise.then(function(lastInstance) {
46+
defer.resolve(lastInstance);
4847
});
4948
return defer.promise;
5049
}
5150

5251
function getList() {
5352
var defer = $q.defer();
54-
if (!_dtInstances) {
55-
_deferDTInstances = $q.defer();
56-
_dtInstances = _deferDTInstances.promise;
57-
}
58-
_dtInstances.then(function(instances) {
53+
_deferDTInstances.promise.then(function(instances) {
5954
defer.resolve(instances);
60-
// Reset the promise
61-
_deferDTInstances = null;
62-
_dtInstances = null;
6355
});
6456
return defer.promise;
6557
}

0 commit comments

Comments
 (0)