Module: React::Component

Included in:
ReactiveRecord::WhileLoading
Defined in:
lib/reactive_record/active_record/reactive_record/while_loading.rb

Instance Method Summary collapse

Instance Method Details

#component_did_mount(*args) ⇒ Object



225
226
227
228
229
# File 'lib/reactive_record/active_record/reactive_record/while_loading.rb', line 225

def component_did_mount(*args)
  original_component_did_mount(*args)
  reactive_record_link_to_enclosing_while_loading_container
  reactive_record_link_set_while_loading_container_class
end

#component_did_update(*args) ⇒ Object



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

def component_did_update(*args)
  original_component_did_update(*args)
  reactive_record_link_set_while_loading_container_class
end

#original_component_did_mountObject



223
224
225
226
227
# File 'lib/reactive_record/active_record/reactive_record/while_loading.rb', line 223

def component_did_mount(*args)
  original_component_did_mount(*args)
  reactive_record_link_to_enclosing_while_loading_container
  reactive_record_link_set_while_loading_container_class
end

#original_component_did_updateObject



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

def component_did_update(*args)
  original_component_did_update(*args)
  reactive_record_link_set_while_loading_container_class
end


255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# File 'lib/reactive_record/active_record/reactive_record/while_loading.rb', line 255

def reactive_record_link_set_while_loading_container_class

  %x{

    var node = #{dom_node};
    var while_loading_container_id = $(node).attr('data-reactive_record_enclosing_while_loading_container_id');
    if (while_loading_container_id) {
      var while_loading_container = $('[data-reactive_record_while_loading_container_id='+while_loading_container_id+']');
      var loading = (#{waiting_on_resources} == true);
      if (loading) {
        $(node).addClass('reactive_record_is_loading');
        $(node).removeClass('reactive_record_is_loaded');
        $(while_loading_container).addClass('reactive_record_is_loading');
        $(while_loading_container).removeClass('reactive_record_is_loaded');

      } else if (!$(node).hasClass('reactive_record_is_loaded')) {

        if (!$(node).attr('data-reactive_record_while_loading_container_id')) {
          $(node).removeClass('reactive_record_is_loading');
          $(node).addClass('reactive_record_is_loaded');
        }
        if (!$(while_loading_container).hasClass('reactive_record_is_loaded')) {
          var loading_children = $(while_loading_container).
            find('[data-reactive_record_enclosing_while_loading_container_id='+while_loading_container_id+'].reactive_record_is_loading')
          if (loading_children.length == 0) {
            $(while_loading_container).removeClass('reactive_record_is_loading')
            $(while_loading_container).addClass('reactive_record_is_loaded')
          }
        }

      }

    }
  }

end


238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
# File 'lib/reactive_record/active_record/reactive_record/while_loading.rb', line 238

def reactive_record_link_to_enclosing_while_loading_container
  # Call after any component mounts - attaches the containers loading id to this component
  # Fyi, the while_loading container is responsible for setting its own link to itself

  %x{
    var node = #{dom_node};
    if (!$(node).is('[data-reactive_record_enclosing_while_loading_container_id]')) {
      var while_loading_container = $(node).closest('[data-reactive_record_while_loading_container_id]')
      if (while_loading_container.length > 0) {
        var container_id = $(while_loading_container).attr('data-reactive_record_while_loading_container_id')
        $(node).attr('data-reactive_record_enclosing_while_loading_container_id', container_id)
      }
    }
  }

end