Skip to content

Commit

Permalink
More typescripting
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Oct 5, 2023
1 parent f4d19aa commit 9effb17
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 41 deletions.
File renamed without changes.
31 changes: 0 additions & 31 deletions srcjs/components/View.jsx

This file was deleted.

34 changes: 34 additions & 0 deletions srcjs/components/View.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from 'react'
import {
createViewState,
JBrowseLinearGenomeView,
} from '@jbrowse/react-linear-genome-view'

import { messageShiny } from '../utils'

export default function View(props: {
tracks: string
assembly: string
location: string
theme: string
text_index: string
}) {
const { theme, text_index, assembly, tracks, location, ...rest } =
Object.fromEntries(
Object.entries(props).map(([key, value]) => [
key,
key === 'location' ? value : JSON.parse(value),
]),
)
const state = createViewState({
...rest,
onChange: messageShiny,
configuration: { theme },
aggregateTextSearchAdapters: text_index,
location,
assembly,
tracks,
})

return <JBrowseLinearGenomeView viewState={state} />
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import React from 'react'
import {
createViewState,
JBrowseLinearGenomeView,
Expand Down Expand Up @@ -86,11 +87,11 @@ const defaultSession = {
},
}

export default function Hg19View(props) {
export default function Hg19View({ location }: { location: string }) {
const state = createViewState({
assembly,
tracks,
location: props.location,
location,
defaultSession,
onChange: messageShiny,
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import React from 'react'
import {
createViewState,
JBrowseLinearGenomeView,
Expand Down Expand Up @@ -86,12 +87,11 @@ const defaultSession = {
},
}

export default function ViewHg38(props) {
console.log({ props })
export default function ViewHg38({location}:{location:string}) {
const state = createViewState({
assembly,
tracks,
location: props.location,
location,
defaultSession,
onChange: messageShiny,
})
Expand Down
11 changes: 6 additions & 5 deletions srcjs/utils.js → srcjs/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
* @param patch The JSON patch received from
* the LGV ViewState with what was changed.
*/
export function messageShiny(patch) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function messageShiny(patch: any) {
if (typeof Shiny === 'undefined') {
return
}
Expand All @@ -17,9 +18,9 @@ export function messageShiny(patch) {
if (path.endsWith('featureData')) {
Shiny.setInputValue('selectedFeature', value)
} else if (path.endsWith('Feature') && value) {
const { featureData } = value
if (featureData) {
Shiny.setInputValue('selectedFeature', featureData)
}
const { featureData } = value
if (featureData) {
Shiny.setInputValue('selectedFeature', featureData)
}
}
}

0 comments on commit 9effb17

Please sign in to comment.