summaryrefslogtreecommitdiff
path: root/app/services/queries/fetch-workouts.js
blob: 4f37e756a7f0fb622824401724578f480c0e9c15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import * as events from '../events';

export default class FetchWorkouts {
  constructor(eventAggregator, api) {
    this.eventAggregator = eventAggregator;
    this.api = api;
  }

  subscribeTo(eventAggregator) {
    eventAggregator.subscribe(events.FETCH_WORKOUTS, this);
  }

  notify(event) {
    this.api.get('/workouts', this.onResponse.bind(this));
  }

  onResponse(json) {
    this.eventAggregator.publish({
      event: events.FETCHED_WORKOUTS,
      workouts: json.workouts || []
    });
  }
}