Skip to content

Instantly share code, notes, and snippets.

@niquola
Last active September 27, 2016 21:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niquola/9f7d9e461172c7353dd9d7ebf793a55a to your computer and use it in GitHub Desktop.
Save niquola/9f7d9e461172c7353dd9d7ebf793a55a to your computer and use it in GitHub Desktop.

JSX Pro & Cons:

Pro:

  • looks like html template
  • goes with react

Cons:

  • new syntax & require preprocessor
  • mix of xml & js syntax
  • embeded expressions is unreadable (so we generate a lot of temporal variables)
  • more characters (same punctuation)
  • does not looks like code - does not drive refactoring & abstraction

So why JSX?

<div className='workflow'>                                                                         
   <Navigation workflow={wf} onNavigate={this.gotoStep.bind(this)} currentStepIndex={stepIndex} />  
   <Workspace step={currentStep} onNext={this.gotoNextStep.bind(this)} />                           
</div>   

characters: 311 syntax(<{/): 19

div({ className: 'workflow' },
  navigation({ workflow: wf, onNavigate=this.gotoStep.bind(this), currentStepIndex: stepIndex }),
  workspaec({ step: currentStep, onNext: this.gotoNextStep.bind(this) })
)

characters: 203 syntax (({,): 16

(<div className='workspace'>                                                                              
  <div className='ws-header'>                                                                            
    <h3>{step && step.title}</h3>                                                                        
    <div className='ws-btns'>                                                                            
      {buttons}                                                                                          
    </div>                                                                                               
  </div>                                                                                                 
  <div className='ws-body'>                                                                              
    { editorEl }                                                                                         
  </div>                                                                                                 
  <div className='ws-footer'>                                                                            
    <div className='ws-spacer'></div>                                                                    
    <div className='ws-btns'>                                                                            
      {buttons}                                                                                          
    </div>                                                                                               
  </div>                                                                                                 
</div>)           

punctuation: 50 characters: 1699

div({ className:'workspace'},                                                                            
    div({ className:'ws-header'},                                                                        
        h3({}, step && step.title),                                                                      
        div({ className:'ws-btns'},                                                                      
            {buttons})),                                                                                 
    div({ className:'ws-body'},                                                                          
        { editorEl }),                                                                                   
    div( { className:'ws-footer'},                                                                       
         div( { className:'ws-spacer'}),                                                                 
         div( { className:'ws-btns'}, {buttons})))  

punctuation: 48 characters: 997

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment