Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from rdfjs-base/fetch-config-headers
feat: added Headers class to fetch, added .config method to fetch
- Loading branch information
Showing
3 changed files
with
101 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,40 @@ | ||
import fetch from '@rdfjs/fetch-lite' | ||
|
||
class FetchFactory { | ||
fetch (url, options = {}) { | ||
const factory = typeof this.dataset === 'function' ? this : null | ||
const formats = this.formats | ||
function createFetch (context) { | ||
const result = function (url, options = {}) { | ||
const factory = typeof context.dataset === 'function' ? context : null | ||
|
||
return fetch(url, { | ||
...options, | ||
factory, | ||
fetch: context._fetch.fetch, | ||
formats: context.formats | ||
}) | ||
} | ||
|
||
return fetch(url, { ...options, factory, formats }) | ||
result.config = function (key, value) { | ||
context._fetch[key] = value | ||
} | ||
|
||
result.Headers = fetch.Headers | ||
|
||
return result | ||
} | ||
|
||
FetchFactory.exports = ['fetch'] | ||
class FetchFactory { | ||
init () { | ||
this._fetch = { | ||
fetch: null | ||
} | ||
|
||
this.fetch = createFetch(this) | ||
} | ||
|
||
clone (original) { | ||
for (const [key, value] of Object.entries(original._fetch)) { | ||
this._fetch[key] = value | ||
} | ||
} | ||
} | ||
|
||
export default FetchFactory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters