codeforamerica / bizfriendly-web

An experiment in digital literacy lessons. The experiment is now over.
http://bizfriend.ly
22 stars 67 forks source link

Refactor _checkStep response functions #65

Open ondrae opened 11 years ago

ondrae commented 11 years ago

Description

All the functions called within _checkStep are nearly identical. There is a good opportunity there for refactoring.

Example

// A certain attribute exists at the url endpoint
  // Display the returned attribute
  function _checkIfAttributeExists(response){
    if (debug) console.log(response);
    response = $.parseJSON(response);
    if (response.timeout) _checkStep();
    if ( response.attribute_exists ){
      $('#step'+currentStep.stepNumber+' .feedback .responseDisplay').html(response.attribute_to_display);
      $('#step'+currentStep.stepNumber+' .step_text').css('display','none');
      $('#step'+currentStep.stepNumber+' .feedback').css('display','block');
      $('#next').addClass('animated pulse');
    }
  }

All of the similar functions have the same style. They check for a certain response response.attribute_exists then display the feedback portion of the step.

Files

js/instructions.js

Tips