226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
|
# File 'lib/reactive_record/active_record/reactive_record/while_loading.rb', line 226
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
|