Skip to content

Instantly share code, notes, and snippets.

@stevepentler
Last active May 18, 2016 20:35
Show Gist options
  • Save stevepentler/70a6ace5a820c07aa4bd37829ff93503 to your computer and use it in GitHub Desktop.
Save stevepentler/70a6ace5a820c07aa4bd37829ff93503 to your computer and use it in GitHub Desktop.

Flow:

  1. Hits Site Controller, which calls the index action and fires App Component of React
  2. Upon Component did mount, fires off AJAX call to API/V1/DataController
    • Instantiates RachioService
    • calls store_data
      • retrieves user_id info
      • retrieves devices
      • retreives device_zones
  3. After data is loaded into the database, promises call getZones and getDevices and sets State

React Components:

  • App: Contains all state and handles all AJAX calls
    • Device: Preloader until database is loaded and app receives device in state
      • All Zones: Once state has a zones object, it maps and passes a single zone to the zone component
        • Zone: Displays zone data including name, previous watering duration and date
          • WateringForm:
            • sets initial state specific to the form
            • captures zoneData from form
            • fires waterZone and passes zoneData to the AJAX call at the App level
            • changes state of watering to true, renders "Watering Zone for X minutes" instead

Notes & Challenges

  • Striking the balance between a scalable design and overdesigning
    • Example - No need for users in the database at this point, but it would be beneficial to have ActiveRecord Relations in the future, ie: current_user.devices.zones.all
    • Could make an AJAX call with headers and save everything in state from React without a Rails backend
      • no testing
      • not as scalable
  • Tracing the flow of the application is fairly complex, and I think it could be more simple.
  • Data doesn't persist, but Firebase / local storage seemed overkill considering the intent was only to water
  • Return data from the API seems finicky, especially the wateringDuration. Also, no way to check if the sprinkler is actually firing.
  • Loading data at the appropriate time.
    • Solutions for to hold off mapping until data loads into state
  • Not entirely sure how to format time of last watering. It seems like others may have been hitting the API with their duration formatted in minutes. I just want to prove that I hit Zone 3 on 5/18 at 2:15PM for 10 minutes (600 seconds).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment