Skip to content
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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

kayhadrin
Copy link

@kayhadrin kayhadrin commented May 18, 2020

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)

@@ -26,6 +26,7 @@
"dependencies": {
"@babel/runtime": "^7.9.2",
"babel-plugin-fbt-runtime": "^0.9.4",
"cls-hooked": "^4.2.2",
Copy link
Author

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)

Comment on lines 16 to 28
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
};
}
Copy link
Author

@kayhadrin kayhadrin May 18, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant