Skip to content

Instantly share code, notes, and snippets.

View adambeynon's full-sized avatar

Adam Beynon adambeynon

View GitHub Profile
@adambeynon
adambeynon / opal_js.md
Last active August 29, 2015 13:55
Notes/summary from weekend discussion (Jan, 31).

Notes/summary from weekend discussion (Jan, 31).

Variables: nil, true, false, self

nil == null == undefined

nil   # => null
true  # => true
false # => false
.row
.col-md-8
%h2 Items
.col-md-3
%h2 Shopping List
= bind_unless cart_empty? do
%a.btn.btn-default#clear-cart(style="width: 50%")
= bind clear_title
require 'opal'
require 'sinatra'
get '/' do
<<-EOS
<!doctype html>
<html>
<head>
<script src="/assets/application.js"></script>
</head>
$window.setTimeout -> do
a = $document.createElement 'div'
a.innerHTML = "hi there"
$document.body.appendChild a
puts a.innerHTML
end, 0
Promise.new do |promise|
HTTP.get(url, :GET, opts) do |response|
if response.ok?
promise.resolve response
else
promise.reject response
end
end
end

The idea is that we are binding an attribute cart_empty on the current object to get updated when some remote attribute on some other object changes. This results in a method call current_obj.cart_empty = new_value.

bind(:cart_empty).to observe(@cart, :empty?)

bind(:cart_empty).to @cart.observe(:empty?)

bind :cart_empty, @cart.observe(:empty?)
RACSignal *nameSignal = [RACObserve(self, someManagedObject.name) distinctUntilChanged];
RAC(self, someTextField.text) = [nameSignal deliverOn:[RACScheduler mainThreadScheduler]];
signal = observe(self, "some_managed_object.name")
signal.on_value { |val| self.some_text_field.text = val }

Sending method no args

recv.foo
rb_send0(recv, 'foo');

function rb_send0(recv, mid) {
require 'opal-jquery/version'
if RUBY_ENGINE == "opal"
require 'opal-jquery/window'
require 'opal-jquery/document'
require 'opal-jquery/element'
require 'opal-jquery/event'
require 'opal-jquery/http'
require 'opal-jquery/kernel'
end
@adambeynon
adambeynon / bindings.rb
Created May 7, 2014 15:58
Opal Bound attributes + DOM Compiler
module Vienna
class BaseBinding
def initialize(view, context, node, attr)
@view = view
@context = context
@node = node
@attr = attr
setup_binding
end