Sha256: 24a02fc68af22b8c52e341b69d90d579b53f7c2602d6a7886f14bc31f72f4537

Contents?: true

Size: 959 Bytes

Versions: 13

Compression:

Stored size: 959 Bytes

Contents

module Volt
  module Persistors
    # 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

        @state
      end

      # Called from the QueryListener when the data is loaded
      def change_state_to(new_state)
        old_state = @state
        @state    = new_state

        # Trigger changed on the 'state' method
        if old_state != @state
          @state_dep.changed! if @state_dep
        end

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

          # puts "STOP LIST---------"
          stop_listening
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
volt-0.8.27.beta3 lib/volt/models/persistors/store_state.rb
volt-0.8.27.beta2 lib/volt/models/persistors/store_state.rb
volt-0.8.27.beta1 lib/volt/models/persistors/store_state.rb
volt-0.8.26.beta1 lib/volt/models/persistors/store_state.rb
volt-0.8.26 lib/volt/models/persistors/store_state.rb
volt-0.8.24 lib/volt/models/persistors/store_state.rb
volt-0.8.23 lib/volt/models/persistors/store_state.rb
volt-0.8.22 lib/volt/models/persistors/store_state.rb
volt-0.8.22.beta2 lib/volt/models/persistors/store_state.rb
volt-0.8.22.beta1 lib/volt/models/persistors/store_state.rb
volt-0.8.21 lib/volt/models/persistors/store_state.rb
volt-0.8.20 lib/volt/models/persistors/store_state.rb
volt-0.8.19 lib/volt/models/persistors/store_state.rb