import { Observable } from 'rxjs';
const singleton = Symbol();
const singletonEnforcer = Symbol();
export class HttpService {
    constructor(enforcer) {
        this.optionDefaults = {
            cache: 'no-cache',
            credentials: 'same-origin',
            headers: {},
            mode: 'same-origin',
            method: 'GET',
        };
        if (enforcer !== singletonEnforcer) {
            throw new Error('Cannot construct singleton');
        }
        this._type = 'HttpService';
    }
    get(url, options = this.optionDefaults) {
        return Observable.create(observer => {
            fetch(url, options)
                .then(response => response.json()) // or text() or blob() etc.
                .then(data => {
                observer.next(data);
                observer.complete();
            })
                .catch(err => {
                console.error('http.get error:', err);
                observer.error(err);
            });
        });
        // data$.subscribe(data => /*do something with data*/);
    }
    put(url, object, options) {
    }
    post(url, object, options) {
    }
    delete(url, object, options) {
    }
    static get instance() {
        if (!this[singleton]) {
            this[singleton] = new HttpService(singletonEnforcer);
        }
        return this[singleton];
    }
    get type() {
        return this._type;
    }
    set type(value) {
        this._type = value;
    }
}
//# sourceMappingURL=http-service.js.map