-
Notifications
You must be signed in to change notification settings - Fork 25
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
Issue compiling Opal for a backend-less web app #82
Comments
@andyhaskell Thanks for the report. I haven't looked much into Opal for a while because every release resulted in a much larger Opal JS runtime, so I've mostly kept Clearwater on Opal 0.x. With Opal 1.2, a baseline Clearwater app (specifically, the one generated with When they released 1.0 I did make a branch that worked with it, but I believe it was still using Sprockets v3 to compile, so that Clearwater's APIs are pretty stable (I've replicated features like React's hooks and Suspense using only things that Clearwater already provides), so a lot of its ecosystem wouldn't need to change much to support newer Opal versions, other than to relax the Opal version restriction and inject themselves into its asset load path with whatever the new API is. I'm happy to merge PRs to any gems that are needed to get Clearwater apps running on Opal 1.x:
And anything else one might want to use. For a minimal application, though, If you're new to Clearwater and just want to get started, the quickest way (other than the Clearwater Playground) is with
Then http://localhost:9292 will serve the Clearwater app. This does run a server (intended to let you build a Ruby API with Roda for the Clearwater app to consume, and in development also provides hot module reloading for the Clearwater app so you don't have to refresh the page to see your changes), but you can use |
Ah, that hypothesis makes sense. It looks like the version my Opal is on is 1.3.2, and my Ruby version is I'll try clearwater-roda out. If you do end up making a new branch, happy to take it for a spin. I was trying to use this for a browser extension, which is why the app was intended to be backend-less. By the way if you're ever in Boston, let me know and we can get some beers! |
Ah, interesting! I looked into making browser extensions with Clearwater, too! Turned out to be too many yaks to shave all at once, though. I was trying to avoid JS and the DOM APIs when I created Clearwater — joke's on me, in order to abstract them away I had to learn how they worked. I'll have a look and see if there's a good way to accommodate the compilation side of things here. That branch to support Opal 1.0 only applied to the JS runtime, so maybe we can support the compilation side with some metaprogramming.
Definitely! |
Oh, interesting. Looking into this and I totally misunderstood the problem you were reporting. It's compiling the server-side Ruby code to JS and the I was able to get this working, though! It did require adding a fix to my branch for Opal 1.x, but it was a tiny change. For your gem 'clearwater', github: 'clearwater-rb/clearwater', branch: 'allow-opal-1.0' And then instead of
And it showed my Clearwater app in the browser! This was the Ruby code: require 'clearwater'
require 'bowser'
class App
include Clearwater::Component
def render
div "hello world! The time now is #{Time.now}!"
end
end
app = Clearwater::Application.new(component: App.new, element: Bowser.document['#app'])
app.call If the |
Great to hear! Regarding -q, it looks like I am getting this error:
The -q option in Opal is documented as
and here's my
As I mentioned I'm pretty new to the Ruby ecosystem. Is there anything special I need to do after running |
Also, I noticed -q was introduced in Opal 1.1.0 (below is my output for 0.11.0). Would there be something else I would need to do in order to try out your branch of Clearwater in 0.x? Sorry for the noob questions
|
I had a whole explanation written out and then the page reloaded and it lost the whole thing. The short version of what I wrote was to try prefixing the
I forgot that the Ruby version manager I use automatically does the equivalent of
No apologies necessary. You ran into some legacy Ruby ecosystem stuff that confused Ruby devs for a long, long time. People have given entire conference talks on the gaps between Bundler and Rubygems. The Clearwater docs could probably be updated for the Opal CLI. I’m really glad it’s gotten easier to use and that you can compile an entire Clearwater app with it now. I tried it with Opal 0.x using |
Okay, I think I got it working on both Opal 1.3 CLI and Opal 0.10 via Sprockets. It looks like they changed the internal name of the property for the class prototype (if they now implement Ruby classes in terms of JS classes, that would explain this), so I've set it to check both. |
I am very glad to see, clearwater support the newest version opal + sprockets for now. anyway, diverge is not good for the community, especially, for a so mini community, i works on ruby 8~9 years, but, never see anyone use Opal, we need help together, otherwize, no one use Opal, no one use clearwater too soon. |
Hi @jgaskins, I don't really understand what happened (like, I think I now have a new version of Clearwater where the demo version of your app Works On My Machine, but RubyGems-wise, I am not sure how you had updated that gem). As I play with Clearwater some more, would you be interested in more contributions on Thanks again for the help last winter! Sincerely, &y |
the author mostly work with crystal-lang, this gem probably not so active maintain i guess. |
@andyhaskell Sorry, I got your DM the other day and then pulled this move: So thank you for following up! 💯 Docs contributions are always welcome! I believe they all live in @zw963 One of these days I should find the code where I got Clearwater frontends working nicely with Crystal backends. 😄 But the gem itself is relatively solid and I haven't needed to really maintain it much. I have proofs of concept for just about everything that came out of the React ecosystem (including hooks and suspense) without ever changing Clearwater internals because things like |
Hi, I recently found Opal and Clearwater, and wanted to try compiling your hello world example for use without a backend (the examples I've seen tend to all have servers). I am a newcomer to Opal and don't know Ruby's ecosystem in-depth (I'm doing Ruby just for fun and am a Gopher on the job), and came across an error when I tried to run a Clearwater app in my browser:
Here's the code I have.
My Gemfile:
My index.html:
The compilation command I was running:
opal -g clearwater -c app/application.rb > app.js
My Ruby code is the hello world example in your repo.
Like I said, I am pretty new to Ruby, so maybe this was just a misunderstanding on my part about gems or running Opal, but I was wondering what I should be doing to compile Opal if a web app doesn't talk to any server.
The text was updated successfully, but these errors were encountered: