Module: ReactiveRecord
- Defined in:
- lib/reactive_record/pry.rb,
lib/reactive_record/broadcast.rb,
lib/reactive_record/scope_description.rb,
lib/reactive_record/server_data_cache.rb,
lib/reactive_record/active_record/reactive_record/base.rb,
lib/reactive_record/active_record/reactive_record/getters.rb,
lib/reactive_record/active_record/reactive_record/setters.rb,
lib/reactive_record/active_record/reactive_record/collection.rb,
lib/reactive_record/active_record/reactive_record/operations.rb,
lib/reactive_record/active_record/reactive_record/dummy_value.rb,
lib/reactive_record/active_record/reactive_record/column_types.rb,
lib/reactive_record/active_record/reactive_record/lookup_tables.rb,
lib/reactive_record/active_record/reactive_record/while_loading.rb,
lib/reactive_record/active_record/reactive_record/isomorphic_base.rb,
lib/reactive_record/active_record/reactive_record/scoped_collection.rb,
lib/reactive_record/active_record/reactive_record/unscoped_collection.rb,
lib/reactive_record/active_record/reactive_record/backing_record_inspector.rb
Defined Under Namespace
Modules: BackingRecordInspector, Getters, LookupTables, Operations, Pry, ScopedCollection, Setters, UnscopedCollection Classes: Base, Broadcast, Collection, ScopeDescription, ServerDataCache, WhileLoading
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
-
.on_fetch_error(e, params) ⇒ Object
redefine if you want to process errors (i.e. logging, rollbar, etc).
- .run_blocks_to_load(fetch_id, failure = nil) ⇒ Object
Class Method Details
.check_loads_pending ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/reactive_record/active_record/reactive_record/while_loading.rb', line 34 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.current_fetch_id 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
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/reactive_record/active_record/reactive_record/while_loading.rb', line 12 def self.load(&block) promise = Promise.new @load_stack ||= [] @load_stack << @loads_pending @loads_pending = nil result = block.call.itself if @loads_pending @blocks_to_load ||= [] @blocks_to_load << [Base.current_fetch_id, 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
30 31 32 |
# File 'lib/reactive_record/active_record/reactive_record/while_loading.rb', line 30 def self.loads_pending! @loads_pending = true end |
.on_fetch_error(e, params) ⇒ Object
redefine if you want to process errors (i.e. logging, rollbar, etc)
3 |
# File 'lib/reactive_record/active_record/reactive_record/operations.rb', line 3 def self.on_fetch_error(e, params); end |
.run_blocks_to_load(fetch_id, failure = nil) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/reactive_record/active_record/reactive_record/while_loading.rb', line 46 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 && !failure @blocks_to_load << [Base.current_fetch_id, 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 |