These are chat archives for opal/opal

12th
Nov 2015
Ilya Bylich
@iliabylich
Nov 12 2015 15:17
Does opal have an issue with method dispatching in Module -> Class chain? I have a method method1 for both Class and Module. When I write Module.new.method1 opal always invokes a method for Class. Is it a know problem or should I create an issue on github?
Elia Schito
@elia
Nov 12 2015 15:18
@iliabylich fire the issue, without a full example I may misunderstand the problem :)
Ilya Bylich
@iliabylich
Nov 12 2015 15:18
I've made a workaround with joining this method into a single one + inline check if self.is_a?(Class) for running a correct sub-method
@elia ok, thanks
Elia Schito
@elia
Nov 12 2015 15:22
thank you!
giuan
@giuan
Nov 12 2015 16:02

I tried to require a file, but with the opal runner it doesn't work.

# all work with ruby; all doesn't with opal
# require_relative 'lib/hello'
 require_relative './lib/hello.rb'
# require './lib/hello'
# require './lib/hello.rb'
print_hello

I run with $ opal main.rb
I guess that with opal require search only the gems.
Can anyone help me?

Elia Schito
@elia
Nov 12 2015 16:06
@giuan try opal -I. main.rb
Martin Becker
@Thermatix
Nov 12 2015 16:09
part of my app will have file uploads (to s3) but to ensure file integrity I want to hash the file (md5) and use that as the file name and reference to the file in s3, then check if the file made it without issues by checking the hash against the MD5 header that AWS s3 sends to check for integrity. Is it a good idea/viable to MD5 hash (using crypto-js) on the front end for the use of file integrity checking?
Martin Becker
@Thermatix
Nov 12 2015 18:02
you can ignore the last chat message, I've decided to do it but, can I have a link to an example to implementing promises?
Elia Schito
@elia
Nov 12 2015 18:20
@Thermatix there s a blog post on them on opalrb.org
Martin Becker
@Thermatix
Nov 12 2015 18:24
it shows how to use them, not implement them for something, unless I misread it?
Elia Schito
@elia
Nov 12 2015 18:34
Uhm maybe you can have a look at how they're used in opal-jquery
meh.
@meh
Nov 12 2015 18:35
Thermatix, all you need to do is Promise.new, return that promise, and call #resolve or #reject in your callback
Ryan Stout
@ryanstout
Nov 12 2015 19:20
@meh any plans to change Promise so it doesn't give you the "a promise has already been chained" message?
(just curious)
meh.
@meh
Nov 12 2015 19:30
ryanstout, I'm personally kind of against it because it complicates the code and isn't compatible with the promise standard
ryanstout, but feel free to change my mind :)
Jamie Gaskins
@jgaskins
Nov 12 2015 19:30
@meh You mean the JS Promise standard?
meh.
@meh
Nov 12 2015 19:30
jgaskins, yes
the A+ one
unsure if there were new ones that allow multiple thens
if there are, you already changed my mind :P
Ryan Stout
@ryanstout
Nov 12 2015 19:36
@meh yea, I think pretty much every promise lib out there in JS land does it
its a pretty common use case (at least for me)
meh.
@meh
Nov 12 2015 19:37
ryanstout, really?
Ryan Stout
@ryanstout
Nov 12 2015 19:37
yea
@jgaskins you've needed it also right?
I started trying to change https://github.com/lgierth/promise.rb to be compatible with your promise's api, but ran into a few issues.
anyway, not complaining, just was curious if you were interested in changing it. If not, I'll probably need to write my own or modify something else. In volt there's a lot of cases where it needs to be able to chain multiple times.
Jamie Gaskins
@jgaskins
Nov 12 2015 19:49
@ryanstout Yep :-) opal/opal#1142
@meh I can confirm what @ryanstout said about other promises allowing multiple then calls. For example, there's a difference between p.then.catch and p.then; p.catch. The first one can call .catch if a failure occurs anywhere in the chain, but the second catch won't be triggered if the failure occurs inside the then.
meh.
@meh
Nov 12 2015 19:52
ryanstout, jgaskins, fine, you've changed my mind
Ryan Stout
@ryanstout
Nov 12 2015 19:53
@meh not sure if it makes things easier, but that promise.rb library has a nice clean implementation.
it had a bit different api, and for some reason raised exceptions through on failure
giuan
@giuan
Nov 12 2015 21:33
@elia opal -I. main.rb doesn't work!
But if i copy the file hello.rb in the gems/opal/stdlib it works.
I'm using opal 9 beta 2 (i tried also with opal 0.8)
meh.
@meh
Nov 12 2015 21:51
giuan, where is hello.rb?
@ryanstout @jgaskins anything against the non-checking then/etc being banged version?
I'd still like to have a checked version
or do you think that's useless?
Ryan Stout
@ryanstout
Nov 12 2015 21:54
@meh you mean having .then! which would raise an error if its already chained?
meh.
@meh
Nov 12 2015 21:54
ryanstout, no, the other way around
Ryan Stout
@ryanstout
Nov 12 2015 21:54
ah
usually the bang version raises an error :-)
meh.
@meh
Nov 12 2015 21:54
or is an "unsafe" version
or anything really :P
Ryan Stout
@ryanstout
Nov 12 2015 21:54
yea
meh.
@meh
Nov 12 2015 21:54
the rationale is
1) it won't change the API, so no possible breaking for whatever reason
2) if you're doing double thenning, you're already using a variable, so it doesn't make the chaining ugly/weird
3) you know in the code you're using multiple thenning
@Thermatix by the way I just noticed there's actually documentation on providing APIs using promises in promise.rb inline-doc
Ryan Stout
@ryanstout
Nov 12 2015 21:59
@meh so let me explain my use case, that might make it clearer. In volt we have methods like: store.posts.first, which returns a promise. Sometimes you'll assign that promise to an instance variable or something, then have other methods that use that Promise.
that lets people setup things using the promise before it resolves
which is common
like when bindings render
each of the bindings resolves the value if its a promise
meh.
@meh
Nov 12 2015 22:00
ryanstout, sounds like it wouldn't hurt too much then to do things like I said
ryanstout, it just sounds weird to me that a promise would resolve to multiple things at once
Ryan Stout
@ryanstout
Nov 12 2015 22:09
@meh thats how all of the other promise libs do it though
I'll have to change a bunch of things in volt to make it use .then!
meh.
@meh
Nov 12 2015 22:10
wouldn't it not work in the first place tho?
Ryan Stout
@ryanstout
Nov 12 2015 22:10
yea, but right now people are just getting errors
its like the number one issue people have in volt right now
meh.
@meh
Nov 12 2015 22:10
ryanstout, I'm not convinced :D
Ryan Stout
@ryanstout
Nov 12 2015 22:10
ok, fair enough
meh.
@meh
Nov 12 2015 22:11
nah, I'm making it the opposite
Ryan Stout
@ryanstout
Nov 12 2015 22:11
sorry, are you saying you'll do .then! to raise an exception :-)
meh.
@meh
Nov 12 2015 22:11
yes
Ryan Stout
@ryanstout
Nov 12 2015 22:12
cool, thanks!
I do understand though if you don't want to, your call
but it would help me out quite a bit to have .then do multiple
meh.
@meh
Nov 12 2015 22:12
ryanstout, nah, it comes down to personal preference here, and since there are more people using volt than being pedantic like me, I'll go for the least annoying for the most people
Ryan Stout
@ryanstout
Nov 12 2015 22:47
thanks
meh.
@meh
Nov 12 2015 22:50
now if I could figure out why this happened I'd be happier
this wasn't failing before, and the #then changes shouldn't affect it
meh.
@meh
Nov 12 2015 23:09
ah I think I get it