Class: ReactiveGenerator
- Defined in:
- lib/volt/reactive/reactive_generator.rb
Class Method Summary collapse
-
.find_reactives(object) ⇒ Object
Recursively loop through the data, returning a list of all reactive values in the hash, array, etc..
-
.from_hash(hash, skip_if_no_reactives = false) ⇒ Object
Takes a hash and returns a ReactiveValue that depends on any ReactiveValue’s inside of the hash (or children).
Class Method Details
.find_reactives(object) ⇒ Object
Recursively loop through the data, returning a list of all reactive values in the hash, array, etc..
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/volt/reactive/reactive_generator.rb', line 25 def self.find_reactives(object) found = [] if object.reactive? found << object found += find_reactives(object.cur) elsif object.is_a?(Array) object.each do |item| found += find_reactives(item) end elsif object.is_a?(Hash) object.each_pair do |key, value| found += find_reactives(key) found += find_reactives(value) end end return found.flatten end |
.from_hash(hash, skip_if_no_reactives = false) ⇒ Object
Takes a hash and returns a ReactiveValue that depends on any ReactiveValue’s inside of the hash (or children).
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/volt/reactive/reactive_generator.rb', line 4 def self.from_hash(hash, skip_if_no_reactives=false) reactives = find_reactives(hash) if skip_if_no_reactives && reactives.size == 0 # There weren't any reactives, we can just use the hash return hash else # Create a new reactive value that listens on all of its # child reactive values. value = ReactiveValue.new(hash) reactives.each do |child| value.reactive_manager.add_parent!(child) end return value end end |