Method: QueryListener#add_store

Defined in:
lib/volt/models/persistors/query/query_listener.rb

#add_store(store, &block) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/volt/models/persistors/query/query_listener.rb', line 37

def add_store(store, &block)
  @stores << store

  if @listening
    # We are already listening and have this model somewhere else,
    # copy the data from the existing model.
    store.model.clear
    @stores.first.model.each_with_index do |item, index|
      store.add(index, item.to_h)
    end
  else
    # First time we've added a store, setup the listener and get
    # the initial data.
    add_listener
  end
end