Module: StoreState

Included in:
Persistors::ArrayStore, Persistors::ModelStore
Defined in:
lib/volt/models/persistors/store_state.rb

Overview

StoreState provides method for a store to track its loading state.

Instance Method Summary collapse

Instance Method Details

#change_state_to(new_state, skip_trigger = false) ⇒ Object

Called from the QueryListener when the data is loaded



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/volt/models/persistors/store_state.rb', line 14

def change_state_to(new_state, skip_trigger=false)
  old_state = @state
  @state = new_state

  # Trigger changed on the 'state' method
  unless skip_trigger
    if old_state != @state
      @model.trigger_for_methods!('changed', :state, :loaded?)
    end
  end

  if @state == :loaded && @fetch_promises
    # Trigger each waiting fetch
    @fetch_promises.compact.each {|fp| fp.resolve(@model) }
    @fetch_promises = nil
  end
end

#loaded(initial_state = nil) ⇒ Object

Called when a collection loads



5
6
7
# File 'lib/volt/models/persistors/store_state.rb', line 5

def loaded(initial_state=nil)
  change_state_to(initial_state || :not_loaded)
end

#stateObject



9
10
11
# File 'lib/volt/models/persistors/store_state.rb', line 9

def state
  @state
end