These are chat archives for opal/opal

2nd
Oct 2014
Eric West
@edubkendo
Oct 02 2014 14:45
@georgeu2000 All it really took to sell me was being able to operate on collections of data using the Enumerable methods
It's infinitely nicer than using javascripts nasty for loops
Manipulating collections of data is such a huge, enormous part of what we do all the time, anything that makes that better/easier/cleaner is a big win
George
@georgeu2000
Oct 02 2014 14:53
@edubkendo - I see.
Adam Beynon
@adambeynon
Oct 02 2014 14:55
georgeu2000 - In relation to your sharing code question, I share quite a few "model validator" classes between the server and client, and that works really nicely. Both also use rspec for tests, so running those in the client as well is really reassuring
apart from that, the backend is just serving up JSON, and then the client uses Vienna::View for rendering the HAML templates
George
@georgeu2000
Oct 02 2014 15:17
@adambeynon - Cool. Do you write your own "model validator" classes?
Elia Schito
@elia
Oct 02 2014 15:18
@adambeynon please paste here one of them (or in a gist) I’m interested too :)
George
@georgeu2000
Oct 02 2014 15:18
Or use AR or other DB validators?
Adam Beynon
@adambeynon
Oct 02 2014 15:21
They used to be AR validations, but I extracted them because I also wanted them client side
e.g. the one Im working to refactor now just validates dates for a Holiday Reservation
so, I just implement them as simple Ruby classes..
and for Rails, add them inside a before_update call
and for vienna, I have similar callback features
(I dont like packing everything inside the model implementation as much as I can)
Elia Schito
@elia
Oct 02 2014 15:24
extracting validations makes much sense, especially considering different context (same as what happened with strong parameters)
Adam Beynon
@adambeynon
Oct 02 2014 15:25
agreed. One thing I've also really got into recently is the Interactor pattern with rails controllers
converted most controllers to use that
so controller testing now is pretty much zero
even PORO make more sense
George
@georgeu2000
Oct 02 2014 20:03
How can I tell if the code is running in Javascript?
Is there a var or method that exposes the environment?
Adam Beynon
@adambeynon
Oct 02 2014 20:18
RUBY_ENGINE == "opal"
Elia Schito
@elia
Oct 02 2014 21:14
@adambeynon interactor looks good, but I’d like to see one of the validators
Adam Beynon
@adambeynon
Oct 02 2014 21:21
elia: well, the one Im about to start rewriting: https://gist.github.com/adambeynon/dd86f787f53e0a878f40
that doesnt currently work under opal/vienna...
its also quite tricky to make work under both :(
Elia Schito
@elia
Oct 02 2014 21:23
thanks, I was curious about error handling / storage
dates uh?
Adam Beynon
@adambeynon
Oct 02 2014 21:31
dealing with dates has ruined most of my day so far...
Elia Schito
@elia
Oct 02 2014 21:34
sorry about that :)
Adam Beynon
@adambeynon
Oct 02 2014 21:35
elia: do you use Vienna::Model at all?
George
@georgeu2000
Oct 02 2014 21:37
@adambeynon - Thanks.
Elia Schito
@elia
Oct 02 2014 21:38
I usually end up using plain classes, and mostly the Vienna inspired View class from this post
elia @elia is fetching the link
@adambeynon on current project opal is off limits (seems to be at least)
Adam Beynon
@adambeynon
Oct 02 2014 21:42
ahhh yeah, I remember reading that post
I think im starting to need a much more complete Model setup for my apps..
lots of rails inspired callbacks, old attribute values etc
might make a new repo
and keep Vienna::Model simpler..
Loïc Boutet
@loicboutet
Oct 02 2014 21:43
Isn't what he describes in this post pretty much the same as vienna::view?
Elia Schito
@elia
Oct 02 2014 21:43
you said AR callbacks? weren’t those bad? :P
@loicboutet pretty much, probably a stripped down version
Loïc Boutet
@loicboutet
Oct 02 2014 21:44
ok ^^
Adam Beynon
@adambeynon
Oct 02 2014 21:44
lol, yes they are. but sometimes (just sometimes ;) ) they make sense
"sometimes"
Elia Schito
@elia
Oct 02 2014 21:45
agreed ;)
Loïc Boutet
@loicboutet
Oct 02 2014 21:45
I must admit I did not use the vienna::model at the moment, mainly because I always have a rails/sintra back end
and I'm still figuring out what's the best way to integrate :)
How do you guys do usually?
Elia Schito
@elia
Oct 02 2014 23:15
@adambeynon @meh we’re official AltRuby :P
http://youtu.be/5FLrKg-b6o8?t=7m47s