Module: ReactiveRecord
- Defined in:
- lib/reactive_record/engine.rb,
lib/reactive_record/version.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
Classes: ApplicationController, Base, Collection, Engine, ReactiveRecordController, ServerDataCache, WhileLoading
Constant Summary collapse
- VERSION =
"0.7.0"
Class Method Summary collapse
-
.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 ⇒ Object
Class Method Details
.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 |
# 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 << [promise, block] else promise.resolve result end @loads_pending = @load_stack.pop promise end |
.loads_pending! ⇒ Object
22 23 24 |
# File 'lib/reactive_record/active_record/reactive_record/while_loading.rb', line 22 def self.loads_pending! @loads_pending = true end |
.run_blocks_to_load ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/reactive_record/active_record/reactive_record/while_loading.rb', line 26 def self.run_blocks_to_load if @blocks_to_load blocks_to_load = @blocks_to_load @blocks_to_load = [] blocks_to_load.each do |promise_and_block| @loads_pending = nil result = promise_and_block.last.call if @loads_pending @blocks_to_load << promise_and_block else promise_and_block.first.resolve result end end end rescue Exception => e = "ReactiveRecord.run_blocks_to_load exception raised: #{e}" `console.error(#{})` end |