Module: ReactiveRecord
- Defined in:
- lib/reactive_record/engine.rb,
lib/reactive_record/pry.rb,
lib/reactive_record/version.rb,
lib/reactive_record/permissions.rb,
lib/reactive_record/server_data_cache.rb,
app/controllers/reactive_record/application_controller.rb,
lib/reactive_record/active_record/reactive_record/base.rb,
app/controllers/reactive_record/reactive_record_controller.rb,
lib/reactive_record/active_record/reactive_record/collection.rb,
lib/reactive_record/active_record/reactive_record/while_loading.rb,
lib/reactive_record/active_record/reactive_record/isomorphic_base.rb
Overview
require ‘rails’
Defined Under Namespace
Modules: Pry Classes: AccessViolation, ApplicationController, Base, Collection, Engine, ReactiveRecordController, ServerDataCache, WhileLoading
Constant Summary collapse
- VERSION =
"0.8.3"
Class Method Summary collapse
- .check_loads_pending ⇒ Object
-
.load(&block) ⇒ Object
will repeatedly execute the block until it is loaded immediately returns a promise that will resolve once the block is loaded.
- .loads_pending! ⇒ Object
- .run_blocks_to_load(fetch_id, failure = nil) ⇒ Object
Class Method Details
.check_loads_pending ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/reactive_record/active_record/reactive_record/while_loading.rb', line 28 def self.check_loads_pending if @loads_pending if Base.pending_fetches.count > 0 true else # this happens when for example loading foo.x results in somebody looking at foo.y while foo.y is still being loaded ReactiveRecord::WhileLoading.loaded_at Base.last_fetch_at ReactiveRecord::WhileLoading.quiet! false end end end |
.load(&block) ⇒ Object
will repeatedly execute the block until it is loaded immediately returns a promise that will resolve once the block is loaded
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/reactive_record/active_record/reactive_record/while_loading.rb', line 6 def self.load(&block) promise = Promise.new @load_stack ||= [] @load_stack << @loads_pending @loads_pending = nil result = block.call if @loads_pending @blocks_to_load ||= [] @blocks_to_load << [Base.last_fetch_at, promise, block] else promise.resolve result end @loads_pending = @load_stack.pop promise rescue Exception => e React::IsomorphicHelpers.log "ReactiveRecord.load exception raised during initial load: #{e}", :error end |
.loads_pending! ⇒ Object
24 25 26 |
# File 'lib/reactive_record/active_record/reactive_record/while_loading.rb', line 24 def self.loads_pending! @loads_pending = true end |
.run_blocks_to_load(fetch_id, failure = nil) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/reactive_record/active_record/reactive_record/while_loading.rb', line 40 def self.run_blocks_to_load(fetch_id, failure = nil) if @blocks_to_load blocks_to_load_now = @blocks_to_load.select { |data| data.first == fetch_id } @blocks_to_load = @blocks_to_load.reject { |data| data.first == fetch_id } @load_stack ||= [] blocks_to_load_now.each do |data| id, promise, block = data @load_stack << @loads_pending @loads_pending = nil result = block.call(failure) if check_loads_pending and !failure @blocks_to_load << [Base.last_fetch_at, promise, block] else promise.resolve result end @loads_pending = @load_stack.pop end end rescue Exception => e React::IsomorphicHelpers.log "ReactiveRecord.load exception raised during retry: #{e}", :error end |