Class: QueryTasks

Inherits:
Object show all
Defined in:
app/volt/tasks/query_tasks.rb

Constant Summary collapse

@@live_query_pool =
LiveQueryPool.new(DataStore.new)
@@channel_live_queries =
{}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(channel, dispatcher = nil) ⇒ QueryTasks

The dispatcher passes its self in



13
14
15
16
# File 'app/volt/tasks/query_tasks.rb', line 13

def initialize(channel, dispatcher=nil)
  @channel = channel
  @dispatcher = dispatcher
end

Class Method Details

.live_query_poolObject



8
9
10
# File 'app/volt/tasks/query_tasks.rb', line 8

def self.live_query_pool
  @@live_query_pool
end

Instance Method Details

#add_listener(collection, query) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'app/volt/tasks/query_tasks.rb', line 18

def add_listener(collection, query)
  live_query = @@live_query_pool.lookup(collection, query)
  track_channel_in_live_query(live_query)

  live_query.add_channel(@channel)

  # Return the initial data
  return live_query.initial_data
end

#close!Object

Removes a channel from all associated live queries



37
38
39
40
41
42
43
44
45
46
47
# File 'app/volt/tasks/query_tasks.rb', line 37

def close!
  live_queries = @@channel_live_queries[@channel]

  if live_queries
    live_queries.each do |live_query|
      live_query.remove_channel(@channel)
    end
  end

  @@channel_live_queries.delete(@channel)
end

#remove_listener(collection, query) ⇒ Object

Remove a listening channel, the LiveQuery will automatically remove itsself from the pool when there are no channels.



30
31
32
33
# File 'app/volt/tasks/query_tasks.rb', line 30

def remove_listener(collection, query)
  live_query = @@live_query_pool.lookup(collection, query)
  live_query.remove_channel(@channel)
end