class Volt::ReactiveHash
Public Class Methods
new(values = {})
click to toggle source
# File lib/volt/reactive/reactive_hash.rb, line 5 def initialize(values = {}) @hash = values @deps = HashDependency.new @all_deps = Dependency.new end
Public Instance Methods
==(val)
click to toggle source
# File lib/volt/reactive/reactive_hash.rb, line 11 def ==(val) @all_deps.depend @hash == val end
[](key)
click to toggle source
# File lib/volt/reactive/reactive_hash.rb, line 26 def [](key) @deps.depend(key) @hash[key] end
[]=(key, value)
click to toggle source
# File lib/volt/reactive/reactive_hash.rb, line 32 def []=(key, value) @deps.changed!(key) @all_deps.changed! @hash[key] = value end
blank?()
click to toggle source
# File lib/volt/reactive/reactive_hash.rb, line 16 def blank? @hash.blank? end
clear()
click to toggle source
# File lib/volt/reactive/reactive_hash.rb, line 45 def clear # Don't use .each_key so we get a clone here since we are # deleting as we go. @hash.keys.each do |key| delete(key) end @all_deps.changed! end
delete(key)
click to toggle source
# File lib/volt/reactive/reactive_hash.rb, line 39 def delete(key) @deps.delete(key) @all_deps.changed! @hash.delete(key) end
inspect()
click to toggle source
# File lib/volt/reactive/reactive_hash.rb, line 72 def inspect @all_deps.depend "#<#{self.class.name} #{@hash.inspect}>" end
method_missing(method_name, *args, &block)
click to toggle source
TODO: We should finish off this class for reactivity
# File lib/volt/reactive/reactive_hash.rb, line 21 def method_missing(method_name, *args, &block) @all_deps.depend @hash.send(method_name, *args, &block) end
replace(hash)
click to toggle source
# File lib/volt/reactive/reactive_hash.rb, line 55 def replace(hash) clear hash.each_pair do |key, value| self[key] = value end end
to_h()
click to toggle source
# File lib/volt/reactive/reactive_hash.rb, line 63 def to_h @all_deps.depend @hash end
to_json()
click to toggle source
# File lib/volt/reactive/reactive_hash.rb, line 68 def to_json @hash.to_json end