Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-hooks-worker

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-hooks-worker - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

4

CHANGELOG.md

@@ -5,2 +5,6 @@ # Change Log

## [1.0.3] - 2021-12-17
### Changed
- fix: handle nullish result from worker function #36
## [1.0.2] - 2021-11-04

@@ -7,0 +11,0 @@ ### Changed

2

dist/index.modern.js

@@ -1,2 +0,2 @@

import{useState as r,useMemo as e,useRef as t,useEffect as n}from"react";const o={};function s(s,a){const[i,l]=r(o),u=e(s,[s]),c=t(u);return n(()=>{c.current=u;let r=r=>l(r);return u.onmessage=e=>r({result:e.data}),u.onerror=()=>r({error:"error"}),u.onmessageerror=()=>r({error:"messageerror"}),()=>{r=()=>null,u.terminate(),l(o)}},[u]),n(()=>{c.current.postMessage(a)},[a]),i}function a(r){function e(r){if(Object(r)!==r)return Promise.reject(new TypeError(r+" is not an object."));var e=r.done;return Promise.resolve(r.value).then(function(r){return{value:r,done:e}})}return a=function(r){this.s=r,this.n=r.next},a.prototype={s:null,n:null,next:function(){return e(this.n.apply(this.s,arguments))},return:function(r){var t=this.s.return;return void 0===t?Promise.resolve({value:r,done:!0}):e(t.apply(this.s,arguments))},throw:function(r){var t=this.s.return;return void 0===t?Promise.reject(r):e(t.apply(this.s,arguments))}},new a(r)}function i(r){self.onmessage=async e=>{const t=r(e.data);if(t[Symbol.asyncIterator]){var n,o=!1,s=!1;try{for(var i,l=function(r){var e,t,n,o=2;for("undefined"!=typeof Symbol&&(t=Symbol.asyncIterator,n=Symbol.iterator);o--;){if(t&&null!=(e=r[t]))return e.call(r);if(n&&null!=(e=r[n]))return new a(e.call(r));t="@@asyncIterator",n="@@iterator"}throw new TypeError("Object is not async iterable")}(t);o=!(i=await l.next()).done;o=!1)self.postMessage(i.value)}catch(r){s=!0,n=r}finally{try{o&&null!=l.return&&await l.return()}finally{if(s)throw n}}}else if(t[Symbol.iterator])for(const r of t)self.postMessage(r);else self.postMessage(await t)}}export{i as exposeWorker,s as useWorker};
import{useState as r,useMemo as e,useRef as t,useEffect as n}from"react";const o={};function s(s,a){const[i,l]=r(o),u=e(s,[s]),c=t(u);return n(()=>{c.current=u;let r=r=>l(r);return u.onmessage=e=>r({result:e.data}),u.onerror=()=>r({error:"error"}),u.onmessageerror=()=>r({error:"messageerror"}),()=>{r=()=>null,u.terminate(),l(o)}},[u]),n(()=>{c.current.postMessage(a)},[a]),i}function a(r){function e(r){if(Object(r)!==r)return Promise.reject(new TypeError(r+" is not an object."));var e=r.done;return Promise.resolve(r.value).then(function(r){return{value:r,done:e}})}return a=function(r){this.s=r,this.n=r.next},a.prototype={s:null,n:null,next:function(){return e(this.n.apply(this.s,arguments))},return:function(r){var t=this.s.return;return void 0===t?Promise.resolve({value:r,done:!0}):e(t.apply(this.s,arguments))},throw:function(r){var t=this.s.return;return void 0===t?Promise.reject(r):e(t.apply(this.s,arguments))}},new a(r)}function i(r){self.onmessage=async e=>{const t=r(e.data);if(t&&t[Symbol.asyncIterator]){var n,o=!1,s=!1;try{for(var i,l=function(r){var e,t,n,o=2;for("undefined"!=typeof Symbol&&(t=Symbol.asyncIterator,n=Symbol.iterator);o--;){if(t&&null!=(e=r[t]))return e.call(r);if(n&&null!=(e=r[n]))return new a(e.call(r));t="@@asyncIterator",n="@@iterator"}throw new TypeError("Object is not async iterable")}(t);o=!(i=await l.next()).done;o=!1)self.postMessage(i.value)}catch(r){s=!0,n=r}finally{try{o&&null!=l.return&&await l.return()}finally{if(s)throw n}}}else if(t&&t[Symbol.iterator])for(const r of t)self.postMessage(r);else self.postMessage(await t)}}export{i as exposeWorker,s as useWorker};
//# sourceMappingURL=index.modern.mjs.map

@@ -1,2 +0,2 @@

!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((n||self).reactHooksWorker={},n.react)}(this,function(n,t){var e={};function r(n){function t(n){if(Object(n)!==n)return Promise.reject(new TypeError(n+" is not an object."));var t=n.done;return Promise.resolve(n.value).then(function(n){return{value:n,done:t}})}return r=function(n){this.s=n,this.n=n.next},r.prototype={s:null,n:null,next:function(){return t(this.n.apply(this.s,arguments))},return:function(n){var e=this.s.return;return void 0===e?Promise.resolve({value:n,done:!0}):t(e.apply(this.s,arguments))},throw:function(n){var e=this.s.return;return void 0===e?Promise.reject(n):t(e.apply(this.s,arguments))}},new r(n)}function o(n,t){(null==t||t>n.length)&&(t=n.length);for(var e=0,r=new Array(t);e<t;e++)r[e]=n[e];return r}function i(n,t,e){if(!n.s){if(e instanceof u){if(!e.s)return void(e.o=i.bind(null,n,t));1&t&&(t=e.s),e=e.v}if(e&&e.then)return void e.then(i.bind(null,n,t),i.bind(null,n,2));n.s=t,n.v=e;var r=n.o;r&&r(n)}}var u=/*#__PURE__*/function(){function n(){}return n.prototype.then=function(t,e){var r=new n,o=this.s;if(o){var u=1&o?t:e;if(u){try{i(r,1,u(this.v))}catch(n){i(r,2,n)}return r}return this}return this.o=function(n){try{var o=n.v;1&n.s?i(r,1,t?t(o):o):e?i(r,1,e(o)):i(r,2,o)}catch(n){i(r,2,n)}},r},n}();function f(n){return n instanceof u&&1&n.s}function a(n,t){try{var e=n()}catch(n){return t(!0,n)}return e&&e.then?e.then(t.bind(null,!1),t.bind(null,!0)):t(!1,e)}n.exposeWorker=function(n){self.onmessage=function(t){try{var e=n(t.data);return Promise.resolve(function(){if(e[Symbol.asyncIterator]){var n,t=!1,c=!1;return a(function(){return function(n,o){try{var a=function(){var n,o=function(n){var t,e,o,i=2;for("undefined"!=typeof Symbol&&(e=Symbol.asyncIterator,o=Symbol.iterator);i--;){if(e&&null!=(t=n[e]))return t.call(n);if(o&&null!=(t=n[o]))return new r(t.call(n));e="@@asyncIterator",o="@@iterator"}throw new TypeError("Object is not async iterable")}(e),a=function(n,t,e){for(var r;;){var o=n();if(f(o)&&(o=o.v),!o)return a;if(o.then){r=0;break}var a=e();if(a&&a.then){if(!f(a)){r=1;break}a=a.s}if(t){var c=t();if(c&&c.then&&!f(c)){r=2;break}}}var s=new u,l=i.bind(null,s,2);return(0===r?o.then(v):1===r?a.then(h):c.then(d)).then(void 0,l),s;function h(r){a=r;do{if(t&&(c=t())&&c.then&&!f(c))return void c.then(d).then(void 0,l);if(!(o=n())||f(o)&&!o.v)return void i(s,1,a);if(o.then)return void o.then(v).then(void 0,l);f(a=e())&&(a=a.v)}while(!a||!a.then);a.then(h).then(void 0,l)}function v(n){n?(a=e())&&a.then?a.then(h).then(void 0,l):h(a):i(s,1,a)}function d(){(o=n())?o.then?o.then(v).then(void 0,l):v(o):i(s,1,a)}}(function(){return!!Promise.resolve(o.next()).then(function(e){return t=!(n=e).done})},function(){return!!(t=!1)},function(){self.postMessage(n.value)});if(a&&a.then)return a.then(function(){})}()}catch(n){return o(n)}return a&&a.then?a.then(void 0,o):a}(0,function(t){c=!0,n=t})},function(e,r){function o(n){if(e)throw r;return r}var i=a(function(){var n=function(){if(t&&null!=_iterator.return)return Promise.resolve(_iterator.return()).then(function(){})}();if(n&&n.then)return n.then(function(){})},function(t,e){if(c)throw n;if(t)throw e;return e});return i&&i.then?i.then(o):o()})}var s=function(){if(!e[Symbol.iterator]){var n=self,t=n.postMessage;return Promise.resolve(e).then(function(e){t.call(n,e)})}for(var r,i=function(n,t){var e="undefined"!=typeof Symbol&&n[Symbol.iterator]||n["@@iterator"];if(e)return(e=e.call(n)).next.bind(e);if(Array.isArray(n)||(e=function(n,t){if(n){if("string"==typeof n)return o(n,t);var e=Object.prototype.toString.call(n).slice(8,-1);return"Object"===e&&n.constructor&&(e=n.constructor.name),"Map"===e||"Set"===e?Array.from(n):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?o(n,t):void 0}}(n))){e&&(n=e);var r=0;return function(){return r>=n.length?{done:!0}:{done:!1,value:n[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(e);!(r=i()).done;)self.postMessage(r.value)}();if(s&&s.then)return s.then(function(){})}())}catch(t){return Promise.reject(t)}}},n.useWorker=function(n,r){var o=t.useState(e),i=o[0],u=o[1],f=t.useMemo(n,[n]),a=t.useRef(f);return t.useEffect(function(){a.current=f;var n=function(n){return u(n)};return f.onmessage=function(t){return n({result:t.data})},f.onerror=function(){return n({error:"error"})},f.onmessageerror=function(){return n({error:"messageerror"})},function(){n=function(){return null},f.terminate(),u(e)}},[f]),t.useEffect(function(){a.current.postMessage(r)},[r]),i}});
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((n||self).reactHooksWorker={},n.react)}(this,function(n,t){var e={};function r(n){function t(n){if(Object(n)!==n)return Promise.reject(new TypeError(n+" is not an object."));var t=n.done;return Promise.resolve(n.value).then(function(n){return{value:n,done:t}})}return r=function(n){this.s=n,this.n=n.next},r.prototype={s:null,n:null,next:function(){return t(this.n.apply(this.s,arguments))},return:function(n){var e=this.s.return;return void 0===e?Promise.resolve({value:n,done:!0}):t(e.apply(this.s,arguments))},throw:function(n){var e=this.s.return;return void 0===e?Promise.reject(n):t(e.apply(this.s,arguments))}},new r(n)}function o(n,t){(null==t||t>n.length)&&(t=n.length);for(var e=0,r=new Array(t);e<t;e++)r[e]=n[e];return r}function i(n,t,e){if(!n.s){if(e instanceof u){if(!e.s)return void(e.o=i.bind(null,n,t));1&t&&(t=e.s),e=e.v}if(e&&e.then)return void e.then(i.bind(null,n,t),i.bind(null,n,2));n.s=t,n.v=e;var r=n.o;r&&r(n)}}var u=/*#__PURE__*/function(){function n(){}return n.prototype.then=function(t,e){var r=new n,o=this.s;if(o){var u=1&o?t:e;if(u){try{i(r,1,u(this.v))}catch(n){i(r,2,n)}return r}return this}return this.o=function(n){try{var o=n.v;1&n.s?i(r,1,t?t(o):o):e?i(r,1,e(o)):i(r,2,o)}catch(n){i(r,2,n)}},r},n}();function f(n){return n instanceof u&&1&n.s}function a(n,t){try{var e=n()}catch(n){return t(!0,n)}return e&&e.then?e.then(t.bind(null,!1),t.bind(null,!0)):t(!1,e)}n.exposeWorker=function(n){self.onmessage=function(t){try{var e=n(t.data);return Promise.resolve(function(){if(e&&e[Symbol.asyncIterator]){var n,t=!1,c=!1;return a(function(){return function(n,o){try{var a=function(){var n,o=function(n){var t,e,o,i=2;for("undefined"!=typeof Symbol&&(e=Symbol.asyncIterator,o=Symbol.iterator);i--;){if(e&&null!=(t=n[e]))return t.call(n);if(o&&null!=(t=n[o]))return new r(t.call(n));e="@@asyncIterator",o="@@iterator"}throw new TypeError("Object is not async iterable")}(e),a=function(n,t,e){for(var r;;){var o=n();if(f(o)&&(o=o.v),!o)return a;if(o.then){r=0;break}var a=e();if(a&&a.then){if(!f(a)){r=1;break}a=a.s}if(t){var c=t();if(c&&c.then&&!f(c)){r=2;break}}}var s=new u,l=i.bind(null,s,2);return(0===r?o.then(v):1===r?a.then(h):c.then(d)).then(void 0,l),s;function h(r){a=r;do{if(t&&(c=t())&&c.then&&!f(c))return void c.then(d).then(void 0,l);if(!(o=n())||f(o)&&!o.v)return void i(s,1,a);if(o.then)return void o.then(v).then(void 0,l);f(a=e())&&(a=a.v)}while(!a||!a.then);a.then(h).then(void 0,l)}function v(n){n?(a=e())&&a.then?a.then(h).then(void 0,l):h(a):i(s,1,a)}function d(){(o=n())?o.then?o.then(v).then(void 0,l):v(o):i(s,1,a)}}(function(){return!!Promise.resolve(o.next()).then(function(e){return t=!(n=e).done})},function(){return!!(t=!1)},function(){self.postMessage(n.value)});if(a&&a.then)return a.then(function(){})}()}catch(n){return o(n)}return a&&a.then?a.then(void 0,o):a}(0,function(t){c=!0,n=t})},function(e,r){function o(n){if(e)throw r;return r}var i=a(function(){var n=function(){if(t&&null!=_iterator.return)return Promise.resolve(_iterator.return()).then(function(){})}();if(n&&n.then)return n.then(function(){})},function(t,e){if(c)throw n;if(t)throw e;return e});return i&&i.then?i.then(o):o()})}var s=function(){if(!e||!e[Symbol.iterator]){var n=self,t=n.postMessage;return Promise.resolve(e).then(function(e){t.call(n,e)})}for(var r,i=function(n,t){var e="undefined"!=typeof Symbol&&n[Symbol.iterator]||n["@@iterator"];if(e)return(e=e.call(n)).next.bind(e);if(Array.isArray(n)||(e=function(n,t){if(n){if("string"==typeof n)return o(n,t);var e=Object.prototype.toString.call(n).slice(8,-1);return"Object"===e&&n.constructor&&(e=n.constructor.name),"Map"===e||"Set"===e?Array.from(n):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?o(n,t):void 0}}(n))){e&&(n=e);var r=0;return function(){return r>=n.length?{done:!0}:{done:!1,value:n[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(e);!(r=i()).done;)self.postMessage(r.value)}();if(s&&s.then)return s.then(function(){})}())}catch(t){return Promise.reject(t)}}},n.useWorker=function(n,r){var o=t.useState(e),i=o[0],u=o[1],f=t.useMemo(n,[n]),a=t.useRef(f);return t.useEffect(function(){a.current=f;var n=function(n){return u(n)};return f.onmessage=function(t){return n({result:t.data})},f.onerror=function(){return n({error:"error"})},f.onmessageerror=function(){return n({error:"messageerror"})},function(){n=function(){return null},f.terminate(),u(e)}},[f]),t.useEffect(function(){a.current.postMessage(r)},[r]),i}});
//# sourceMappingURL=index.umd.js.map
{
"name": "react-hooks-worker",
"description": "React custom hooks for web workers",
"version": "1.0.2",
"version": "1.0.3",
"author": "Daishi Kato",

@@ -40,3 +40,4 @@ "repository": {

"examples:04_inline": "DIR=04_inline webpack-dev-server",
"examples:05_generator": "DIR=05_generator webpack-dev-server"
"examples:05_generator": "DIR=05_generator webpack-dev-server",
"examples:06_async": "DIR=06_async webpack-dev-server"
},

@@ -52,18 +53,18 @@ "keywords": [

"devDependencies": {
"@types/jest": "^27.0.2",
"@types/react": "^17.0.34",
"@types/jest": "^27.0.3",
"@types/react": "^17.0.37",
"@types/react-dom": "^17.0.11",
"@types/react-test-renderer": "^17.0.1",
"@typescript-eslint/eslint-plugin": "^5.3.0",
"@typescript-eslint/parser": "^5.3.0",
"@typescript-eslint/eslint-plugin": "^5.7.0",
"@typescript-eslint/parser": "^5.7.0",
"documentation": "^13.2.5",
"eslint": "^8.1.0",
"eslint-config-airbnb": "^18.2.1",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-react": "^7.26.1",
"eslint-plugin-react-hooks": "^4.2.0",
"eslint": "^8.4.1",
"eslint-config-airbnb": "^19.0.2",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-react": "^7.27.1",
"eslint-plugin-react-hooks": "^4.3.0",
"html-webpack-plugin": "^5.5.0",
"jest": "^27.3.1",
"microbundle": "^0.14.1",
"jest": "^27.4.5",
"microbundle": "^0.14.2",
"npm-run-all": "^4.1.5",

@@ -73,8 +74,8 @@ "react": "^17.0.2",

"react-test-renderer": "^17.0.2",
"ts-jest": "^27.0.7",
"ts-jest": "^27.1.2",
"ts-loader": "^9.2.6",
"typescript": "^4.4.4",
"webpack": "^5.61.0",
"typescript": "^4.5.4",
"webpack": "^5.65.0",
"webpack-cli": "^4.9.1",
"webpack-dev-server": "^4.4.0"
"webpack-dev-server": "^4.6.0"
},

@@ -81,0 +82,0 @@ "peerDependencies": {

@@ -23,5 +23,5 @@ /* eslint-disable @typescript-eslint/no-explicit-any */

const r = func(e.data);
if (r[Symbol.asyncIterator]) {
if (r && r[Symbol.asyncIterator]) {
for await (const i of r) (self.postMessage as any /* FIXME */)(i);
} else if (r[Symbol.iterator]) {
} else if (r && r[Symbol.iterator]) {
for (const i of r) (self.postMessage as any /* FIXME */)(i);

@@ -28,0 +28,0 @@ } else {

@@ -44,2 +44,3 @@ import {

const cleanup = () => {
// eslint-disable-next-line react/function-component-definition
setStateSafe = () => null; // we should not setState after cleanup.

@@ -46,0 +47,0 @@ worker.terminate();

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc