Code coverage report for src/flux/course-listing.coffee

Statements: 87.18% (34 / 39)      Branches: 100% (4 / 4)      Functions: 83.33% (10 / 12)      Lines: 87.18% (34 / 39)      Ignored: none     

All files » src/flux/ » course-listing.coffee
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86                                       40× 61× 61×   40× 40×                             71×     11×     54× 51×           74×                  
var CourseActions, CourseListingActions, CourseListingStore, CourseStore, DELETED, DELETING, FAILED, LOADED, LOADING, _, flux, ref;
 
_ = require('underscore');
 
flux = require('flux-react');
 
ref = require('./course'), CourseActions = ref.CourseActions, CourseStore = ref.CourseStore;
 
LOADING = 'loading';
 
LOADED = 'loaded';
 
FAILED = 'failed';
 
DELETING = 'deleting';
 
DELETED = 'deleted';
 
CourseListingActions = flux.createActions(['load', 'loaded', 'reset', 'FAILED', 'delete', 'deleted']);
 
CourseListingStore = flux.createStore({
  actions: _.values(CourseListingActions),
  _asyncStatus: null,
  load: function() {
    this._asyncStatus = LOADING;
    return this.emit('load');
  },
  reset: function() {
    this._course_ids = [];
    CourseActions.reset();
    this._asyncStatus = null;
    return this.emitChange();
  },
  FAILED: function() {
    this._asyncStatus = FAILED;
    return this.emit('failed');
  },
  loaded: function(courses) {
    this._course_ids = _.map(courses, function(course) {
      CourseActions.loaded(course, course.id);
      return course.id;
    });
    this._asyncStatus = LOADED;
    return this.emit('loaded');
  },
  "delete": function(courseId) {
    this._asyncStatus[courseId] = DELETING;
    this._course_ids = _.without(this._course_ids, courseId);
    return this.emit(DELETING);
  },
  deleted: function(courseId) {
    this._asyncStatus[courseId] = DELETED;
    return this.emit(DELETED);
  },
  exports: {
    isLoading: function() {
      return this._asyncStatus === LOADING;
    },
    isLoaded: function() {
      return this._asyncStatus === LOADED;
    },
    isFailed: function() {
      return this._asyncStatus === FAILED;
    },
    ensureLoaded: function() {
      if (CourseListingStore.isLoaded()) {
        return false;
      } else {
        if (!CourseListingStore.isLoading()) {
          CourseListingActions.load();
        }
        return true;
      }
    },
    allCourses: function() {
      return _.compact(_.map(this._course_ids, CourseStore.get));
    }
  }
});
 
module.exports = {
  CourseListingActions: CourseListingActions,
  CourseListingStore: CourseListingStore
};