Skip to content

Commit 9f7951b

Browse files
authored
Merge pull request #602 from vtex-apps/event-custom-callback
Add a custom callback param to the localesChanged event
2 parents 9514c00 + 3fc6ec0 commit 9f7951b

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
### Added
11+
- Custom callback param to the localesChanged event.
12+
1013
## [8.127.0] - 2021-03-10
1114

1215
### Added

react/components/RenderProvider.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -964,9 +964,14 @@ export class RenderProvider extends Component<
964964
return assetsPromise
965965
}
966966

967-
public onLocaleSelected = (locale: string, domain?: string) => {
967+
public onLocaleSelected = (
968+
locale: string,
969+
domain?: string,
970+
callback?: () => unknown
971+
) => {
968972
if (locale !== this.state.culture.locale) {
969973
const sessionData = { public: {} }
974+
970975
if (domain && domain === 'admin') {
971976
sessionData.public = {
972977
admin_cultureInfo: {
@@ -980,13 +985,20 @@ export class RenderProvider extends Component<
980985
},
981986
}
982987
}
983-
this.patchSession(sessionData)
984-
.then(() => window.location.reload())
988+
989+
return this.patchSession(sessionData)
990+
.then(() => {
991+
if (callback) return callback()
992+
993+
return window.location.reload()
994+
})
985995
.catch((e) => {
986996
console.log('Failed to fetch new locale file.')
987997
console.error(e)
988998
})
989999
}
1000+
1001+
return undefined
9901002
}
9911003

9921004
public updateRuntime = async (options?: PageContextOptions) => {

0 commit comments

Comments
 (0)