-
-
Notifications
You must be signed in to change notification settings - Fork 324
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Allow customization of built-in IDOM client #253
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
Comments
This came up again: #400 |
@brentbaum The least brittle option I've been able to think of is to try and load a <script>
import("/custom.js")
.then(() => console.log("Loaded custom.js script"))
.catch(() => console.log("No custom.js script found"));
</script> This would allow you to serve a from tempfile import NamedTemporaryFile
from sanic import Sanic
import idom
from idom.server.sanic import PerClientStateServer
temp = NamedTemporaryFile()
open(temp.name, "w+").write("document.title = 'Hello World';") # set the page title on load
app = Sanic()
app.static("/custom.js", temp.name, name="custom_js", content_type="text/javascript")
HelloWorld = idom.component(lambda: idom.html.h1("Hello World"))
PerClientStateServer(HelloWorld, app=app).run("127.0.0.1", 8000) Thoughts on this approach? |
I suppose some of these details could be abstracted away by making this a import idom
idom.run(MyComponent, server_config={"custom_js": "path/to/custom.js"}) |
I like the second approach quite a bit! The killer here is that React doesn't allow you to render and execute <script> tags by default - I tried for an hour yesterday to get a simple |
@brentbaum what do you think about making something like this into a component that you'd just include in your layout? from idom import Javascript
my_javascript = Javascript("path/to/my/script.js")
@idom.component
def MyApp():
return idom.html.div(my_script, ...) |
Fixes: #253 This accomplished by mildly abusing the custom component system. In short, we create a no-op module interface so IDOM will load the file, but won't actually do anything afterwards
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
It would be great if it were possible to do some basic templating on the IDOM client web page. Without this, if you want to include custom styles or JS in the
<head />
of the HTML markup you have to completely re-create the client.The alternative I suppose would be to make it easier to create custom clients. I'm not entirely sure what that would look like though. Maybe just a cookie cutter repo? The downside there of course is that you can't automatically update the repo if you update the template.
The text was updated successfully, but these errors were encountered: