Skip to content

Commit e149821

Browse files
Remove dynamic import (#1787)
* Remove dynamic import * Help typescript along
1 parent 7d3d46d commit e149821

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/browser/modules/Stream/Extras/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@
1818
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1919
*/
2020

21-
export { default as SnakeFrame } from './SnakeFrame'
21+
import SnakeFrame from './SnakeFrame'
22+
export default { SnakeFrame }

src/browser/modules/Stream/FrameContainer.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import StyleFrame from './StyleFrame'
4747
import SysInfoFrame from './SysInfoFrame/SysInfoFrame'
4848
import { Connection } from 'shared/modules/connections/connectionsDuck'
4949
import { FrameStack } from 'shared/modules/frames/framesDuck'
50+
import extras from './Extras/index'
5051

5152
const nameToFrame: Record<string, React.ComponentType<any>> = {
5253
error: ErrorFrame,
@@ -78,14 +79,19 @@ const nameToFrame: Record<string, React.ComponentType<any>> = {
7879

7980
const getFrameComponent = (frameData: FrameStack): React.ComponentType<any> => {
8081
const { cmd, type } = frameData.stack[0]
81-
let MyFrame = nameToFrame[type]
82+
let MyFrame = nameToFrame[type] ?? ErrorFrame
8283

83-
if (!MyFrame || type === 'error') {
84-
try {
85-
const command = cmd.replace(/^:/, '')
86-
const Frame = command[0].toUpperCase() + command.slice(1) + 'Frame'
87-
MyFrame = require('./Extras/index')[Frame] || nameToFrame['error']
88-
} catch (e) {}
84+
if (type === 'error') {
85+
const command = cmd.replace(/^:/, '')
86+
const frameName = command[0].toUpperCase() + command.slice(1) + 'Frame'
87+
const isExtraFrame = (
88+
frameName: string
89+
): frameName is keyof typeof extras =>
90+
Object.keys(extras).includes(frameName)
91+
92+
if (isExtraFrame(frameName)) {
93+
MyFrame = extras[frameName]
94+
}
8995
}
9096
return MyFrame
9197
}

0 commit comments

Comments
 (0)