This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'perpetuity/postgres' | |
require 'time' # Gets around a bug I found while writing this. | |
require 'pp' | |
module AttributeAssignment | |
def initialize attributes={} | |
attributes.each do |attr, value| | |
instance_variable_set "@#{attr}", value | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Router | |
def navigate_to path | |
current_targets = targets_for_path(current_path) | |
new_targets = targets_for_path(path) | |
(current_targets - new_targets).each do |from_target| | |
if from_target.respond_to?(:will_transition_from) | |
from_target.will_transition_from | |
end | |
end | |
(new_targets - current_targets).each do |to_target| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'clearwater/component' | |
require 'google_map_container' | |
class Foo | |
include Clearwater::Component | |
def render | |
GoogleMapContainer.new( | |
height: 500, | |
width: 500, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'browser/animation_frame' | |
require 'hook' | |
class GoogleMapRenderer | |
include Hook | |
def initialize(latitude: 0, longitude: 0, zoom: 13) | |
@latitude = latitude | |
@longitude = longitude | |
@zoom = zoom |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'opal' | |
def fib n | |
return n if n < 2 | |
fib(n - 1) + fib(n - 2) | |
end | |
%x{ | |
var fib = function(n) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'set' | |
class Model | |
def self.attributes *attrs | |
@attributes ||= Set.new | |
attr_reader *attrs | |
@attributes += attrs | |
end | |
def initialize attributes={} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'clearwater/component' | |
require 'clearwater/cached_render' | |
module Dispatcher | |
class Driver | |
include Clearwater::Component | |
include Clearwater::CachedRender | |
attr_reader :driver, :orders |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'opal' | |
require 'clearwater' | |
require 'clearwater/cached_render' | |
require 'grand_central' | |
class Todo | |
attr_reader :id, :description, :timestamp | |
def initialize attributes={} | |
@id = attributes.fetch(:id) { rand(1 << 31) } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyComponent | |
include Clearwater::Component | |
attr_reader :market, :detail_view | |
def initialize(market, detail_view: nil) | |
@market = market | |
@detail_view = detail_view | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Router | |
def initialize | |
if `window.location.pushState === undefined` | |
@location = FragmentLocation.new | |
if !has_fragment? | |
@location.copy_path_to_fragment! | |
end | |
else | |
@location = PushStateLocation.new |