{"name":"comlink","version":"4.0.0-alpha.1","description":"Comlink makes WebWorkers enjoyable","main":"comlink.js","module":"comlink.js","types":"comlink.d.ts","scripts":{"build":"rollup -c","test:unit":"karma start","test:types":"tsc -t esnext -m esnext --lib esnext,dom --moduleResolution node --noEmit tests/type-checks.ts","test":"npm run fmt_test && npm run build && npm run test:types && npm run test:unit","fmt":"prettier --write ./*.{js,ts,md,json} ./{src,docs,tests}/**/*.{js,ts,md,json}","fmt_test":"test $(prettier -l ./*.{js,ts,md,json} ./{src,docs,tests}/**/*.{js,ts,md,json} | wc -l) -eq 0","watchtest":"karma start --no-single-run --browsers ChromeHeadless"},"husky":{"hooks":{"pre-commit":"npm test"}},"keywords":[],"author":{"name":"Surma","email":"surma@google.com"},"repository":{"type":"git","url":"git+https://github.com/GoogleChromeLabs/comlink.git"},"license":"Apache-2.0","devDependencies":{"chai":"4.2.0","conditional-type-checks":"^1.0.0","husky":"^1.3.1","karma":"3.1.4","karma-chai":"0.1.0","karma-chrome-launcher":"2.2.0","karma-detect-browsers":"^2.3.3","karma-firefox-launcher":"1.1.0","karma-mocha":"1.3.0","karma-safari-launcher":"^1.0.0","karma-safaritechpreview-launcher":"2.0.2","mocha":"5.2.0","prettier":"1.16.1","rollup":"^1.6.0","rollup-plugin-terser":"^4.0.4","rollup-plugin-typescript2":"^0.19.3","typescript":"^3.3.3333"},"dependencies":{},"readme":"# Comlink\n\nComlink’s goal is to make [WebWorkers][webworker] enjoyable. Comlink removes the mental barrier of thinking about `postMessage` and hides the fact that you are working with workers.\n\n> Note: Comlink’s goal is to be a building-block for higher-level abstraction libraries. For example, take a look at [Clooney].\n\n```js\n// main.js\nconst MyClass = Comlink.proxy(new Worker(\"worker.js\"));\n// `instance` is an instance of `MyClass` that lives in the worker!\nconst instance = await new MyClass();\nawait instance.logSomething(); // logs “myValue = 42”\n```\n\n```js\n// worker.js\nconst myValue = 42;\nclass MyClass {\n  logSomething() {\n    console.log(`myValue = ${myValue}`);\n  }\n}\nComlink.expose(MyClass, self);\n```\n\n## Browsers support & bundle size\n\n![Chrome 56+](https://img.shields.io/badge/Chrome-56+-green.svg?style=flat-square)\n![Edge 15+](https://img.shields.io/badge/Edge-15+-green.svg?style=flat-square)\n![Firefox 52+](https://img.shields.io/badge/Firefox-52+-green.svg?style=flat-square)\n![Opera 43+](https://img.shields.io/badge/Opera-43+-green.svg?style=flat-square)\n![Safari 10.1+](https://img.shields.io/badge/Safari-10.1+-green.svg?style=flat-square)\n![Samsung Internet 6.0+](https://img.shields.io/badge/Samsung_Internet-6.0+-green.svg?style=flat-square)\n\nBrowsers without [ES6 Proxy] support can use the [proxy-polyfill].\n\n**Size**: ~3.9k, ~1.6k gzip’d\n\n## Introduction\n\nWebWorkers are a web API that allow you to run code in a separate thread. To communicate with another thread, WebWorkers offer the `postMessage` API. You can send messages in form of [transferable] JavaScript objects using `myWorker.postMessage(someObject)`, triggering a `message` event inside the worker.\n\nComlink turns this messaged-based API into a something more developer-friendly: Values from one thread can be used within the other thread (and vice versa) just like local values.\n\nComlink can be used with anything that offers `postMessage` like windows, iframes and ServiceWorkers.\n\n## Download\n\nYou can download Comlink from the [dist folder][dist]. Alternatively, you can\ninstall it via npm\n\n```\n$ npm install --save comlinkjs\n```\n\nor use a CDN like [delivrjs]:\n\n```\nhttps://cdn.jsdelivr.net/npm/comlinkjs@3.1.1/umd/comlink.js\n```\n\n## Examples\n\nThere’s a collection of examples in the [examples directory][examples].\n\n## API\n\nThe Comlink module exports 3 functions:\n\n### `Comlink.proxy(endpoint)`\n\n> Returns the value that is exposed on the other side of `endpoint`.\n\n`proxy` creates an ES6 proxy and sends all operations performed on that proxy through `endpoint`. `endpoint` can be a `Window`, a `Worker` or a `MessagePort`.\\* The other endpoint of the channel should be passed to `Comlink.expose`.\n\nIf you invoke function, all parameters will be structurally cloned or transferred if they are [transferable]. If you want to pass a function as a parameters (e.g. callbacks), make sure to use `proxyValue` (see below). Same applies to the return value of a function.\n\n\\*) Technically it can be any object with `postMessage`, `addEventListener` and\n`removeEventListener`.\n\n### `Comlink.expose(obj, endpoint)`\n\n> Exposes `obj` to `endpoint`. Use `Comlink.proxy` on the other end of `endpoint`.\n\n`expose` is the counter-part to `proxy`. It listens for RPC messages on `endpoint` and applies the operations to `obj`. Return values of functions will be structurally cloned or transfered if they are [transferable].\n\n### `Comlink.proxyValue(value)`\n\n> Makes sure a parameter or return value is proxied, not copied.\n\nBy default, all parameters to a function that are not [transferable] are copied (structural clone):\n\n```js\n// main.js\nconst api = Comlink.proxy(new Worker(\"worker.js\"));\nconst obj = { x: 0 };\nawait api.setXto4(obj);\nconsole.log(obj.x); // logs 0\n```\n\nThe worker receives a copy of `obj`, so any mutation of `obj` done by the worker won’t affect the original object. If the value should _not_ be copied but instead be proxied, use `Comlink.proxyValue`:\n\n```diff\n- await api.setXto4(obj);\n+ await api.setXto4(Comlink.proxyValue(obj));\n```\n\n`console.log(obj.x)` will now log 4.\n\nKeep in mind that functions cannot be copied. Unless they are used in combination with `Comlink.proxyValue`, they will get discarded during copy.\n\n[clooney]: https://github.com/GoogleChromeLabs/clooney\n[webworker]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API\n[umd]: https://github.com/umdjs/umd\n[transferable]: https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n[messageport]: https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[examples]: https://github.com/GoogleChromeLabs/comlink/tree/master/docs/examples\n[dist]: https://github.com/GoogleChromeLabs/comlink/tree/master/dist\n[delivrjs]: https://cdn.jsdelivr.net/\n[es6 proxy]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy\n[proxy-polyfill]: https://github.com/GoogleChrome/proxy-polyfill\n\n---\n\nLicense Apache-2.0\n","readmeFilename":"README.md","gitHead":"4d3cf7254363b2f2eea08bc03e74724bb318a82e","bugs":{"url":"https://github.com/GoogleChromeLabs/comlink/issues"},"homepage":"https://github.com/GoogleChromeLabs/comlink#readme","_id":"comlink@4.0.0-alpha.1","_nodeVersion":"11.9.0","_npmVersion":"6.8.0","dist":{"integrity":"sha512-E2RlU+mMwAS5wRHGPF0X0nMSJzPJbIii9vV1DxisP0E1aqreObQr/Qd9UwgV0w/zKmnl1Xc3qpXU0HWacPn6GQ==","shasum":"303eed6e74feff8414a75eb7ca3d72904f0042bd","tarball":"http://registry-npm.ywwl.com/comlink/download/comlink-4.0.0-alpha.1.tgz","fileCount":48,"unpackedSize":73583,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJchaISCRA9TVsSAnZWagAAIYkP+wZAodyNp2PWDYwVErkT\nG9MFv3m4P7eNSwwHBMGJU14vlNh/yJAmdl0WqrZediHaf4HML3x3Ks/FGfcN\ntt8ZdMDn3nO6XX/2GN8NF1bwrBgl5SS6BLLSVDAmksNPWfAQIfAx2xdpoIUy\nFqG6DiZ18RhBIK5nJLesjw2ryBEqp50HXahr9eGtgHeArAJDLPdQ5v/nz+Er\nGY4IcMiCoSGFfscBtwgu7FKafbk7C9TTBMwv9CsBlFVFmx/AIworhZCN/sac\n4tiiVCWLM+T+YxBoqnLe0rFOfIUYPf8NNdeYzwkodfVPSTQEzcjoXxAe/1V/\nFV6vmDaKT1Hn0TpFSRs7HvsL4qnxSDmwKVg+TrUqkzMvEjqA34ylmFOYu3nC\nqe8JQBMXtyVfw+jAPlF9UZa6BQkMLDRoEHZ4rF9Aue0zOq5+pxN4dnRbjFGD\nX+/HY8iV6w9fxs9KwAH1+PYE7mT49NLFrJUbOQtfi8icZNeni8Gm2+jUnp+q\ntdlgAnVCCQ06aLyl0+o3D3srwhrnHVnDdma9+vX34tB0vSmGzgUJ/r00G3AU\nNXh+SkxgqQUtlAe2kOoBxCDge4oOnHwvDRo92EMveg1HD6LJfcGfU9uYJNww\n6WVxmuCzSYhOpQKFl5X1530y3kAc0wMiPK08Xs/0t1Ufh4s8Gep6gNcvzFBH\nntF4\r\n=hHh9\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFBsWLhGHmUqT0tL19LgdTnrbIs4BqqpTxDITopgxSJqAiEAkjQsxiZpHoQ3EOBHkOtzogXy8ex4i00MhcEf0f24A5g="}],"size":20403,"noattachment":false,"key":"/comlink/-/comlink-4.0.0-alpha.1.tgz"},"maintainers":[{"email":"jason@developit.ca","name":"developit"},{"email":"surma@surma.link","name":"surma"}],"_npmUser":{"name":"surma","email":"surma@surma.link"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/comlink_4.0.0-alpha.1_1552261649582_0.14912312971643993"},"_hasShrinkwrap":false,"publish_time":1552261649759,"_cnpm_publish_time":1552261649759,"dist-tags":{"alpha":"4.0.0-alpha.10","latest":"4.4.2","next":"4.0.0-alpha.10"}}