Skip to content

Commit 370e008

Browse files
author
Raphaël Balet
committed
perf(deepmerge-ts): use local method instead
1 parent 951175a commit 370e008

File tree

4 files changed

+34
-15
lines changed

4 files changed

+34
-15
lines changed

package-lock.json

Lines changed: 1 addition & 9 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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ngx-translate-multi-http-loader",
3-
"version": "18.3.0",
3+
"version": "18.2.0",
44
"license": "MIT",
55
"author": "Raphael Balet",
66
"maintainers": [
@@ -16,7 +16,6 @@
1616
"@angular/common": "^18.2.3",
1717
"@angular/core": "^18.2.3",
1818
"@ngx-translate/core": "^15.0.0",
19-
"deepmerge-ts": "^7.1.0",
2019
"rxjs": "^7.8.1",
2120
"tslib": "2.6.3"
2221
},

projects/multi-http-loader/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ngx-translate-multi-http-loader",
3-
"version": "18.3.0",
3+
"version": "18.2.0",
44
"license": "MIT",
55
"author": {
66
"name": "Raphaël Balet",
@@ -29,7 +29,6 @@
2929
"@angular/common": ">=13.0.0",
3030
"@angular/core": ">=13.0.0",
3131
"@ngx-translate/core": ">=15.0.0",
32-
"deepmerge-ts": "^7.1.0",
3332
"rxjs": "^7.8.1"
3433
}
3534
}

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

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { HttpBackend, HttpClient } from '@angular/common/http'
22
import { TranslateLoader } from '@ngx-translate/core'
3-
import { deepmerge } from 'deepmerge-ts'
43
import { forkJoin, Observable, of } from 'rxjs'
54
import { catchError, map } from 'rxjs/operators'
65

@@ -36,6 +35,36 @@ export class MultiTranslateHttpLoader implements TranslateLoader {
3635
)
3736
})
3837

39-
return forkJoin(requests).pipe(map((response) => deepmerge(...response)))
38+
return forkJoin(requests).pipe(
39+
map((response) => response.reduce((acc, curr) => this.mergeDeep(acc, curr), {})),
40+
)
41+
}
42+
43+
// @ToDo: Use it from ngx-translate once it gets exported: https://github.com/rbalet/ngx-translate-multi-http-loader/issues/35
44+
isObject(item: any): boolean {
45+
return item && typeof item === 'object' && !Array.isArray(item)
46+
}
47+
48+
mergeDeep(target: any, source: any): any {
49+
const output = Object.assign({}, target)
50+
51+
if (!this.isObject(target)) {
52+
return this.mergeDeep({}, source)
53+
}
54+
55+
if (this.isObject(target) && this.isObject(source)) {
56+
Object.keys(source).forEach((key: any) => {
57+
if (this.isObject(source[key])) {
58+
if (!(key in target)) {
59+
Object.assign(output, { [key]: source[key] })
60+
} else {
61+
output[key] = this.mergeDeep(target[key], source[key])
62+
}
63+
} else {
64+
Object.assign(output, { [key]: source[key] })
65+
}
66+
})
67+
}
68+
return output
4069
}
4170
}

0 commit comments

Comments
 (0)