-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-create thrift client when auth credentials (e.g. oauth token) change
Signed-off-by: Levko Kravets <[email protected]>
- Loading branch information
1 parent
12afffe
commit 39eb9c9
Showing
3 changed files
with
67 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { HttpHeaders } from 'thrift'; | ||
|
||
function areArraysEqual<T>(a: Array<T>, b: Array<T>): boolean { | ||
// If they're the same object - they're equal | ||
if (a === b) { | ||
return true; | ||
} | ||
|
||
// If they have a different size - they're definitely not equal | ||
if (a.length !== b.length) { | ||
return false; | ||
} | ||
|
||
// Here we have arrays of same size. Compare elements - if any pair is different | ||
// then arrays are different | ||
for (let i = 0; i < a.length; i += 1) { | ||
if (a[i] !== b[i]) { | ||
return false; | ||
} | ||
} | ||
|
||
// If all corresponding elements in both arrays are equal - arrays are equal too | ||
return true; | ||
} | ||
|
||
export default function areHeadersEqual(a: HttpHeaders, b: HttpHeaders): boolean { | ||
// If they're the same object - they're equal | ||
if (a === b) { | ||
return true; | ||
} | ||
|
||
// If both objects have different keys - they're not equal | ||
const keysOfA = Object.keys(a); | ||
const keysOfB = Object.keys(b); | ||
if (!areArraysEqual(keysOfA, keysOfB)) { | ||
return false; | ||
} | ||
|
||
// Compare corresponding properties of both objects. If any pair is different - objects are different | ||
for (const key of keysOfA) { | ||
const propA = a[key]; | ||
const propB = b[key]; | ||
|
||
if (Array.isArray(propA) && Array.isArray(propB)) { | ||
if (!areArraysEqual(propA, propB)) { | ||
return false; | ||
} | ||
} else if (propA !== propB) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} |
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import areHeadersEqual from './areHeadersEqual'; | ||
import definedOrError from './definedOrError'; | ||
import buildUserAgentString from './buildUserAgentString'; | ||
import formatProgress, { ProgressUpdateTransformer } from './formatProgress'; | ||
|
||
export { definedOrError, buildUserAgentString, formatProgress, ProgressUpdateTransformer }; | ||
export { areHeadersEqual, definedOrError, buildUserAgentString, formatProgress, ProgressUpdateTransformer }; |