BigW Consortium Gitlab

Commit ca5982af by Filipa Lacerda

Changes after review - receives service and method to match current architecture

parent 557c5b0d
import Vue from 'vue';
import VueResource from 'vue-resource';
import httpStatusCodes from './http_status'; import httpStatusCodes from './http_status';
Vue.use(VueResource);
/** /**
* Polling utility for handling realtime updates with Vue.Resource get method. * Polling utility for handling realtime updates.
* Service for vue resouce and method need to be provided as props
* *
* @example * @example
* new poll({ * new poll({
* url: 'endopoint', * resource: resource,
* data: {}, * method: 'name',
* successCallback: () => {},
* errorCallback: () => {},
* }).makeRequest();
*
* this.service = new BoardsService(endpoint);
* new poll({
* resource: this.service,
* method: 'get',
* successCallback: () => {}, * successCallback: () => {},
* errorCallback: () => {}, * errorCallback: () => {},
* }).makeRequest(); * }).makeRequest();
...@@ -47,8 +52,8 @@ export default class poll { ...@@ -47,8 +52,8 @@ export default class poll {
} }
makeRequest() { makeRequest() {
return Vue.http.get(this.options.url, this.options.data) return this.options.resource[this.options.method]()
.then(this.checkConditions) .then(this.checkConditions.bind(this))
.catch(error => this.options.errorCallback(error)); .catch(error => this.options.errorCallback(error));
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment