Module: Volt::ReactiveAccessors::ClassMethods
- Defined in:
- lib/volt/reactive/reactive_accessors.rb
Instance Method Summary collapse
- #reactive_accessor(*names) ⇒ Object
-
#reactive_reader(*names) ⇒ Object
Create a method to read a reactive value from an instance value.
- #reactive_writer(*names) ⇒ Object
Instance Method Details
#reactive_accessor(*names) ⇒ Object
31 32 33 34 |
# File 'lib/volt/reactive/reactive_accessors.rb', line 31 def reactive_accessor(*names) reactive_reader(*names) reactive_writer(*names) end |
#reactive_reader(*names) ⇒ Object
Create a method to read a reactive value from an instance value. If it is not setup, create it so it can be updated through the reactive value at a later point.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/volt/reactive/reactive_accessors.rb', line 7 def reactive_reader(*names) names.each do |name| var_name = :"@#{name}" define_method(name.to_sym) do value = instance_variable_get(var_name) __reactive_dependency_get(name).depend value end end end |
#reactive_writer(*names) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/volt/reactive/reactive_accessors.rb', line 20 def reactive_writer(*names) names.each do |name| var_name = :"@#{name}" define_method("#{name}=") do |new_value| instance_variable_set(var_name, new_value) __reactive_dependency_get(name).changed! end end end |