Class: React::Element

Inherits:
Object show all
Defined in:
lib/reactive_record/active_record/reactive_record/while_loading.rb

Instance Method Summary collapse

Instance Method Details

#hide_while_loadingObject



233
234
235
# File 'lib/reactive_record/active_record/reactive_record/while_loading.rb', line 233

def hide_while_loading
  while_loading
end

#while_loading(display = "", &loading_display_block) ⇒ Object



204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/reactive_record/active_record/reactive_record/while_loading.rb', line 204

def while_loading(display = "", &loading_display_block)

  loaded_children = []
  loaded_children = block.call.dup if block

  if display.respond_to? :as_node
    display = display.as_node
    loading_display_block = lambda { display.render }
  elsif !loading_display_block
    loading_display_block = lambda { display }
  end
  loading_children = RenderingContext.build do |buffer|
    result = loading_display_block.call
    result = result.to_s if result.try :acts_as_string?
    result.span.tap { |e| e.waiting_on_resources = RenderingContext.waiting_on_resources } if result.is_a? String
    buffer.dup
  end

  new_element = React.create_element(
    ReactiveRecord::WhileLoading,
    loading: waiting_on_resources,
    loading_children: loading_children,
    loaded_children: loaded_children,
    element_type: [type],
    element_props: properties)

  RenderingContext.replace(self, new_element)
end