From 125dc9545a866fc3d9ef26bdc0dc3899228450f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Vachon?= Date: Tue, 31 Mar 2015 16:36:20 -0400 Subject: [PATCH] Introduces promise manager --- Gruntfile.js | 7 ++++--- app/app.js | 1 + app/components/utils/promise_manager.js | 26 +++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 app/components/utils/promise_manager.js diff --git a/Gruntfile.js b/Gruntfile.js index 7ca80f9..fa1b647 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -87,10 +87,11 @@ module.exports = function (grunt) { compress: { files: [{ '<%= project.build %>/js/adagios.min.js' : [ + '<%= project.app %>/app.js', '<%= project.app %>/app.js', '<%= project.app %>/components/config/config.js', + '<%= project.app %>/components/utils/promise_manager.js', '<%= project.app %>/components/live/live.js', - '<%= project.app %>/components/live/notifications.js', '<%= project.app %>/components/live/get_objects.js', '<%= project.app %>/components/ng-justgage/ng-justgage.js', '<%= project.app %>/components/filters/filters.js', @@ -135,8 +136,8 @@ module.exports = function (grunt) { { '<%= project.build %>/app.js': '<%= project.app %>/app.js', '<%= project.build %>/components/config/config.js': '<%= project.app %>/components/config/config.js', + '<%= project.build %>/components/utils/promise_manager.js': '<%= project.app %>/components/utils/promise_manager.js', '<%= project.build %>/components/live/live.js': '<%= project.app %>/components/live/live.js', - '<%= project.build %>/components/live/notifications.js': '<%= project.app %>/components/live/notifications.js', '<%= project.build %>/components/live/get_objects.js': '<%= project.app %>/components/live/get_objects.js', '<%= project.build %>/components/ng-justgage/ng-justgage.js': '<%= project.app %>/components/ng-justgage/ng-justgage.js', '<%= project.build %>/components/filters/filters.js': '<%= project.app %>/components/filters/filters.js', @@ -177,8 +178,8 @@ module.exports = function (grunt) { '<%= project.build %>/js/adagios.min.js' : [ '<%= project.build %>/app.js', '<%= project.build %>/components/config/config.js', + '<%= project.build %>/components/utils/promise_manager.js', '<%= project.build %>/components/live/live.js', - '<%= project.build %>/components/live/notifications.js', '<%= project.build %>/components/live/get_objects.js', '<%= project.build %>/components/ng-justgage/ng-justgage.js', '<%= project.build %>/components/filters/filters.js', diff --git a/app/app.js b/app/app.js index 819e913..c95cf4b 100644 --- a/app/app.js +++ b/app/app.js @@ -16,6 +16,7 @@ angular.element(document).ready(function () { angular.module('adagios', [ 'ngRoute', 'adagios.config', + 'adagios.utils.promiseManager', 'adagios.topbar', 'adagios.sidebar', 'adagios.host', diff --git a/app/components/utils/promise_manager.js b/app/components/utils/promise_manager.js new file mode 100644 index 0000000..519b19f --- /dev/null +++ b/app/components/utils/promise_manager.js @@ -0,0 +1,26 @@ +'use strict'; + +angular.module('adagios.utils.promiseManager', []) + + .value('ajaxPromises', []) + + .service('addAjaxPromise', ['ajaxPromises', function (ajaxPromises) { + return function (promise) { + ajaxPromises.push(promise); + }; + }]) + + .service('clearAjaxPromises', ['$interval', 'ajaxPromises', function (ajaxPromises) { + return function ($interval) { + angular.forEach(ajaxPromises, function (promise) { + $interval.cancel(promise); + }); + }; + }]) + + .service('clearAllPromises', ['ajaxPromises', 'clearAjaxPromises', + function (ajaxPromises, clearAjaxPromises) { + return function () { + clearAjaxPromises(); + }; + }]);