3 ms·
If one needs to write code like: `#{context}.lineTo(#{x}, #{height})` ...you're doing it wrong. Please do figure out a way to "automagically" make things
by nnq 13y ago
If one needs to write code like:
`#{context}.lineTo(#{x}, #{height})`
...you're doing it wrong. Please do figure out a way to "automagically" make things work without `...` or just don't bother.
`...` should be a last resort option for when you just need to do something that can't be done any other way, not something that should be peppered over the entire code.
- dham 13y agoYea. They have a canvas wrapper that this guy did not use so you don't have to do that. With that being said, this project https://github.com/rubys/ruby2js https://github.com/rubys/ruby2js is more appealing to me. Sure it doesn't pass more RubySpec tests than Rubinius like Opal does, but it works. The Angular interoperability is especially appealing to me. It also generates readable javascript.
- ylluminate 13y agoUse opal-browser (https://github.com/opal/opal-browser https://github.com/opal/opal-browser). Great stuff.
- Skoofoo 13y agoYou have to drop down to JavaScript at some point, though in practice you would not write this much JavaScript mixed with Ruby in an app. The joy of using Opal is having the JavaScript wrapped away in a module, letting you use pure Ruby for your app. The author used a lot of JavaScript here, likely for teaching purposes, but he could instead have used pure Ruby to interface with canvas using opal-browser. https://github.com/opal/opal-browser/blob/master/opal/browser/canvas.rb https://github.com/opal/opal-browser/blob/master/opal/browse...
- adambeynon 13y agoThe example in this post is definitely a bad example of inline js in Opal. This is better handled by the `Native` bridge class, or writing a wrapper for it. On the other hand, being able to drop down to native javascript anytime you like is a huge win.
- ylluminate 13y ago@adam maybe you can give us a tutorial on doing this properly? Opal is amazing and being able to wrap things like ImpactJS and other js libs is enormously powerful.
- isbadawi 13y agoCould you explain what is so offensive about using `...` here?
- bshimmin 13y agoIn 48 lines of code, he has 12 lines where he's evaluating JavaScript between backticks (and not all those 48 lines are significant). If you're having to do that much evaluation of raw JavaScript, then what is the point of using a compile-to-JS language at all? With CoffeeScript, I think I've "had" to use backticks all of about twice (I probably didn't actually have to, but it seemed easier at the time - I don't remember the exact circumstances). Also, as others have said, the JavaScript that this outputs is a real mess (in comparison with, say, CoffeeScript).
- nnq 13y agoI wouldn't mind the outputed javascript - it's unfair to compare it with coffeescript as cs is just a thin syntax layer whereas opal giver you all the goodies of rubyan oop (like, method_missing? :) ), so there is a price that needs to be paid for this. But having to drop to raw js everywhere kind of nulls the advantage. Just think of all the errors that a linter or parser could have caught, but now it can't, and on top of this add it to the inherent pain of debugging a transcompiled language and... not fun :| I liked the idea of ruby to js but this doesn't seem like an acceptable solution.