Skip to content

Commit

Permalink
ON-39739 # Fixed duplicate determineQueueSize functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mymattcarroll committed Apr 19, 2024
1 parent 76e401c commit b82ba96
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 47 deletions.
35 changes: 14 additions & 21 deletions src/http-handlers/FetchHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,31 +90,24 @@ export class OneBlinkFetchHandler<T>
}

determineQueueSize() {
let queueSize = 1 // default to 1 as the lowest common denominator
// Return as though using highest speed for Node environments
if (!window) return 10
if (
const effectiveType =
window.navigator &&
'connection' in window.navigator &&
!!window.navigator.connection &&
// @ts-expect-error effectiveType prop is still in draft
window.navigator.connection.effectiveType
) {
// @ts-expect-error effectiveType prop is still in draft
switch (window.navigator.connection.effectiveType) {
case 'slow-2g':
case '2g':
queueSize = 1
break
case '3g':
queueSize = 2
break
case '4g':
queueSize = 10
break
typeof window.navigator.connection === 'object' &&
'effectiveType' in window.navigator.connection
? window.navigator.connection.effectiveType
: undefined
switch (effectiveType) {
case '4g':
return 10
case '3g':
return 2
case 'slow-2g':
case '2g':
default: {
return 1
}
}

return queueSize
}
}
27 changes: 1 addition & 26 deletions src/http-handlers/NodeJsHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,31 +87,6 @@ export class OneBlinkNodeJsHandler<T>
}

determineQueueSize() {
let queueSize = 1 // default to 1 as the lowest common denominator
// Return as though using highest speed for Node environments
if (!window) return 10
if (
window.navigator &&
'connection' in window.navigator &&
!!window.navigator.connection &&
// @ts-expect-error effectiveType prop is still in draft
window.navigator.connection.effectiveType
) {
// @ts-expect-error effectiveType prop is still in draft
switch (window.navigator.connection.effectiveType) {
case 'slow-2g':
case '2g':
queueSize = 1
break
case '3g':
queueSize = 2
break
case '4g':
queueSize = 10
break
}
}

return queueSize
return 10
}
}

0 comments on commit b82ba96

Please sign in to comment.