Sha256: dd2cf43389eac3f09d55454e2ebf48be8ced3c17e05ac25cd9b9ff2252377129

Contents?: true

Size: 1.94 KB

Versions: 13

Compression:

Stored size: 1.94 KB

Contents

class QueryTasks < Volt::Task
  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.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.message }
    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]
      end
    end

    [initial_data, error]
  end

  def initial_data
    data = live_query.initial_data
    data[:id] = data[:id].to_s

    data
  end

  # Remove a listening channel, the LiveQuery will automatically remove
  # itsself from the pool when there are no channels.
  def remove_listener(collection, query)
    live_query = @volt_app.live_query_pool.lookup(collection, query)
    live_query.remove_channel(@channel)
  end

  # Removes a channel from all associated live queries
  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

  private

  # Tracks that this channel will be notified from the live query.
  def track_channel_in_live_query(live_query)
    channel_live_queries = @volt_app.channel_live_queries
    channel_live_queries[@channel] ||= []
    channel_live_queries[@channel] << live_query
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
volt-0.9.5.pre3 app/volt/tasks/query_tasks.rb
volt-0.9.5.pre2 app/volt/tasks/query_tasks.rb
volt-0.9.5.pre1 app/volt/tasks/query_tasks.rb
volt-0.9.4 app/volt/tasks/query_tasks.rb
volt-0.9.4.pre5 app/volt/tasks/query_tasks.rb
volt-0.9.4.pre3 app/volt/tasks/query_tasks.rb
volt-0.9.4.pre2 app/volt/tasks/query_tasks.rb
volt-0.9.4.pre1 app/volt/tasks/query_tasks.rb
volt-0.9.3 app/volt/tasks/query_tasks.rb
volt-0.9.3.pre6 app/volt/tasks/query_tasks.rb
volt-0.9.3.pre5 app/volt/tasks/query_tasks.rb
volt-0.9.3.pre4 app/volt/tasks/query_tasks.rb
volt-0.9.3.pre3 app/volt/tasks/query_tasks.rb