Skip to content

Instantly share code, notes, and snippets.

@francescoagati
Last active December 30, 2015 02:09
Show Gist options
  • Save francescoagati/7760541 to your computer and use it in GitHub Desktop.
Save francescoagati/7760541 to your computer and use it in GitHub Desktop.
wrapping Bacon.js Streams with Opal
Bacon = Native `Bacon`
class ProxyStream
def initialize(wrapped)
@wrapped = wrapped
end
def method_missing(method,*args)
Bacon.fromCallback do |cb|
@wrapped.send(method,*args) do |response|
cb.call response
end
end
end
end
Rest = ProxyStream.new HTTP
ip = Rest.get('http://ip.jsontest.com/?callback=?',dataType:'json').map { |response| response.json[:ip]}
time = Rest.get('http://date.jsontest.com/',dataType:'json').map {|response| response.json[:time] }
Bacon.combineTemplate(ip:ip,time:time).onValue do |response|
response = Native(response)
p response.ip
p response.time
end
@francescoagati
Copy link
Author

Bacon.Observable.prototype.onValue = function(f) { old.apply(this,[function(value) { f("".$Native(value)) }]) }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment