Class: ObjectTracker
Constant Summary collapse
- @@queue =
{}
- @@cache_enabled =
false
- @@cache_version =
0
Class Method Summary collapse
- .cache_enabled ⇒ Object
- .cache_version ⇒ Object
- .clear_cache ⇒ Object
-
.process_queue ⇒ Object
Run through the queue and update the followers for each.
- .queue ⇒ Object
Instance Method Summary collapse
- #disable! ⇒ Object
- #enable! ⇒ Object
-
#initialize(main_object) ⇒ ObjectTracker
constructor
A new instance of ObjectTracker.
- #queue_update ⇒ Object
-
#remove_followers ⇒ Object
Remove follower.
- #update_followers ⇒ Object
Constructor Details
#initialize(main_object) ⇒ ObjectTracker
Returns a new instance of ObjectTracker.
20 21 22 23 24 |
# File 'lib/volt/reactive/object_tracker.rb', line 20 def initialize(main_object) # puts "NEW OBJECT TRACKER FOR: #{main_object.inspect}" @main_object = main_object @enabled = false end |
Class Method Details
.cache_enabled ⇒ Object
8 9 10 |
# File 'lib/volt/reactive/object_tracker.rb', line 8 def self.cache_enabled @@cache_enabled end |
.cache_version ⇒ Object
12 13 14 |
# File 'lib/volt/reactive/object_tracker.rb', line 12 def self.cache_version @@cache_version end |
.clear_cache ⇒ Object
16 17 18 |
# File 'lib/volt/reactive/object_tracker.rb', line 16 def self.clear_cache @@cache_version = (@@cache_version || 0) + 1 end |
.process_queue ⇒ Object
Run through the queue and update the followers for each
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/volt/reactive/object_tracker.rb', line 36 def self.process_queue # puts "PROCESS QUEUE: #{@@queue.size}" puts "Process #{@@queue.size} items" if OBJECT_TRACKER_DEBUG # TODO: Doing a full dup here is expensive? queue = @@queue.dup # Clear before running incase someone adds during @@queue = {} @@cache_enabled = true self.clear_cache queue.each_pair do |object_tracker,val| object_tracker.update_followers end @@cache_enabled = false end |
.queue ⇒ Object
26 27 28 |
# File 'lib/volt/reactive/object_tracker.rb', line 26 def self.queue @@queue end |
Instance Method Details
#disable! ⇒ Object
64 65 66 67 68 69 |
# File 'lib/volt/reactive/object_tracker.rb', line 64 def disable! puts "Disable OBJ Tracker" if OBJECT_TRACKER_DEBUG remove_followers @@queue.delete(self) @enabled = false end |
#enable! ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/volt/reactive/object_tracker.rb', line 56 def enable! unless @enabled puts "Enable OBJ Tracker" if OBJECT_TRACKER_DEBUG @enabled = true queue_update end end |
#queue_update ⇒ Object
30 31 32 33 |
# File 'lib/volt/reactive/object_tracker.rb', line 30 def queue_update puts "QUEUE UPDATE" if OBJECT_TRACKER_DEBUG @@queue[self] = true end |
#remove_followers ⇒ Object
Remove follower
92 93 94 95 96 97 98 |
# File 'lib/volt/reactive/object_tracker.rb', line 92 def remove_followers # Remove from previous if @cached_current_obj @cached_current_obj.remove_event_follower(@main_object) @cached_current_obj = nil end end |
#update_followers ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/volt/reactive/object_tracker.rb', line 71 def update_followers if @enabled puts "UPDATE" if OBJECT_TRACKER_DEBUG current_obj = @main_object.cur#(true) # puts "UPDATE ON #{current_obj.inspect}" remove_followers # Add to current should_attach = current_obj.respond_to?(:on) if should_attach current_obj.add_event_follower(@main_object) @cached_current_obj = current_obj end else puts "DISABLED, no update" if OBJECT_TRACKER_DEBUG end end |