Class: RVar
- Inherits:
-
Object
- Object
- RVar
- Defined in:
- lib/bull/reactive_var.rb
Constant Summary collapse
- @@ticket =
0
- @@group =
nil
- @@backup =
[]
Instance Attribute Summary collapse
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #add(block) ⇒ Object
- #add_form(form) ⇒ Object
-
#initialize(value) ⇒ RVar
constructor
A new instance of RVar.
- #remove(id) ⇒ Object
- #remove_form(form) ⇒ Object
Constructor Details
#initialize(value) ⇒ RVar
Returns a new instance of RVar.
10 11 12 13 14 |
# File 'lib/bull/reactive_var.rb', line 10 def initialize value @value = value @blocks = {} @forms = Set.new end |
Instance Attribute Details
#value ⇒ Object
Returns the value of attribute value.
5 6 7 |
# File 'lib/bull/reactive_var.rb', line 5 def value @value end |
Class Method Details
.raise_if_dirty ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/bull/reactive_var.rb', line 16 def self.raise_if_dirty @@group = Set.new @@backup = [] raised = false begin yield rescue @@backup.each do |v| v.call end raised = true raise #else # @@group.each do |blk| # blk.call # end ensure if !raised @@group.each do |blk| blk.call end end @@group = nil @@backup = [] end end |
.rgrouping ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/bull/reactive_var.rb', line 43 def self.rgrouping @@group = Set.new yield @@group.each {|blk| blk.call} @@group = nil @@backup = [] end |
Instance Method Details
#add(block) ⇒ Object
65 66 67 68 69 70 |
# File 'lib/bull/reactive_var.rb', line 65 def add block id = @@ticket @@ticket += 1 @blocks[id] = block id end |
#add_form(form) ⇒ Object
76 77 78 |
# File 'lib/bull/reactive_var.rb', line 76 def add_form form @forms.add form end |
#remove(id) ⇒ Object
72 73 74 |
# File 'lib/bull/reactive_var.rb', line 72 def remove id @blocks.delete id end |
#remove_form(form) ⇒ Object
80 81 82 |
# File 'lib/bull/reactive_var.rb', line 80 def remove_form form @forms.delete form end |