Stupid idea, but lets just look at the benefits/costs
We compile a ruby call currently as:
recv.$foo(1, 2, 3);| [1, 2, 3, 4].each do |a| | |
| a | |
| end | |
| // [1, 2, 3, 4].$each($iter(function(a) { return a }, self)); | |
| Array.prototype.$each = function(block) { | |
| if (typeof(block) === 'function' && block._isBlock) { | |
| var block = block; | |
| } |
| /* | |
| class Foo | |
| # some method to handle bananas | |
| def do_it | |
| 42 | |
| end | |
| def and_this | |
| do_it | |
| end |
| # We want vienna to render our Product#show view... | |
| class ProductController < ApplicationController | |
| def show | |
| @product = Product.find(...) | |
| render :vienna => @product | |
| end | |
| end | |
| # The `vienna` renderer will look for a view (Vienna::View) subclass that |
| $iter(self, '$it', "should do something", ($TMP_1 = function() { | |
| return (1).$should()['$=='](2); | |
| }), self); | |
| class Array::Wrapper | |
| def self.inherited(subclass) | |
| real_subclass = Class.new(Array::Wrapper) | |
| %x{ | |
| subclass._proto = real_subclass._proto; | |
| subclass._alloc = real_subclass._alloc; | |
| subclass.$new = real_subclass.$new; | |
| subclass['$[]'] = real_subclass['$[]']; |
| # Class.new | |
| Foo = Class.new(Bar) do | |
| def woosh | |
| :kapow | |
| end | |
| end | |
| # Native.new | |
| LocalStorage = Native.new(`localStorage`) do | |
| def [](key) |
| Opal.register_metadata([ | |
| { | |
| "method": "Array#size", | |
| "file": "opal/array.rb", | |
| "line": 12, | |
| "source": "# This method.......\ndef size;....\nend" | |
| }, | |
| { | |
| "method": "Array#slice", |
| describe "Timeouts" do | |
| async "blah" do | |
| default_timeout 100 | |
| set_timeout(4000) do | |
| run_async { :ok } | |
| end | |
| end | |
| end |
| module JqueryRspecHelpers | |
| def stub_http(action, url, result) | |
| expect(HTTP).to receive(action).with(url).and_yield(result) | |
| end | |
| end | |
| describe User do | |
| describe ".current" do | |
| it "should make an http request for user details" do | |
| stub_http(:get, '/current_user', { "name" => "Fred", "admin" => true }) |