John Cowen 5c0ec13fb9
ui: Run Ember native class code mod (#9093)
* ui: Apply native class codemod to all services

* ui: Apply native class codemod to routes

* ui: Apply native class codemod to controllers

* Fix up ember proxy `content` issue

* Add a CreateTime on policy creation

* Minor formatting

* Convert child based saving to use ec instead of custom approach

* Remove custom event source repo wrapping initializer

* Repos here are no longer proxy objects revert to using them normally

* Remove areas of code that were used to set up source backed repos
2020-11-09 09:25:35 +00:00

36 lines
1.2 KiB
JavaScript

import Service, { inject as service } from '@ember/service';
import { get } from '@ember/object';
import { BlockingEventSource as EventSource } from 'consul-ui/utils/dom/event-source';
import { ifNotBlocking } from 'consul-ui/services/settings';
import { restartWhenAvailable } from 'consul-ui/services/client/http';
import maybeCall from 'consul-ui/utils/maybe-call';
export default class BlockingService extends Service {
@service('client/http')
client;
@service('settings')
settings;
source(find, configuration) {
return new EventSource((configuration, source) => {
const close = source.close.bind(source);
const deleteCursor = () => (configuration.cursor = undefined);
//
return maybeCall(deleteCursor, ifNotBlocking(this.settings))().then(() => {
return find(configuration)
.then(maybeCall(close, ifNotBlocking(this.settings)))
.then(function(res = {}) {
const meta = get(res, 'meta') || {};
if (typeof meta.cursor === 'undefined' && typeof meta.interval === 'undefined') {
close();
}
return res;
})
.catch(restartWhenAvailable(this.client));
});
}, configuration);
}
}