Class: Volt::Dependency
Instance Method Summary collapse
- #changed! ⇒ Object
- #depend ⇒ Object
-
#initialize ⇒ Dependency
constructor
A new instance of Dependency.
-
#remove ⇒ Object
Called when a dependency is no longer needed.
Constructor Details
#initialize ⇒ Dependency
Returns a new instance of Dependency.
32 33 34 |
# File 'lib/volt/reactive/dependency.rb', line 32 def initialize @dependencies = Set.new end |
Instance Method Details
#changed! ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/volt/reactive/dependency.rb', line 54 def changed! deps = @dependencies # If no deps, dependency has been removed return unless deps @dependencies = Set.new deps.each(&:invalidate!) end |
#depend ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/volt/reactive/dependency.rb', line 36 def depend # If there is no @dependencies, don't depend because it has been removed return unless @dependencies current = Computation.current if current added = @dependencies.add?(current) if added # puts "Added #{self.inspect} to #{current.inspect}" current.on_invalidate do # If @dependencies is nil, this Dependency has been removed @dependencies.delete(current) if @dependencies end end end end |
#remove ⇒ Object
Called when a dependency is no longer needed
66 67 68 69 |
# File 'lib/volt/reactive/dependency.rb', line 66 def remove changed! @dependencies = nil end |