Skip to content

Commit d9b3261

Browse files
committed
Can get configuration object at config
1 parent 83f8dc8 commit d9b3261

File tree

3 files changed

+39
-13
lines changed

3 files changed

+39
-13
lines changed

package/dist/ConfigurationProvider.js

+22-10
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,15 @@
5757
/* @ngInject */
5858
function ConfigurationProvider() {
5959
this.mergedConfiguration = {};
60-
this.addObject(window.webConfig, true);
61-
this.addObject(window.configuration, true);
60+
this.addConfiguration(window.webConfig, true);
61+
this.addConfiguration(window.configuration, true);
6262
}
63+
/* @ngInject */
6364
ConfigurationProvider.prototype.$get = function ($q) {
64-
return this.mergedConfiguration;
65+
return this.getConfiguration();
6566
};
66-
ConfigurationProvider.prototype.get = function () {
67-
return this.mergedConfiguration;
68-
};
69-
ConfigurationProvider.prototype.addObject = function (obj, optional) {
67+
ConfigurationProvider.prototype.$get.$inject = ["$q"];
68+
ConfigurationProvider.prototype.addConfiguration = function (obj, optional) {
7069
if (obj) {
7170
this.mergedConfiguration = merge(this.mergedConfiguration, obj);
7271
}
@@ -76,6 +75,18 @@
7675
}
7776
}
7877
};
78+
/**
79+
* Add a default object that will only add params that aren't already specified
80+
* @param obj
81+
*/
82+
ConfigurationProvider.prototype.addDefaultConfiguration = function (obj) {
83+
if (obj) {
84+
this.mergedConfiguration = merge(obj, this.mergedConfiguration);
85+
}
86+
};
87+
ConfigurationProvider.prototype.getConfiguration = function () {
88+
return this.mergedConfiguration;
89+
};
7990
return ConfigurationProvider;
8091
}());
8192
exports.ConfigurationProvider = ConfigurationProvider;
@@ -84,9 +95,10 @@
8495
xobj.overrideMimeType("application/json");
8596
xobj.open('GET', 'configuration.json', true); // Replace 'my_data' with the path to your file
8697
xobj.onreadystatechange = function () {
87-
if (xobj.readyState == 4 && xobj.status == 200) {
88-
// Required use of an anonymous callback as .open will NOT return a value but simply returns undefined in asynchronous mode
89-
window.configuration = JSON.parse(xobj.responseText);
98+
if (xobj.readyState == 4) {
99+
if (xobj.status == 200) {
100+
window.configuration = JSON.parse(xobj.responseText);
101+
}
90102
callback();
91103
}
92104
};

package/dist/src/ConfigurationProvider.d.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ export declare class ConfigurationProvider<T> {
22
private mergedConfiguration;
33
constructor();
44
$get($q: angular.IQService): T;
5-
get(): T;
6-
addObject(obj: any, optional?: boolean): void;
5+
addConfiguration(obj: T, optional?: boolean): void;
6+
/**
7+
* Add a default object that will only add params that aren't already specified
8+
* @param obj
9+
*/
10+
addDefaultConfiguration(obj: T): void;
11+
getConfiguration(): T;
712
}
813
export declare function loadConfigurationJSON(callback: any): void;

package/src/ConfigurationProvider.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class ConfigurationProvider<T> {
1414

1515
/* @ngInject */
1616
public $get($q: angular.IQService) {
17-
return this.mergedConfiguration;
17+
return this.getConfiguration();
1818
}
1919

2020
public addConfiguration(obj: T, optional?: boolean) {
@@ -36,6 +36,15 @@ export class ConfigurationProvider<T> {
3636
this.mergedConfiguration = <T>merge(obj, this.mergedConfiguration);
3737
}
3838
}
39+
40+
/**
41+
* Get the configuration object at config.
42+
* It can be useful to configure other providers with the loaded configuration
43+
* @returns {T}
44+
*/
45+
public getConfiguration() {
46+
return this.mergedConfiguration;
47+
}
3948
}
4049

4150
export function loadConfigurationJSON(callback) {

0 commit comments

Comments
 (0)