master
 1import * as events from '../events';
 2
 3export default class FetchWorkouts {
 4  constructor(eventAggregator, api) {
 5    this.eventAggregator = eventAggregator;
 6    this.api = api;
 7  }
 8
 9  subscribeTo(eventAggregator) {
10    eventAggregator.subscribe(events.FETCH_WORKOUTS, this);
11  }
12
13  notify(event) {
14    this.api.get('/workouts', this.onResponse.bind(this));
15  }
16
17  onResponse(json) {
18    this.eventAggregator.publish({
19      event: events.FETCHED_WORKOUTS,
20      workouts: json.workouts || []
21    });
22  }
23}