Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Attempt #2: Prepare fbs.js sync to fbsource
Summary: - Add "Fbt" in some internal i18n flow types to make it easier for our linter to detect - Refactor FbtResultBase into a "common implementation" file and a repo specific file - This will be useful to share code with fbsource ---- - Fixed incorrect creation of the FbtResultWWW derived class Depends on D13430310 Reviewed By: jrwats Differential Revision: D13503870 fbshipit-source-id: 788de3d5eeb0a279c01aebf315cf590fc8111f82
- Loading branch information
1 parent
cf9db30
commit a1c6d96
Showing
8 changed files
with
253 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* Copyright 2004-present Facebook. All Rights Reserved. | ||
* | ||
* NOTE: | ||
* The FbtResultBase "implemented" module has a forked version on the fbsource repo: | ||
* See `xbgf __forks__/FbtResultBaseImpl.js` | ||
* | ||
* When you change this file on www, please make sure you apply | ||
* similar (relevant) changes on the fbsource version. | ||
* | ||
* @flow | ||
* @format | ||
* @emails oncall+internationalization | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const FbtResultWWW = require('FbtResultWWW'); | ||
|
||
module.exports = FbtResultWWW; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* Copyright 2004-present Facebook. All Rights Reserved. | ||
* | ||
* @flow | ||
* @format | ||
* @emails oncall+internationalization | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import type { | ||
FbtContentItem as _FbtContentItem, | ||
NestedFbtContentItems as _NestedFbtContentItems, | ||
} from 'FbtResultBase'; | ||
|
||
export type FbtContentItem = _FbtContentItem; | ||
export type NestedFbtContentItems = _NestedFbtContentItems; | ||
|
||
const FBLogger = require('FBLogger'); | ||
const FbtResultBase = require('FbtResultBase'); | ||
const killswitch = require('killswitch'); | ||
|
||
function logErrorUseStringMethod(methodName: string): void { | ||
// If the contents is array of length greater than one, then use the string | ||
// method will cause error | ||
FBLogger('fbt') | ||
.blameToPreviousFile() | ||
.mustfix( | ||
'Error using fbt string. Used method %s' + | ||
' on Fbt string. Fbt string is designed to be immutable ' + | ||
'and should not be manipulated.', | ||
methodName, | ||
); | ||
} | ||
|
||
/** | ||
* The FbtResultBase "implemented" module for www. | ||
*/ | ||
class FbtResultWWW extends FbtResultBase { | ||
onStringSerializationError(content: FbtContentItem): void { | ||
let details = 'Context not logged.'; | ||
if (!killswitch('JS_RELIABILITY_FBT_LOGGING')) { | ||
try { | ||
details = JSON.stringify(content).substr(0, 250); | ||
} catch (err) { | ||
// Catching circular reference error | ||
details = err.message; | ||
} | ||
} | ||
FBLogger('fbt') | ||
.blameToPreviousFile() | ||
.mustfix('Converting to a string will drop content data. %s', details); | ||
} | ||
} | ||
|
||
const FbtResultWWWWithStringishMethods = FbtResultWWW.usingStringProxyMethod( | ||
(methodName: $Keys<IFbtStringish>) => { | ||
return function() { | ||
logErrorUseStringMethod(methodName); | ||
// $FlowFixMe Mock stringish methods | ||
return String.prototype[methodName].apply(this, arguments); | ||
}; | ||
}, | ||
); | ||
|
||
module.exports = FbtResultWWWWithStringishMethods; |
Oops, something went wrong.