while_loading doesn't work with external Hyperloop::Component
The following doesn't appear to work.
class LoadingComponent < Hyperloop::Component
render do
DIV do
'Loading...'
end
end
end
class MainComponent < Hyperloop::Router::Component
render do
FORM do
INPUT(defaultValue: User.find_by_first_name('Lily').last_name)
end
.while_loading do
LoadingComponent {}
end
end
end
Appears to have something to do with an INPUT's defaultValue.
while_loading also doesn't appear to work when rendering a state variable that depends on data. (Possibly related?)
class LoadingComponent < Hyperloop::Component
render do
SPAN { 'loading...' }
end
end
class MainComponent < Hyperloop::Component
state last_name: nil
before_mount do
mutate.last_name User.find(1).last_name
end
render do
DIV do
state.last_name
end
.while_loading do
LoadingComponent {}
end
end
end
@aberios okay the first case will be closed shortly, but the second case is may be more difficult, as it will require changing the semantics of mutate to be more intelligent, not a bad idea at all, but should be done with some thought.
Meanwhile if you needed to do the second case it could be rewritten like this:
class LoadingComponent < Hyperloop::Component
render do
SPAN { 'loading...' }
end
end
class MainComponent < Hyperloop::Component
before_mount do
ReactiveRecord.load do
User.find(1).last_name
end.then do |last_name|
mutate.last_name last_name
end
end
render do
if state.last_name
DIV { state.last_name }
else
LoadingComponent {}
end
end
end
The thing is this second case is really not needed, as your active record model data is already using reactive states, so having the "state.last_name" is just a redundant copy of User.find(1).last_name
It could be the case that you want to have a state like state.user that gets updated by some event change, and that would work fine.