Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement dynamic imports? #13

Closed
garrettjstevens opened this issue Oct 29, 2018 · 8 comments
Closed

Implement dynamic imports? #13

garrettjstevens opened this issue Oct 29, 2018 · 8 comments
Assignees

Comments

@garrettjstevens
Copy link
Collaborator

Since we want basically everything to be configurable, we're going to need a way to load things like plugins from user-defined sources. With dynamic imports, we can at least load custom React components, which is a good start.

Need to experiment and see if this will work well for us.

@garrettjstevens
Copy link
Collaborator Author

@rbuels I've tested this out a bit and it seems to work pretty well. Basically you import the module in a component's componentDidMount() method and then update the state with the imported module. It was originally implemented so you could split up code in your bundle and have it only loaded when it's needed, but it works great for updating code from a variable path as well. This would work well for plugins, etc. that are available at build time. Also I think it's the way to go for dynamically updating our content-aware SideDrawer (or Credenza...). We'd have to figure something else out for non-bundled plugins like we talked about in the last backlog grooming.

If there are no objections I'm going to start working on implementing this in some of the UI components I've created and see how it goes.

@rbuels
Copy link
Contributor

rbuels commented Oct 30, 2018 via email

@garrettjstevens
Copy link
Collaborator Author

This seems to be working well. I've got a demo working that imports a new component and places it in the side drawer when a button is clicked:

Before click:
image

After click:
image

@cmdcolin
Copy link
Collaborator

cmdcolin commented Nov 9, 2018

I was curious still if this could apply to plugins added after compilation...I was thinking maybe of looking at the Electron atom ecosystem how they have add-on packages.

@garrettjstevens garrettjstevens self-assigned this Nov 27, 2018
@garrettjstevens
Copy link
Collaborator Author

With the recent addition of Lazy and Suspense to React, it probably make more sense to use that for lazy loading. Currently the drawer widgets are required to lazy react components (example), but we need to make sure this will work with run-time plugins (see GMOD/jbrowse-plugin-template#32).

@rbuels
Copy link
Contributor

rbuels commented Dec 9, 2018

Interestingly, it's starting to look like a lot of our code is actually going to be MST models, and MST's need to know the types of things in advance means that MST models can't really be lazy-loaded.

But could we lazy-load a lot of our react components by wrapping them with lazy and suspense though?

@garrettjstevens
Copy link
Collaborator Author

Yeah, so far both drawer widget and menu bar pluggable types are required to have their React components be Lazy components that are loaded with Suspense. I'm planning on seeing if this model holds up with run-time plugins.

@rbuels
Copy link
Contributor

rbuels commented Jan 16, 2019

a number of things are using this, closing.

@rbuels rbuels closed this as completed Jan 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants