Class: 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.
4
5
6
7
8
|
# File 'lib/volt/reactive/reactive_hash.rb', line 4
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
16
17
18
19
20
|
# File 'lib/volt/reactive/reactive_hash.rb', line 16
def method_missing(method_name, *args, &block)
@all_deps.depend
return @hash.send(method_name, *args, &block)
end
|
Instance Method Details
10
11
12
13
|
# File 'lib/volt/reactive/reactive_hash.rb', line 10
def ==(val)
@all_deps.depend
@hash == val
end
|
22
23
24
25
26
|
# File 'lib/volt/reactive/reactive_hash.rb', line 22
def [](key)
@deps.depend(key)
return @hash[key]
end
|
#[]=(key, value) ⇒ Object
28
29
30
31
32
33
|
# File 'lib/volt/reactive/reactive_hash.rb', line 28
def []=(key, value)
@deps.changed!(key)
@all_deps.changed!
@hash[key] = value
end
|
40
41
42
43
44
|
# File 'lib/volt/reactive/reactive_hash.rb', line 40
def clear
@hash.each_pair do |key,_|
delete(key)
end
end
|
#delete(key) ⇒ Object
35
36
37
38
|
# File 'lib/volt/reactive/reactive_hash.rb', line 35
def delete(key)
@deps.delete(key)
@hash.delete(key)
end
|
46
47
48
|
# File 'lib/volt/reactive/reactive_hash.rb', line 46
def inspect
"#<ReactiveHash #{@hash.inspect}>"
end
|