Skip to content

Commit

Permalink
chore: Merge pull request #1 from code-adn/deep-merge
Browse files Browse the repository at this point in the history
Deep merge
  • Loading branch information
denniske authored Sep 13, 2018
2 parents 2f08a80 + b0c7120 commit e0173a2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@angular/platform-browser-dynamic": "^6.0.0",
"@ngx-translate/core": ">=10.0.0",
"core-js": "^2.5.4",
"deepmerge": "^2.1.1",
"rxjs": "^6.1.0",
"zone.js": "^0.8.26"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {HttpClient} from "@angular/common/http";
import {TranslateLoader} from "@ngx-translate/core";
import {Observable, forkJoin} from "rxjs";
import {map} from "rxjs/operators";
import merge from 'deepmerge';


export interface ITranslationResource {
Expand All @@ -19,6 +20,6 @@ export class MultiTranslateHttpLoader implements TranslateLoader {
const requests = this.resources.map(resource => {
return this.http.get(resource.prefix + lang + resource.suffix);
});
return forkJoin(requests).pipe(map(response => response.reduce((a, b) => Object.assign(a, b))));
return forkJoin(requests).pipe(map(response => merge.all(response)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,17 @@ describe('MultiTranslateHttpLoader - Multiple Translation Files', () => {
// mock response after the xhr request, otherwise it will be undefined
http.expectOne('/assets/i18n/core/en.json').flush({
"TEST": "This is a test (core)",
"TEST2": "This is another test (core)"
"TEST2": "This is another test (core)",
"DEEP": {
"some": "thing"
}
});
http.expectOne('/assets/i18n/shared/en.json').flush({
"TEST-SHARED": "This is a test (shared)",
"TEST2-SHARED": "This is another test (shared)"
"TEST2-SHARED": "This is another test (shared)",
"DEEP": {
"another": "something"
}
});

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

0 comments on commit e0173a2

Please sign in to comment.