diff --git a/dist/angular-defensive.js b/dist/angular-defensive.js index e665849..53a683a 100644 --- a/dist/angular-defensive.js +++ b/dist/angular-defensive.js @@ -7,10 +7,15 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons })(this, function () { 'use strict'; + var HTTP = new WeakMap(); + var TEMPLATE_CACHE = new WeakMap(); + var DefensiveConfiguration = (function () { - function DefensiveConfiguration() { + function DefensiveConfiguration($http, $templateCache) { _classCallCheck(this, DefensiveConfiguration); + HTTP.set(this, $http); + TEMPLATE_CACHE.set(this, $templateCache); this.configurations = {}; } @@ -22,52 +27,49 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons return configuration; } }, { - key: '$get', - value: function $get($http, $templateCache) { - var configurations = this.configurations; - return { - getTemplate: function getTemplate(confCase) { - return new Promise(function (resolve) { - if (confCase.hasOwnProperty('template')) { - resolve(confCase.template); - } else if (confCase.hasOwnProperty('templateUrl')) { - $http.get(confCase.templateUrl, { - cache: $templateCache, - headers: { Accept: 'text/html' } - }).then(function (response) { - resolve(response.data); - }); - } + key: 'getTemplate', + value: function getTemplate(confCase) { + return new Promise(function (resolve) { + if (confCase.hasOwnProperty('template')) { + resolve(confCase.template); + } else if (confCase.hasOwnProperty('templateUrl')) { + HTTP.get(this).get(confCase.templateUrl, { + cache: TEMPLATE_CACHE.get(this), + headers: { Accept: 'text/html' } + }).then(function (response) { + resolve(response.data); }); - }, - getDefensiveCase: function getDefensiveCase(configurationName) { - var self = this; - return new Promise(function (resolve, reject) { - if (!configurations.hasOwnProperty(configurationName)) { - return reject('Configuration ' + configurationName + ' does not exist'); - } - var configuration = configurations[configurationName]; - - var _loop = function () { - var confCase = configuration.cases.shift(); - if (confCase.check()) { - return { - v: self.getTemplate(confCase).then(function (template) { - confCase.template = template; - return resolve(confCase); - }) - }; - } + } + }); + } + }, { + key: 'getDefensiveCase', + value: function getDefensiveCase(configurationName) { + var configurations = this.configurations; + return new Promise(function (resolve, reject) { + if (!configurations.hasOwnProperty(configurationName)) { + return reject('Configuration ' + configurationName + ' does not exist'); + } + var configuration = configurations[configurationName]; + + var _loop = function () { + var confCase = configuration.cases.shift(); + if (confCase.check()) { + return { + v: self.getTemplate(confCase).then(function (template) { + confCase.template = template; + return resolve(confCase); + }) }; + } + }; - while (configuration.cases.length) { - var _ret = _loop(); + while (configuration.cases.length) { + var _ret = _loop(); - if (typeof _ret === 'object') return _ret.v; - } - }); + if (typeof _ret === 'object') return _ret.v; } - }; + }); } }, { key: 'Configuration', @@ -76,8 +78,8 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons } }], [{ key: 'factory', - value: function factory() { - return new DefensiveConfiguration(); + value: function factory($http, $templateCache) { + return new DefensiveConfiguration($http, $templateCache); } }, { key: 'Configuration', @@ -107,7 +109,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons var moduleName$2 = 'ngDefensive.services'; - angular.module(moduleName$2, []).provider('DefensiveConfiguration', DefensiveConfiguration.factory); + angular.module(moduleName$2, []).factory('DefensiveConfiguration', DefensiveConfiguration.factory); var NgDefensive = (function () { function NgDefensive($compile, DefensiveConfiguration) { diff --git a/dist/angular-defensive.js.map b/dist/angular-defensive.js.map index f7c3d9f..fa9d6c5 100644 --- a/dist/angular-defensive.js.map +++ b/dist/angular-defensive.js.map @@ -1 +1 @@ -{"version":3,"sources":["angular-defensive.js"],"names":[],"mappings":";;;;AAAA,AAAC,CAAA,UAAU,MAAM,EAAE,OAAO,EAAE;AAC3B,QAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,MAAM,KAAK,WAAW,GAAG,MAAM,CAAC,OAAO,GAAG,OAAO,EAAE,GACzF,OAAO,MAAM,KAAK,UAAU,IAAI,MAAM,CAAC,GAAG,GAAG,MAAM,CAAC,OAAO,CAAC,GAC5D,MAAM,CAAC,gBAAgB,GAAG,OAAO,EAAE,CAAC;CACpC,CAAA,CAAC,IAAI,EAAE,YAAY;AAAE,aAAY,CAAC;;KAE5B,sBAAsB;AAEf,WAFP,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,KAAK,EAAE;AAC1C,QAAI,UAAU,GAAG,IAAI,CAAC;AACtB,0BAAsB,CAAC,gBAAgB,CAAC,KAAK,CAAC,WAAW,CAAC,CACzD,IAAI,CAAC,UAAS,QAAQ,EAAE;AACvB,YAAO,CAAC,WAAW,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;AACxD,eAAU,GAAG,QAAQ,CAAC;KACvB,CAAC,CAAC;AACH,SAAK,CAAC,MAAM,GAAG,YAAW;AACxB,UAAK,CAAC,SAAS,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;KACxC,CAAC;IACH,CAAC;GACH;;eAlBG,WAAW;;UAoBD,iBAAC,QAAQ,EAAE,sBAAsB,EAAE;AAC/C,WAAO,IAAI,WAAW,CAAC,QAAQ,EAAE,sBAAsB,CAAC,CAAC;IAC1D;;;SAtBG,WAAW;;;AA0BjB,KAAI,YAAY,GAAG,wBAAwB,CAAC;;AAE5C,QAAO,CAAC,MAAM,CAAC,YAAY,EAAE,EAAE,CAAC,CAC7B,SAAS,CAAC,aAAa,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;;AAEjD,KAAI,UAAU,GAAG,aAAa,CAAC;;AAE/B,KAAI,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC,UAAU,EAAE,CACpC,YAAY,EACZ,YAAY,CACZ,CAAC,CAAC;;AAEH,QAAO,UAAU,CAAC;CAElB,CAAC,CAAE","file":"angular-defensive.js","sourcesContent":["(function (global, factory) {\n\ttypeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :\n\ttypeof define === 'function' && define.amd ? define(factory) :\n\tglobal.angularDefensive = factory();\n}(this, function () { 'use strict';\n\n\tclass DefensiveConfiguration {\n\n\t constructor() {\n\t this.configurations = {};\n\t }\n\n\t static get Configuration() {\n\t return class Configuration {\n\t constructor() {\n\t this.cases = [];\n\t }\n\n\t addCase(confCase) {\n\t this.cases.push(confCase);\n\t return this;\n\t }\n\t };\n\t }\n\n\t get Configuration() {\n\t return DefensiveConfiguration.Configuration;\n\t }\n\n\t registerConfiguration(configurationName) {\n\t let configuration = new this.Configuration();\n\t this.configurations[configurationName] = configuration;\n\t return configuration;\n\t }\n\n\t $get($http, $templateCache) {\n\t let configurations = this.configurations;\n\t return {\n\t getTemplate(confCase) {\n\t return new Promise(function(resolve) {\n\t if (confCase.hasOwnProperty('template')) {\n\t resolve(confCase.template);\n\t } else if (confCase.hasOwnProperty('templateUrl')) {\n\t $http\n\t .get(confCase.templateUrl, {\n\t cache: $templateCache,\n\t headers: {Accept: 'text/html'}\n\t })\n\t .then(function(response) {\n\t resolve(response.data);\n\t });\n\t }\n\t });\n\t },\n\t getDefensiveCase(configurationName) {\n\t let self = this;\n\t return new Promise(function(resolve, reject) {\n\t if (!configurations.hasOwnProperty(configurationName)) {\n\t return reject(`Configuration ${configurationName} does not exist`);\n\t }\n\t let configuration = configurations[configurationName];\n\t while (configuration.cases.length) {\n\t let confCase = configuration.cases.shift();\n\t if (confCase.check()) {\n\t return self.getTemplate(confCase)\n\t .then(function(template) {\n\t confCase.template = template;\n\t return resolve(confCase);\n\t });\n\t }\n\t }\n\t });\n\t }\n\t };\n\t }\n\n\t static factory() {\n\t return new DefensiveConfiguration();\n\t }\n\n\t}\n\n\tvar moduleName$2 = 'ngDefensive.services';\n\n\tangular.module(moduleName$2, [])\n\t .provider('DefensiveConfiguration', DefensiveConfiguration.factory);\n\n\tclass NgDefensive {\n\n\t constructor($compile, DefensiveConfiguration) {\n\t this.restrict = 'A';\n\t this.scope = {\n\t callbacks: '=ngDefensiveCallbacks'\n\t };\n\t this.link = function(scope, element, attrs) {\n\t let activeCase = null;\n\t DefensiveConfiguration.getDefensiveCase(attrs.ngDefensive)\n\t .then(function(confCase) {\n\t element.replaceWith($compile(confCase.template)(scope));\n\t activeCase = confCase;\n\t });\n\t scope.action = function() {\n\t scope.callbacks[activeCase.caseName]();\n\t };\n\t };\n\t }\n\n\t static factory($compile, DefensiveConfiguration) {\n\t return new NgDefensive($compile, DefensiveConfiguration);\n\t }\n\n\t}\n\n\tvar moduleName$1 = 'ngDefensive.directives';\n\n\tangular.module(moduleName$1, [])\n\t .directive('ngDefensive', NgDefensive.factory);\n\n\tvar moduleName = 'ngDefensive';\n\n\tvar app = angular.module(moduleName, [\n\t\tmoduleName$1,\n\t\tmoduleName$2\n\t]);\n\n\treturn moduleName;\n\n}));"],"sourceRoot":"/source/"} \ No newline at end of file +{"version":3,"sources":["angular-defensive.js"],"names":[],"mappings":";;;;AAAA,AAAC,CAAA,UAAU,MAAM,EAAE,OAAO,EAAE;AAC3B,QAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,MAAM,KAAK,WAAW,GAAG,MAAM,CAAC,OAAO,GAAG,OAAO,EAAE,GACzF,OAAO,MAAM,KAAK,UAAU,IAAI,MAAM,CAAC,GAAG,GAAG,MAAM,CAAC,OAAO,CAAC,GAC5D,MAAM,CAAC,gBAAgB,GAAG,OAAO,EAAE,CAAC;CACpC,CAAA,CAAC,IAAI,EAAE,YAAY;AAAE,aAAY,CAAC;;AAElC,KAAM,IAAI,GAAG,IAAI,OAAO,EAAE,CAAC;AAC3B,KAAM,cAAc,GAAG,IAAI,OAAO,EAAE,CAAC;;KAE/B,sBAAsB;AAEf,WAFP,sBAAsB,CAEd,KAAK,EAAE,cAAc,EAAE;yBAF/B,sBAAsB;;AAGxB,OAAI,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AACtB,iBAAc,CAAC,GAAG,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;AACzC,OAAI,CAAC,cAAc,GAAG,EAAE,CAAC;GAC1B;;eANG,sBAAsB;;UAyBL,+BAAC,iBAAiB,EAAE;AACvC,QAAI,aAAa,GAAG,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;AAC7C,QAAI,CAAC,cAAc,CAAC,iBAAiB,CAAC,GAAG,aAAa,CAAC;AACvD,WAAO,aAAa,CA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C,CAAC;AACH,SAAK,CAAC,MAAM,GAAG,YAAW;AACxB,UAAK,CAAC,SAAS,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;KACxC,CAAC;IACH,CAAC;GACH;;eAlBG,WAAW;;UAoBD,iBAAC,QAAQ,EAAE,sBAAsB,EAAE;AAC/C,WAAO,IAAI,WAAW,CAAC,QAAQ,EAAE,sBAAsB,CAAC,CAAC;IAC1D;;;SAtBG,WAAW;;;AA0BjB,KAAI,YAAY,GAAG,wBAAwB,CAAC;;AAE5C,QAAO,CAAC,MAAM,CAAC,YAAY,EAAE,EAAE,CAAC,CAC7B,SAAS,CAAC,aAAa,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;;AAEjD,KAAI,UAAU,GAAG,aAAa,CAAC;;AAE/B,KAAI,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC,UAAU,EAAE,CACpC,YAAY,EACZ,YAAY,CACZ,CAAC,CAAC;;AAEH,QAAO,UAAU,CAAC;CAElB,CAAC,CAAE","file":"angular-defensive.js","sourcesContent":["(function (global, factory) {\n\ttypeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :\n\ttypeof define === 'function' && define.amd ? define(factory) :\n\tglobal.angularDefensive = factory();\n}(this, function () { 'use strict';\n\n\tconst HTTP = new WeakMap();\n\tconst TEMPLATE_CACHE = new WeakMap();\n\n\tclass DefensiveConfiguration {\n\n\t constructor($http, $templateCache) {\n\t HTTP.set(this, $http);\n\t TEMPLATE_CACHE.set(this, $templateCache);\n\t this.configurations = {};\n\t }\n\n\t static get Configuration() {\n\t return class Configuration {\n\t constructor() {\n\t this.cases = [];\n\t }\n\n\t addCase(confCase) {\n\t this.cases.push(confCase);\n\t return this;\n\t }\n\t };\n\t }\n\n\t get Configuration() {\n\t return DefensiveConfiguration.Configuration;\n\t }\n\n\t registerConfiguration(configurationName) {\n\t let configuration = new this.Configuration();\n\t this.configurations[configurationName] = configuration;\n\t return configuration;\n\t }\n\n\t getTemplate(confCase) {\n\t return new Promise(function(resolve) {\n\t if (confCase.hasOwnProperty('template')) {\n\t resolve(confCase.template);\n\t } else if (confCase.hasOwnProperty('templateUrl')) {\n\t HTTP.get(this)\n\t .get(confCase.templateUrl, {\n\t cache: TEMPLATE_CACHE.get(this),\n\t headers: {Accept: 'text/html'}\n\t })\n\t .then(function(response) {\n\t resolve(response.data);\n\t });\n\t }\n\t });\n\t }\n\n\t getDefensiveCase(configurationName) {\n\t let configurations = this.configurations;\n\t return new Promise(function(resolve, reject) {\n\t if (!configurations.hasOwnProperty(configurationName)) {\n\t return reject(`Configuration ${configurationName} does not exist`);\n\t }\n\t let configuration = configurations[configurationName];\n\t while (configuration.cases.length) {\n\t let confCase = configuration.cases.shift();\n\t if (confCase.check()) {\n\t return self.getTemplate(confCase)\n\t .then(function(template) {\n\t confCase.template = template;\n\t return resolve(confCase);\n\t });\n\t }\n\t }\n\t });\n\t }\n\n\t static factory($http, $templateCache) {\n\t return new DefensiveConfiguration($http, $templateCache);\n\t }\n\n\t}\n\n\tvar moduleName$2 = 'ngDefensive.services';\n\n\tangular.module(moduleName$2, [])\n\t .factory('DefensiveConfiguration', DefensiveConfiguration.factory);\n\n\tclass NgDefensive {\n\n\t constructor($compile, DefensiveConfiguration) {\n\t this.restrict = 'A';\n\t this.scope = {\n\t callbacks: '=ngDefensiveCallbacks'\n\t };\n\t this.link = function(scope, element, attrs) {\n\t let activeCase = null;\n\t DefensiveConfiguration.getDefensiveCase(attrs.ngDefensive)\n\t .then(function(confCase) {\n\t element.replaceWith($compile(confCase.template)(scope));\n\t activeCase = confCase;\n\t });\n\t scope.action = function() {\n\t scope.callbacks[activeCase.caseName]();\n\t };\n\t };\n\t }\n\n\t static factory($compile, DefensiveConfiguration) {\n\t return new NgDefensive($compile, DefensiveConfiguration);\n\t }\n\n\t}\n\n\tvar moduleName$1 = 'ngDefensive.directives';\n\n\tangular.module(moduleName$1, [])\n\t .directive('ngDefensive', NgDefensive.factory);\n\n\tvar moduleName = 'ngDefensive';\n\n\tvar app = angular.module(moduleName, [\n\t\tmoduleName$1,\n\t\tmoduleName$2\n\t]);\n\n\treturn moduleName;\n\n}));"],"sourceRoot":"/source/"} \ No newline at end of file diff --git a/dist/angular-defensive.min.js b/dist/angular-defensive.min.js index 9c535ce..5130e94 100644 --- a/dist/angular-defensive.min.js +++ b/dist/angular-defensive.min.js @@ -1,2 +1,2 @@ -function _classCallCheck(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}var _createClass=function(){function e(e,n){for(var t=0;t