Skip to content
This repository has been archived by the owner on Oct 19, 2018. It is now read-only.

while_loading doesn't work with external Hyperloop::Component #102

Open
aberios opened this issue Jun 23, 2018 · 2 comments
Open

while_loading doesn't work with external Hyperloop::Component #102

aberios opened this issue Jun 23, 2018 · 2 comments

Comments

@aberios
Copy link

aberios commented Jun 23, 2018

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.

@aberios
Copy link
Author

aberios commented Jun 24, 2018

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                                                                              

@catmando
Copy link
Contributor

@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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants