opal -R server my_code.rb
trick that you mentioned, I am getting Empty reply from server
for http://localhost:3000
What am I missing?
pbpaste | opal -R server
, does it work that way?
-r
requires)
node debug ...
. Thanks you so much :)
ruby -run -e httpd . -p 3000
) It's gotta be something in that server cli runner, but wth? I'm not having a good day today, one mystery after another :smile: Thought maybe it's thin, but the same result with webrick. Better luck tomorrow perhaps.
vagrant ssh curl localhost:3000
)
$$.setTimeout(-> { callback code }, 500)
delay
in opal-browser that takes a timeout and a block
opal-browser
dependency in opal-jquery
's gemspec
opal-browser
is a wrapper for a native browser functionality
object.inspect
return the object and it's attributes? only the object itself?
lets say I'm doing:
Request.get("/api/forms/tree/#{id}") do |result|
result.on :success do |response|
puts response.inspect
end
end
it only displays #<Request:0x2d6>
and nothing else I have to do puts response.instance_variables
to see anything and I'd still have to iterate over each one to find the value of each attribute (if they are a public attribute at all).
require 'browser/http'
class Request
class << self
%w{get post delete put patch head}.each do |http_verb|
define_method http_verb do |*args,&block|
self.make(http_verb,*args,&block)
end
end
def make(type,url,payload=nil, &block)
data_hash = {dataType: 'json'}
data_hash.merge!({payload: payload.to_json})if payload
Browser::HTTP.send type, url, *data_hash do |response|
puts response.inspect
# results = [response.status_code,response.json]
if block_given?
block.call(*response)
else
response
end
end
end
end
end
def handle_validation event
value = event.target.value
::Request.post("/api/forms/validate/#{Form.tree[:meta][:id]}",format_validation(event)) do |result|
result.on :success do |response|
self.tree = response.json
set_pair_validation_field_value true, value
set_validation_messages 'correct', false
end
result.on :failure do |response|
set_pair_validation_field_value false
set_validation_messages response.json[:data][:message], true
end
end
end
unexpected token at 'dataType=json&payload=%7B%22meta%22%3A%7B%22context%22%3A%22form.validation.check%22%2C%20%22target%22%3A%22form.account%22%7D%2C%20%22data%22%3A%7B%22field%22%3A%22user%20name%22%2C%20%22value%22%3A%22%22%7D%7D':
format_validation
does is just make sure it's in the correct hash structure, nothing more
data_hash
)
Hash
to the send
method, Browser::HTTP::Request
encodes it as "key1=value1&key2=value2" (while you need json). The solution is: encode your data with to_json
manually before passing it to Browser::HTTP.send
hash[:payload]
is a JSON string
Browser::HTTP.post
returns a promise and not the request object?Browser::HTTP.post
only takes a url and the payload but not the payload type, I don't see how to set the content_type
when I don't get access to the request object directly nor can you pass it into the request object.
when I do:
Request.get("/api/forms/tree/#{id}") do |result|
puts result
end
I get a promise not a request object is what I meant
HTTP.post(url, hash) { content_type 'application/json' }.then { |result }
NoMethodError: undefined method 'content_type=' for #<Request:0x2d6>
content_type
not content_type=
HTTP.post(..) { |r| r.content_type 'application/json' }
or `HTTP.post(..) { content_type 'application/json' }
$$s
is currently used for the inheret self of a block
$$s
remains, but instead of the common check being self = $$s || this
, it becomes self = $$m.self || $$s || this
$$m.self
?
$m
or $meta
or $metadata
in the prelude
prepend
?
@/all 0.9.0.beta2 is out! here's the new stuff from beta1: https://gist.github.com/elia/72872e47b23423228f09
(would post the rubygems tweet but apparently I have some connection issues ๐ )