comlink-fetch
Advanced tools
Comparing version 0.0.1 to 0.1.0
import { Comlink } from 'https://cdn.jsdelivr.net/npm/comlinkjs@2.3/comlink.global.min.js'; | ||
const fetchWorker = new Worker('./../src/fetch.worker.js'); | ||
const worker = new Worker('./../src/fetch.worker.js'); | ||
const api = Comlink.proxy(fetchWorker); | ||
const proxy = Comlink.proxy(worker); | ||
async function init() { | ||
const backend = await new api.Backend(); | ||
const Fetch = await new proxy.Fetch(); | ||
backend.setBaseUrl("https://jsonplaceholder.typicode.com/"); | ||
backend.setDefaultHeaders({'Content-Type': 'application/json'}); | ||
backend.setDefaultBody({lang: 'en'}); | ||
Fetch.setBaseUrl("https://jsonplaceholder.typicode.com/"); | ||
Fetch.setDefaultHeaders({'Content-Type': 'application/json'}); | ||
Fetch.setDefaultBody({lang: 'en'}); | ||
backend.get('users/1'); | ||
backend.get('users/2'); | ||
backend.post('posts/3'); | ||
backend.put('posts/4'); | ||
backend.delete('posts/5'); | ||
Fetch.get('users/1'); | ||
Fetch.get('users/2'); | ||
Fetch.post('posts/3'); | ||
Fetch.put('posts/4'); | ||
Fetch.delete('posts/5'); | ||
}; | ||
@@ -20,0 +20,0 @@ |
{ | ||
"name": "comlink-fetch", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "A Web worker fetch wrapper using comlink ", | ||
@@ -5,0 +5,0 @@ "main": "src/fetch.worker.js", |
# Comlink Fetch | ||
An ES6 wrapper around fetch for [GoogleChromeLabs/comlink](https://github.com/GoogleChromeLabs/comlink) | ||
# Install | ||
``` | ||
npm install comlink-fetch --save | ||
``` |
importScripts('https://cdn.jsdelivr.net/npm/comlinkjs@2.3/comlink.global.min.js'); | ||
class Backend { | ||
class Fetch { | ||
constructor() { | ||
@@ -5,0 +5,0 @@ this._baseUrl = ""; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3710
10