Sha256: b5cce6130e8a09562927aad1a3974861fca775c891ffc4cce8116cfc15d90dd5

Contents?: true

Size: 633 Bytes

Versions: 36

Compression:

Stored size: 633 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 @value }
    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

36 entries across 36 versions & 4 rubygems

Version Path
hyper-store-0.99.6 lib/react/observable.rb
hyper-store-0.99.5 lib/react/observable.rb
hyper-store-0.99.4 lib/react/observable.rb
hyper-store-0.99.3 lib/react/observable.rb
hyper-store-0.99.2 lib/react/observable.rb
hyper-store-0.99.1 lib/react/observable.rb
hyper-store-0.99.0 lib/react/observable.rb
hyper-store-1.0.0.lap28 lib/react/observable.rb
hyper-store-0.2.3 lib/react/observable.rb
hyper-store-0.2.2 lib/react/observable.rb
hyper-store-0.2.1 lib/react/observable.rb
hyper-store-0.2.0 lib/react/observable.rb
hyper-react-0.11.0 lib/react/observable.rb
hyper-react-0.10.0 lib/react/observable.rb
reactrb-0.9.0 lib/react/observable.rb
reactrb-0.8.8 lib/react/observable.rb
reactrb-0.8.7 lib/react/observable.rb
reactrb-0.8.6 lib/react/observable.rb
reactrb-0.8.5 lib/react/observable.rb
reactrb-0.8.4 lib/react/observable.rb