Class: QueryTasks
- Inherits:
-
Volt::Task
- Object
- Volt::Task
- QueryTasks
- Defined in:
- app/volt/tasks/query_tasks.rb
Instance Method Summary collapse
- #add_listener(collection, query) ⇒ Object
-
#close! ⇒ Object
Removes a channel from all associated live queries.
- #initial_data ⇒ Object
-
#remove_listener(collection, query) ⇒ Object
Remove a listening channel, the LiveQuery will automatically remove itsself from the pool when there are no channels.
Methods inherited from Volt::Task
#cookies, #fetch_cookies, inherited, #initialize, known_handlers, method_missing, timeout
Methods included from Volt::LoginAsHelper
Methods included from Volt::CollectionHelpers
#channel, #cookies, #flash, #local_store, #page, #params, #store, #tasks, #url, #url_for, #url_with
Constructor Details
This class inherits a constructor from Volt::Task
Instance Method Details
#add_listener(collection, query) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/volt/tasks/query_tasks.rb', line 2 def add_listener(collection, query) live_query = @volt_app.live_query_pool.lookup(collection, query) track_channel_in_live_query(live_query) if @channel # For requests from the client (with @channel), we track the channel # so we can send the results back. Server side requests don't stay live, # they simply return to :dirty once the query is issued. @channel.update_user_id(Volt.current_user_id) # live_query.add_channel(@channel) end live_query.add_channel(@channel) errors = {} begin # Get the initial data initial_data = live_query.initial_data rescue => exception # Capture and pass up any exceptions error = { error: exception. } end if initial_data # Only send the filtered attributes for this user initial_data.map! do |data| [data[0], live_query.model_for_filter(data[1]).filtered_attributes.sync] end end [initial_data, error] end |
#close! ⇒ Object
Removes a channel from all associated live queries
51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/volt/tasks/query_tasks.rb', line 51 def close! live_queries = @volt_app.channel_live_queries[@channel] if live_queries live_queries.each do |live_query| live_query.remove_channel(@channel) end end @volt_app.channel_live_queries.delete(@channel) end |
#initial_data ⇒ Object
36 37 38 39 40 41 |
# File 'app/volt/tasks/query_tasks.rb', line 36 def initial_data data = live_query.initial_data data[:id] = data[:id].to_s data end |
#remove_listener(collection, query) ⇒ Object
Remove a listening channel, the LiveQuery will automatically remove itsself from the pool when there are no channels.
45 46 47 48 |
# File 'app/volt/tasks/query_tasks.rb', line 45 def remove_listener(collection, query) live_query = @volt_app.live_query_pool.lookup(collection, query) live_query.remove_channel(@channel) end |