GMOD / jbrowse-components

Source code for JBrowse 2, a modern React-based genome browser
https://jbrowse.org/jb2
Apache License 2.0
208 stars 62 forks source link

plain-JS wrapper for embeddable LGV #1028

Closed rbuels closed 3 years ago

rbuels commented 4 years ago

wraps the embeddable-LGV state model and theme providers (#1027) with plain JS and provides a CDN build of it, so that people can run something like:

<html>
<head>
  <script src="(CDN URL)/component.js"></script>
</head>
<body>
  <div id="jb2_lgv"></div>
  <script>

    const genomeView = new JBrowseLinearGenomeView({
      container: document.getElementById('jb2_lgv'),
      assembly: { /* full assembly config snapshotin */ },
      tracks: [ /* full track snapshotIns */ ],
      plugins: [ /* optional list of runtime plugins to load */ ],
      defaultSession: {
        /* session snapshot just for an LGV */
        bpPerPx: 1,
        displayedRegions: [ /* list of displayed regions */ ]
      }
    })

    // here's how you can react to changes in the state
    genomeView.addChangeListener( (mst_patch) => {
      /* handler for reacting to changes in the LGV's state tree */
    })

    // the view's MST model would just be exposed in the .view attribute, and
    // people could call actions on it
    genomeView.view.navTo("chr4:234235-235245")

    // JBrowseLinearGenomeView would be a subclass of JBrowseEmbeddedViewContainer,
    // which would set up the environment necessary for the view to run (theme, pluginManager,
    // root MST model, etc).
  </script>
</body>

</html>

This code might be a little hard to test so let's try to keep it a very thin wrapper around the code made in #1027. Mostly just a plain-JS class that looks a little like protein-widget/src/Viewer.js, and a webpack configuration that does a CDN-able UMD build of it.

CDN URLs (needs review)

cmdcolin commented 4 years ago

It was briefly mentioned that packaging webworker bundles might be tricky for example. Does that mean embeddable LGV will be limited to MainThreadRpc? Any way to allow web worker? I just ask because RPC adds a fair bit of overhead (not sure we have a way to measure that overhead, maybe by comparing to something like JB1)

rbuels commented 4 years ago

Seems a little bit weird for an embedded thing to be launching web workers. But maybe not too weird. It's not really out of the question that an embedded browser could launch them, it would just need to have a web worker entry point that it builds as well.

On Sun, Sep 6, 2020 at 11:15 AM Colin Diesh notifications@github.com wrote:

It was briefly mentioned that packaging webworker bundles might be tricky for example. Does that mean embeddable LGV will be limited to MainThreadRpc? Any way to allow web worker? I just ask because RPC adds a fair bit of overhead (not sure we have a way

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/GMOD/jbrowse-components/issues/1028#issuecomment-687860277, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAASAFP4JMJHMQL7UWAODG3SEPGVRANCNFSM4OJS5L5Q .

garrettjstevens commented 3 years ago

See this branch for what was used to generate the plain-js wrapper for the BCC2020 course (with a couple updates): https://github.com/GMOD/jbrowse-components/tree/react_lgv_plainjs

garrettjstevens commented 3 years ago

Updated branch for v1.1.0: https://github.com/GMOD/jbrowse-components/tree/react_lgv_plainjs_1.1.0

garrettjstevens commented 3 years ago

Just a note, I had trouble building the above v1.1.0 branch on node 12, but node 10 seems to work fine.

cmdcolin commented 3 years ago

interesting...any specific error? I think we may be moving to node 12+ soon...node 10 EOLd and the data-grid #1977 upgrades because data-grid specifies engines:12

garrettjstevens commented 3 years ago

The error was:

ERROR in ./src/index.js
Module not found: Error: Can't resolve '@jbrowse/react-linear-genome-view' in '/path/to/jbrowse-components/products/jbrowse-linear-genome-view/src'
 @ ./src/index.js 8:0-173 29:23-34 33:24-39 43:66-79 44:25-43 51:52-80
cmdcolin commented 3 years ago

did you happen to try with v1.2.0?

garrettjstevens commented 3 years ago

No, I didn't.

garrettjstevens commented 3 years ago

Updated branch for v1.2.0: https://github.com/GMOD/jbrowse-components/tree/react_lgv_plainjs_1.2.0. This also includes a fix for https://github.com/GMOD/jbrowse-components/issues/1996.

Also, ignore the trouble on node 12 I mentioned above. That was user error on my part.

cmdcolin commented 3 years ago

is there any benefit for the user to add themeprovider themselves?

garrettjstevens commented 3 years ago

@cmdcolin I'm not sure what you mean

cmdcolin commented 3 years ago

we could remove our usage ThemeProvider inside the component and make the user provide it. it "feels" like a more direct way for them to provide the theme they want rather than interface with our config system. maybe it is not needed though

cmdcolin commented 3 years ago

I guess the configuration versions of theme can be used in things like the renderer...may be needed to keep in config

garrettjstevens commented 3 years ago

Updated branch for v1.3.2: https://github.com/GMOD/jbrowse-components/tree/react_lgv_plainjs_1.3.2