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

Interface with external JS library #547

Open
runfalk opened this issue Oct 11, 2020 · 9 comments
Open

Interface with external JS library #547

runfalk opened this issue Oct 11, 2020 · 9 comments
Labels
question Further information is requested

Comments

@runfalk
Copy link

runfalk commented Oct 11, 2020

Hi!

I'm interested in using Seed but I also need Mapbox GL). I tried to look for that in the documentation, but there doesn't seem to be any mention on how to interface Seed with JS libraries (if it's even possible?).

What's the best way of doing this?

@MartinKavik
Copy link
Member

MartinKavik commented Oct 12, 2020

Hi @runfalk,

Rust <-> Js communication is possible (for instance, all Rust frameworks have to talk with the Js world to call browser APIs). There is also a WIP tutorial that uses Auth0's Js library to provide authentication - see e.g. https://seed-rs.org/0.7.0/time_tracker_authentication.

However for your case I would recommend to wrap Mapbox into a custom element. This way, the Mapbox Js libraries can modify DOM as they wish and it doesn't fight with the framework's DOM patching and you will be able to use it in any SPA framework.

Some links that should help you a bit:

Hope it helps!

@MartinKavik MartinKavik added the question Further information is requested label Oct 12, 2020
@flosse
Copy link
Member

flosse commented Oct 12, 2020

@runfalk https://github.com/kartevonmorgen/leaflet-rs might be interesting for you.

@seanybaggins
Copy link

Kinda a similar question...

Is using bootstrap by just modifying the class attributes within the html macros okay?

Does bootstrap interact with the DOM in a way that could not play nice with Seed?

@MartinKavik
Copy link
Member

@seanybaggins Bootstrap uses jQuery.. so it modifies DOM a lot (if nothing changed recently). There are some efforts to create a "native Bootstrap" (i.e. Bootstrap with JS without jQuery) or even a combination of Bootstrap with lit-element (it should work with Seed) - see e.g. https://medium.com/lightbaseio/bootstrap-4-lit-element-37c857a6bcca. But generally there is a reason why React, Vuejs and others have a special Bootstrap library.
I've written some Bootstrap components during a job for my client but nothing complete or open-source.
It makes sense to write a proper Bootstrap library once Styles and Hooks are fully integrated into Seed. Until then I would suggest to use CSS-only frameworks like Bulma or WebComponent frameworks like https://www.fast.design/ (I didn't test fast but it should work).

@seanybaggins
Copy link

seanybaggins commented Oct 20, 2020

@MartinKavik Could this work within an electron application? I am guessing you would not get access to the file system because the framework is only designed to target wasm.

@MartinKavik
Copy link
Member

MartinKavik commented Oct 20, 2020

@seanybaggins
I haven't tried to integrate Seed into an Electron app, but I was able to write an Electron app with Elm and Typescript several years ago. So if I'm not wrong, the architecture is similar to a standard browser app - Seed/Elm is a "view + business logic" layer and Electron/Browser exposes some methods that allow "view" layer to do safe IO operations. So I think it should be doable.
(Similar architecture allows to write also serverless backend with WASM.)

Btw there are potential Electron alternatives:

@seanybaggins
Copy link

@MartinKavik. Thanks for the reply. Tauri looks pretty cool. Definitely something I will keep my eye on.

@runfalk
Copy link
Author

runfalk commented Oct 20, 2020

Thanks for the great pointers @MartinKavik and @flosse. I feel your replies answer my question pretty well.

If I, or someone else, do something with this, would you be interested in a PR for the official documentation?

@MartinKavik
Copy link
Member

If I, or someone else, do something with this, would you be interested in a PR for the official documentation?

Yes, PRs with examples or docs are very welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants