-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Experimental/continuation local storage with fbt runtime #17
base: master
Are you sure you want to change the base?
Experimental/continuation local storage with fbt runtime #17
Conversation
@@ -26,6 +26,7 @@ | |||
"dependencies": { | |||
"@babel/runtime": "^7.9.2", | |||
"babel-plugin-fbt-runtime": "^0.9.4", | |||
"cls-hooked": "^4.2.2", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Used cls-hooked instead of node-continuation-local-storage:
See othiym23/node-continuation-local-storage#98 (comment) for more info.
There's maybe hopes to find something more elegant with this other Express plugin: othiym23/node-continuation-local-storage#98 (comment)
src/helpers/translations/index.ts
Outdated
getViewerContext() { | ||
if (!!isNode && continuationLocalStorage != null) { | ||
const sessionLocale = continuationLocalStorage.getNamespace('session').get('locale'); | ||
if (!sessionLocale) { | ||
throw new Error('Unknown sessionLocale'); | ||
} | ||
locale = sessionLocale; | ||
} | ||
return { | ||
GENDER: IntlVariations.GENDER_UNKNOWN, | ||
locale: locale || DEFAULT_LOCALE | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Depends on a new (WIP) Fbt runtime API from this PR: facebook/fbt#142
This PR demonstrates how the continuation-local-storage npm module (actually, a fork of it) could be used to keep track of the initial locale of a web request, when used with the fbt runtime JS API.
Depends on a new (WIP) Fbt runtime API from this PR: facebook/fbt#142
Note that the vanilla continuation-local-storage module is not
await
friendly, so you might want to investigate how to make it work best for your purposes.For now, I used cls-hooked instead of node-continuation-local-storage:
See othiym23/node-continuation-local-storage#98 (comment) for more info.
There's maybe hopes to find something more elegant with this other Express plugin: othiym23/node-continuation-local-storage#98 (comment)