summaryrefslogtreecommitdiff
path: root/app/services/queries/fetch-new-workout.js
blob: e0203ea272f16a3fefca0a608528690a1aa8b963 (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 FetchNewWorkout {
  constructor(eventAggregator, api) {
    this.eventAggregator = eventAggregator;
    this.api = api;
  }

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

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

  onResponse(json) {
    this.eventAggregator.publish({
      event: events.FETCHED_NEW_WORKOUT,
      ...json
    });
  }
}