Sha256: 427008175e16f2e29ee3e0b47e8537c8b9849a69e1be10257368c12e6c1b6042

Contents?: true

Size: 832 Bytes

Versions: 14

Compression:

Stored size: 832 Bytes

Contents

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

  # Called when a collection loads
  def loaded(initial_state=nil)
    change_state_to(initial_state || :not_loaded)
  end

  def state
    @state_dep ||= Dependency.new
    @state_dep.depend

    return @state
  end

  # Called from the QueryListener when the data is loaded
  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
        @state_dep.changed! if @state_dep
      end
    end

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

      stop_listening
    end
  end

end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
volt-0.8.14 lib/volt/models/persistors/store_state.rb
volt-0.8.13 lib/volt/models/persistors/store_state.rb
volt-0.8.11 lib/volt/models/persistors/store_state.rb
volt-0.8.10 lib/volt/models/persistors/store_state.rb
volt-0.8.9 lib/volt/models/persistors/store_state.rb
volt-0.8.8 lib/volt/models/persistors/store_state.rb
volt-0.8.7 lib/volt/models/persistors/store_state.rb
volt-0.8.6 lib/volt/models/persistors/store_state.rb
volt-0.8.5 lib/volt/models/persistors/store_state.rb
volt-0.8.4 lib/volt/models/persistors/store_state.rb
volt-0.8.3 lib/volt/models/persistors/store_state.rb
volt-0.8.2 lib/volt/models/persistors/store_state.rb
volt-0.8.1 lib/volt/models/persistors/store_state.rb
volt-0.8.0 lib/volt/models/persistors/store_state.rb