Class: ReactiveRecord::WhileLoading
- Inherits:
-
Object
- Object
- ReactiveRecord::WhileLoading
show all
- Includes:
- React::Component, React::IsomorphicHelpers
- Defined in:
- lib/reactive_record/active_record/reactive_record/while_loading.rb
Overview
To notify React that something is loading use React::WhileLoading.loading! once everything is loaded then do React::WhileLoading.loaded_at message (typically a time stamp just for debug purposes)
Class Method Summary
collapse
Instance Method Summary
collapse
#component_did_mount, #component_did_update, #original_component_did_mount, #original_component_did_update, #reactive_record_link_set_while_loading_container_class, #reactive_record_link_to_enclosing_while_loading_container
Class Method Details
.add_style_sheet ⇒ Object
137
138
139
140
141
142
143
144
|
# File 'lib/reactive_record/active_record/reactive_record/while_loading.rb', line 137
def add_style_sheet
@style_sheet ||= %x{
$('<style type="text/css">'+
' .reactive_record_is_loading > .reactive_record_show_when_loaded { display: none; }'+
' .reactive_record_is_loaded > .reactive_record_show_while_loading { display: none; }'+
'</style>').appendTo("head")
}
end
|
.loaded_at(loaded_at) ⇒ Object
118
119
120
121
|
# File 'lib/reactive_record/active_record/reactive_record/while_loading.rb', line 118
def loaded_at(loaded_at)
React::State.set_state(self, :loaded_at, loaded_at)
@is_loading = false
end
|
111
112
113
114
115
116
|
# File 'lib/reactive_record/active_record/reactive_record/while_loading.rb', line 111
def loading!
React::RenderingContext.waiting_on_resources = true
React::State.get_state(self, :loaded_at)
React::State.set_state(self, :quiet, false)
@is_loading = true
end
|
.loading? ⇒ Boolean
107
108
109
|
# File 'lib/reactive_record/active_record/reactive_record/while_loading.rb', line 107
def loading?
@is_loading
end
|
.page_loaded? ⇒ Boolean
127
128
129
|
# File 'lib/reactive_record/active_record/reactive_record/while_loading.rb', line 127
def page_loaded?
React::State.get_state(self, :page_loaded)
end
|
131
132
133
134
135
|
# File 'lib/reactive_record/active_record/reactive_record/while_loading.rb', line 131
def quiet!
React::State.set_state(self, :quiet, true)
after(1) { React::State.set_state(self, :page_loaded, true) } unless on_opal_server? or @page_loaded
@page_loaded = true
end
|
.quiet? ⇒ Boolean
123
124
125
|
# File 'lib/reactive_record/active_record/reactive_record/while_loading.rb', line 123
def quiet?
React::State.get_state(self, :quiet)
end
|
Instance Method Details
#get_next_while_loading_counter ⇒ Object
80
81
82
|
# File 'lib/reactive_record/active_record/reactive_record/while_loading.rb', line 80
def get_next_while_loading_counter
@while_loading_counter += 1
end
|
#preload_css(css) ⇒ Object
84
85
86
|
# File 'lib/reactive_record/active_record/reactive_record/while_loading.rb', line 84
def preload_css(css)
@css_to_preload << css << "\n"
end
|
171
172
173
174
175
176
177
178
179
180
|
# File 'lib/reactive_record/active_record/reactive_record/while_loading.rb', line 171
def render
props = element_props.dup
classes = [props[:class], props[:className], "reactive_record_while_loading_container_#{@uniq_id}"].compact.join(" ")
props.merge!({
"data-reactive_record_while_loading_container_id" => @uniq_id,
"data-reactive_record_enclosing_while_loading_container_id" => @uniq_id,
class: classes
})
React.create_element(element_type, props) { loaded_children + loading_children }
end
|