Class: Volt::ReactiveHash
- Inherits:
-
Object
show all
- Defined in:
- lib/volt/reactive/reactive_hash.rb
Instance Method Summary
collapse
Constructor Details
#initialize(values = {}) ⇒ ReactiveHash
Returns a new instance of ReactiveHash.
5
6
7
8
9
|
# File 'lib/volt/reactive/reactive_hash.rb', line 5
def initialize(values = {})
@hash = values
@deps = HashDependency.new
@all_deps = Dependency.new
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
TODO: We should finish off this class for reactivity
17
18
19
20
21
|
# File 'lib/volt/reactive/reactive_hash.rb', line 17
def method_missing(method_name, *args, &block)
@all_deps.depend
@hash.send(method_name, *args, &block)
end
|
Instance Method Details
11
12
13
14
|
# File 'lib/volt/reactive/reactive_hash.rb', line 11
def ==(val)
@all_deps.depend
@hash == val
end
|
23
24
25
26
27
|
# File 'lib/volt/reactive/reactive_hash.rb', line 23
def [](key)
@deps.depend(key)
@hash[key]
end
|
#[]=(key, value) ⇒ Object
29
30
31
32
33
34
|
# File 'lib/volt/reactive/reactive_hash.rb', line 29
def []=(key, value)
@deps.changed!(key)
@all_deps.changed!
@hash[key] = value
end
|
41
42
43
44
45
|
# File 'lib/volt/reactive/reactive_hash.rb', line 41
def clear
@hash.each_pair do |key, _|
delete(key)
end
end
|
#delete(key) ⇒ Object
36
37
38
39
|
# File 'lib/volt/reactive/reactive_hash.rb', line 36
def delete(key)
@deps.delete(key)
@hash.delete(key)
end
|
47
48
49
|
# File 'lib/volt/reactive/reactive_hash.rb', line 47
def inspect
"#<ReactiveHash #{@hash.inspect}>"
end
|