summaryrefslogtreecommitdiff
path: root/app/services/queries/fetch-new-workout.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/services/queries/fetch-new-workout.js')
-rw-r--r--app/services/queries/fetch-new-workout.js23
1 files changed, 23 insertions, 0 deletions
diff --git a/app/services/queries/fetch-new-workout.js b/app/services/queries/fetch-new-workout.js
new file mode 100644
index 0000000..e0203ea
--- /dev/null
+++ b/app/services/queries/fetch-new-workout.js
@@ -0,0 +1,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
+ });
+ }
+}