services/instructor-service.js

/**
 * AngularJS Service for storing instructor-mode states.
 *
 * @module instructorService
 * @see https://docs.angularjs.org/api/ng/type/angular.Module#service
 */
angular.module('tgaApp')
  .service('instructorService', [
    function instructorService() {
      /**
       * Stored _previous_ instructor state object.
       *
       * @private
       * @member {Object} previousInstructorState
       */
      let previousInstructorState = {};

      /**
       * Stored _current_ instructor state object.
       *
       * @private
       * @member {Object} currentInstructorState
       */
      let currentInstructorState = {};

      /**
       * Get previous and current instructor states.
       *
       * @returns {InstructorStateObject}
       */
      this.getStates = () => ({
        previousInstructorState,
        currentInstructorState,
      });

      /**
       * Update stored instructor state with a new "current" state and cycle
       * the existing stored current state to "previous".
       *
       * @param {Object} state - A new instructor state object to set as current.
       */
      this.updateStates = (state) => {
        previousInstructorState = angular.copy(currentInstructorState);
        currentInstructorState = state;
      };

      /**
       * Get session group ID from {@link module:instructorService~currentInstructorState}
       *
       * @returns {number} A session group ID
       */
      this.getSessionGroupId = () => currentInstructorState.session_group_id;
    },
  ]);