Sha256: 3547b892b0237b85a25231a4d26e337042a4a3648899aaaa9d6176353797c12a

Contents?: true

Size: 793 Bytes

Versions: 14

Compression:

Stored size: 793 Bytes

Contents

require 'volt/reactive/hash_dependency'

class ReactiveHash
  def initialize(values={})
    @hash = values
    @deps = HashDependency.new
    @all_deps = Dependency.new
  end

  def ==(val)
    @all_deps.depend
    @hash == val
  end

  # TODO: We should finish off this class for reactivity
  def method_missing(method_name, *args, &block)
    @all_deps.depend

    return @hash.send(method_name, *args, &block)
  end

  def [](key)
    @deps.depend(key)

    return @hash[key]
  end

  def []=(key, value)
    @deps.changed!(key)
    @all_deps.changed!

    @hash[key] = value
  end

  def delete(key)
    @deps.delete(key)
    @hash.delete(key)
  end

  def clear
    @hash.each_pair do |key,_|
      delete(key)
    end
  end

  def inspect
    "#<ReactiveHash #{@hash.inspect}>"
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
volt-0.8.14 lib/volt/reactive/reactive_hash.rb
volt-0.8.13 lib/volt/reactive/reactive_hash.rb
volt-0.8.11 lib/volt/reactive/reactive_hash.rb
volt-0.8.10 lib/volt/reactive/reactive_hash.rb
volt-0.8.9 lib/volt/reactive/reactive_hash.rb
volt-0.8.8 lib/volt/reactive/reactive_hash.rb
volt-0.8.7 lib/volt/reactive/reactive_hash.rb
volt-0.8.6 lib/volt/reactive/reactive_hash.rb
volt-0.8.5 lib/volt/reactive/reactive_hash.rb
volt-0.8.4 lib/volt/reactive/reactive_hash.rb
volt-0.8.3 lib/volt/reactive/reactive_hash.rb
volt-0.8.2 lib/volt/reactive/reactive_hash.rb
volt-0.8.1 lib/volt/reactive/reactive_hash.rb
volt-0.8.0 lib/volt/reactive/reactive_hash.rb