Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Avoid Logic in template #1

Open
GregOnNet opened this issue Jan 30, 2023 · 0 comments
Open

Proposal: Avoid Logic in template #1

GregOnNet opened this issue Jan 30, 2023 · 0 comments

Comments

@GregOnNet
Copy link

GregOnNet commented Jan 30, 2023

Motivation

JSX templates can be hard to read easily, when logic is added.

<button                                          
   onClick$={() => {                              
     const nextVideoIndex =                       
       state.index + 1 >= props.videos.length     
         ? props.videos.length - 1                
         : state.index + 1;                       
                                                  
     state.video = props.videos[nextVideoIndex];  
     state.index = nextVideoIndex;                
   }}>
  Next Video
</button>                                           

Proposal

We can encourage developers to extract logic into self-descriptive functions.
This implicitly adds documentation due to function-naming + the template's complexity decreases.

<button onClick$={() => showNextVideo$()}>Next Video</button>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant