Class: StoreArray

Inherits:
ArrayModel show all
Defined in:
lib/volt/models/store_array.rb

Instance Attribute Summary

Attributes inherited from ArrayModel

#parent, #path

Instance Method Summary collapse

Methods inherited from ArrayModel

#+, #<<, #attributes, #inject

Methods included from ModelWrapper

#wrap_value, #wrap_values

Methods inherited from ReactiveArray

#+, #<<, #==, #[]=, #delete_at, #insert, #inspect, #method_missing, #split_scope, #trigger_for_index!, #trigger_on_direct_listeners!, #trigger_size_change!

Methods included from ObjectTracking

#__setup_tracking

Methods included from ReactiveTags

included, #reactive_method_tag

Constructor Details

#initialize(tasks = nil, array = [], parent = nil, path = nil) ⇒ StoreArray

Returns a new instance of StoreArray.



2
3
4
5
6
# File 'lib/volt/models/store_array.rb', line 2

def initialize(tasks=nil, array=[], parent=nil, path=nil)
  @tasks = tasks

  super(array, parent, path)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ReactiveArray

Instance Method Details

#change_channel_connection(add_or_remove, event) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/volt/models/store_array.rb', line 25

def change_channel_connection(add_or_remove, event)
  if parent.attributes && path.size != 0
    channel_name = "#{path[-1]}-#{event}"
    puts "Listen on #{channel_name}"
    @tasks.call('ChannelTasks', "#{add_or_remove}_listener", channel_name)
  end    
end

#event_added(event, scope_provider, first) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/volt/models/store_array.rb', line 8

def event_added(event, scope_provider, first) 
  puts "New event: #{event.inspect} - #{first}"   
  if first && [:added, :removed].include?(event)
    # Start listening for added items on the collection
    
    change_channel_connection('add')
  end
end

#event_removed(event, no_more_events) ⇒ Object



17
18
19
20
21
22
# File 'lib/volt/models/store_array.rb', line 17

def event_removed(event, no_more_events)
  if no_more_events && [:added, :removed].include?(event)
    # Stop listening
    change_channel_connection("remove", event)
  end
end

#new_array_model(*args) ⇒ Object



37
38
39
# File 'lib/volt/models/store_array.rb', line 37

def new_array_model(*args)
  StoreArray.new(@tasks, *args)
end

#new_model(*args) ⇒ Object



33
34
35
# File 'lib/volt/models/store_array.rb', line 33

def new_model(*args)
  Store.new(@tasks, *args)
end