Skip to content

Commit e0173a2

Browse files
authored
chore: Merge pull request #1 from code-adn/deep-merge
Deep merge
2 parents 2f08a80 + b0c7120 commit e0173a2

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"@angular/platform-browser-dynamic": "^6.0.0",
2020
"@ngx-translate/core": ">=10.0.0",
2121
"core-js": "^2.5.4",
22+
"deepmerge": "^2.1.1",
2223
"rxjs": "^6.1.0",
2324
"zone.js": "^0.8.26"
2425
},

projects/ngx-translate/multi-http-loader/src/lib/multi-http-loader.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {HttpClient} from "@angular/common/http";
22
import {TranslateLoader} from "@ngx-translate/core";
33
import {Observable, forkJoin} from "rxjs";
44
import {map} from "rxjs/operators";
5+
import merge from 'deepmerge';
56

67

78
export interface ITranslationResource {
@@ -19,6 +20,6 @@ export class MultiTranslateHttpLoader implements TranslateLoader {
1920
const requests = this.resources.map(resource => {
2021
return this.http.get(resource.prefix + lang + resource.suffix);
2122
});
22-
return forkJoin(requests).pipe(map(response => response.reduce((a, b) => Object.assign(a, b))));
23+
return forkJoin(requests).pipe(map(response => merge.all(response)));
2324
}
2425
}

projects/ngx-translate/multi-http-loader/tests/multi-http-loader.spec.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,17 @@ describe('MultiTranslateHttpLoader - Multiple Translation Files', () => {
151151
// mock response after the xhr request, otherwise it will be undefined
152152
http.expectOne('/assets/i18n/core/en.json').flush({
153153
"TEST": "This is a test (core)",
154-
"TEST2": "This is another test (core)"
154+
"TEST2": "This is another test (core)",
155+
"DEEP": {
156+
"some": "thing"
157+
}
155158
});
156159
http.expectOne('/assets/i18n/shared/en.json').flush({
157160
"TEST-SHARED": "This is a test (shared)",
158-
"TEST2-SHARED": "This is another test (shared)"
161+
"TEST2-SHARED": "This is another test (shared)",
162+
"DEEP": {
163+
"another": "something"
164+
}
159165
});
160166

161167
// this will request the translation from downloaded translations without making a request to the backend
@@ -165,5 +171,11 @@ describe('MultiTranslateHttpLoader - Multiple Translation Files', () => {
165171
translate.get('TEST2-SHARED').subscribe((res: string) => {
166172
expect(res).toEqual('This is another test (shared)');
167173
});
174+
translate.get('DEEP').subscribe((res: any) => {
175+
expect(res).toEqual({
176+
"some": "thing",
177+
"another": "something"
178+
});
179+
});
168180
});
169181
});

0 commit comments

Comments
 (0)