Skip to content

Commit

Permalink
fix: bind fetch to window in browser context
Browse files Browse the repository at this point in the history
  • Loading branch information
vhf committed Sep 3, 2019
1 parent a5a8d62 commit 0eafbcc
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/sparqlfetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ class SparqlFetcher {
private fetcher: any = new SparqlEndpointFetcher();

constructor(endpoint: string) {
if (typeof window === "undefined") {
this.fetcher = new SparqlEndpointFetcher();
} else {
this.fetcher = new SparqlEndpointFetcher({
fetch: window.fetch.bind(window),
});
}
this.endpoint = endpoint;
this.fetcher.sparqlParsers["application/json"] = {
parseResultsStream: (stream: Stream): Stream => stream.pipe(require("JSONStream").parse("$*")),
Expand Down

0 comments on commit 0eafbcc

Please sign in to comment.