Sha256: 6d1ed1a5dbacc9a6257d2496a5ef3473530d9ed3547554c6e5b1fe738319f833

Contents?: true

Size: 648 Bytes

Versions: 21

Compression:

Stored size: 648 Bytes

Contents

module React
  
  class Observable

    def initialize(value, on_change = nil, &block)
      @value = value
      @on_change = on_change || block
    end

    def method_missing(method_sym, *args, &block)
      @value.send(method_sym, *args, &block).tap { |result| @on_change.call result }
    end

    def respond_to?(method, *args)
      if [:call, :to_proc].include? method
        true
      else
        @value.respond_to? method, *args
      end
    end
  
    def call(new_value)
      @on_change.call new_value
      @value = new_value
    end
    
    def to_proc
      lambda { |arg = @value| @on_change.call arg }
    end
  
  end
  
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
reactive-ruby-0.7.24 lib/reactive-ruby/observable.rb
reactive-ruby-0.7.23 lib/reactive-ruby/observable.rb
reactive-ruby-0.7.22 lib/reactive-ruby/observable.rb
reactive-ruby-0.7.21 lib/reactive-ruby/observable.rb
reactive-ruby-0.7.20 lib/reactive-ruby/observable.rb
reactive-ruby-0.7.19 lib/reactive-ruby/observable.rb
reactive-ruby-0.7.18 lib/reactive-ruby/observable.rb
reactive-ruby-0.7.17 lib/reactive-ruby/observable.rb
reactive-ruby-0.7.16 lib/reactive-ruby/observable.rb
reactive-ruby-0.7.15 lib/reactive-ruby/observable.rb
reactive-ruby-0.7.14 lib/reactive-ruby/observable.rb
reactive-ruby-0.7.13 lib/reactive-ruby/observable.rb
reactive-ruby-0.7.12 lib/reactive-ruby/observable.rb
reactive-ruby-0.7.11 lib/reactive-ruby/observable.rb
reactive-ruby-0.7.10 lib/reactive-ruby/observable.rb
reactive-ruby-0.7.8 lib/reactive-ruby/observable.rb
reactive-ruby-0.7.7 lib/reactive-ruby/observable.rb
reactive-ruby-0.7.6 lib/reactive-ruby/observable.rb
reactive-ruby-0.7.5 lib/reactive-ruby/observable.rb
reactive-ruby-0.7.4 lib/reactive-ruby/observable.rb