You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

react-async-hook

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-async-hook - npm Package Compare versions

Comparing version

to
3.1.0

2

dist/index.d.ts

@@ -19,3 +19,3 @@ export declare type AsyncState<R> = {

export declare type UseAsyncOptions<R> = Partial<UseAsyncOptionsNormalized<R>> | undefined | null;
export declare type UseAsyncReturn<R, Args extends any[]> = AsyncState<R> & {
export declare type UseAsyncReturn<R, Args extends any[] = never> = AsyncState<R> & {
set: (value: AsyncState<R>) => void;

@@ -22,0 +22,0 @@ execute: (...args: Args) => Promise<R>;

@@ -34,3 +34,3 @@ 'use strict';

const useAsyncState = (options) => {
const [value, setValue] = react.useState(options.initialState());
const [value, setValue] = react.useState(() => options.initialState());
return {

@@ -113,3 +113,3 @@ value,

};
const useAsync = (asyncFunction, params, options) => useAsync(asyncFunction, params, options);
const useAsync = (asyncFunction, params, options) => useAsyncInternal(asyncFunction, params, options);
const useAsyncAbortable = (asyncFunction, params, options) => {

@@ -116,0 +116,0 @@ const abortControllerRef = react.useRef();

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

"use strict";var e=require("react");const t={loading:!0,result:void 0,error:void 0},r={initialState:()=>t,executeOnMount:!0,executeOnUpdate:!0,setLoading:e=>t,setResult:(e,t)=>({loading:!1,result:e,error:void 0}),setError:(e,t)=>({loading:!1,result:void 0,error:e})},s=(t,s,n)=>{const u=(e=>({...r,...e}))(n),o=(t=>{const[r,s]=e.useState(t.initialState());return{value:r,set:s,setLoading:()=>s(t.setLoading(r)),setResult:e=>s(t.setResult(e,r)),setError:e=>s(t.setError(e,r))}})(u),c=(()=>{const t=e.useRef(!1);return e.useEffect(()=>(t.current=!0,()=>{t.current=!1}),[]),()=>t.current})(),i=(()=>{const t=e.useRef(null);return{set:e=>t.current=e,get:()=>t.current,is:e=>t.current===e}})(),a=e=>c()&&i.is(e),l=(...e)=>{const r=t(...e);if(r instanceof Promise)return i.set(r),o.setLoading(),r.then(e=>{a(r)&&o.setResult(e)},e=>{a(r)&&o.setError(e)}),r;{const e=r;return o.setResult(e),Promise.resolve(e)}},d=!c();return e.useEffect(()=>{d?u.executeOnMount&&l(...s):u.executeOnUpdate&&l(...s)},s),{...o.value,set:o.set,execute:l,currentPromise:i.get()}},n=(e,t,r)=>n(e,t,r);exports.useAsync=n,exports.useAsyncAbortable=((t,r,s)=>{const u=e.useRef();return n(async(...e)=>{u.current&&u.current.abort();const r=new AbortController;u.current=r;try{return await t(r.signal,...e)}finally{u.current===r&&(u.current=void 0)}},r,s)}),exports.useAsyncCallback=(e=>s(e,[],{executeOnMount:!1,executeOnUpdate:!1,initialState:()=>({loading:!1,result:void 0,error:void 0})}));
"use strict";var e=require("react");const t={loading:!0,result:void 0,error:void 0},r={initialState:()=>t,executeOnMount:!0,executeOnUpdate:!0,setLoading:e=>t,setResult:(e,t)=>({loading:!1,result:e,error:void 0}),setError:(e,t)=>({loading:!1,result:void 0,error:e})},s=(t,s,n)=>{const u=(e=>({...r,...e}))(n),o=(t=>{const[r,s]=e.useState(()=>t.initialState());return{value:r,set:s,setLoading:()=>s(t.setLoading(r)),setResult:e=>s(t.setResult(e,r)),setError:e=>s(t.setError(e,r))}})(u),c=(()=>{const t=e.useRef(!1);return e.useEffect(()=>(t.current=!0,()=>{t.current=!1}),[]),()=>t.current})(),i=(()=>{const t=e.useRef(null);return{set:e=>t.current=e,get:()=>t.current,is:e=>t.current===e}})(),a=e=>c()&&i.is(e),l=(...e)=>{const r=t(...e);if(r instanceof Promise)return i.set(r),o.setLoading(),r.then(e=>{a(r)&&o.setResult(e)},e=>{a(r)&&o.setError(e)}),r;{const e=r;return o.setResult(e),Promise.resolve(e)}},d=!c();return e.useEffect(()=>{d?u.executeOnMount&&l(...s):u.executeOnUpdate&&l(...s)},s),{...o.value,set:o.set,execute:l,currentPromise:i.get()}},n=(e,t,r)=>s(e,t,r);exports.useAsync=n,exports.useAsyncAbortable=((t,r,s)=>{const u=e.useRef();return n(async(...e)=>{u.current&&u.current.abort();const r=new AbortController;u.current=r;try{return await t(r.signal,...e)}finally{u.current===r&&(u.current=void 0)}},r,s)}),exports.useAsyncCallback=(e=>s(e,[],{executeOnMount:!1,executeOnUpdate:!1,initialState:()=>({loading:!1,result:void 0,error:void 0})}));
//# sourceMappingURL=react-async-hook.cjs.production.js.map

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

import{useRef as e,useEffect as t,useState as r}from"react";const n={loading:!0,result:void 0,error:void 0},o={initialState:()=>n,executeOnMount:!0,executeOnUpdate:!0,setLoading:e=>n,setResult:(e,t)=>({loading:!1,result:e,error:void 0}),setError:(e,t)=>({loading:!1,result:void 0,error:e})},s=(n,s,u)=>{const i=(e=>({...o,...e}))(u),c=(e=>{const[t,n]=r(e.initialState());return{value:t,set:n,setLoading:()=>n(e.setLoading(t)),setResult:r=>n(e.setResult(r,t)),setError:r=>n(e.setError(r,t))}})(i),a=(()=>{const r=e(!1);return t(()=>(r.current=!0,()=>{r.current=!1}),[]),()=>r.current})(),l=(()=>{const t=e(null);return{set:e=>t.current=e,get:()=>t.current,is:e=>t.current===e}})(),d=e=>a()&&l.is(e),g=(...e)=>{const t=n(...e);if(t instanceof Promise)return l.set(t),c.setLoading(),t.then(e=>{d(t)&&c.setResult(e)},e=>{d(t)&&c.setError(e)}),t;{const e=t;return c.setResult(e),Promise.resolve(e)}},v=!a();return t(()=>{v?i.executeOnMount&&g(...s):i.executeOnUpdate&&g(...s)},s),{...c.value,set:c.set,execute:g,currentPromise:l.get()}},u=(e,t,r)=>u(e,t,r),i=(t,r,n)=>{const o=e();return u(async(...e)=>{o.current&&o.current.abort();const r=new AbortController;o.current=r;try{return await t(r.signal,...e)}finally{o.current===r&&(o.current=void 0)}},r,n)},c=e=>s(e,[],{executeOnMount:!1,executeOnUpdate:!1,initialState:()=>({loading:!1,result:void 0,error:void 0})});export{u as useAsync,i as useAsyncAbortable,c as useAsyncCallback};
import{useRef as e,useEffect as t,useState as r}from"react";const n={loading:!0,result:void 0,error:void 0},o={initialState:()=>n,executeOnMount:!0,executeOnUpdate:!0,setLoading:e=>n,setResult:(e,t)=>({loading:!1,result:e,error:void 0}),setError:(e,t)=>({loading:!1,result:void 0,error:e})},s=(n,s,u)=>{const i=(e=>({...o,...e}))(u),c=(e=>{const[t,n]=r(()=>e.initialState());return{value:t,set:n,setLoading:()=>n(e.setLoading(t)),setResult:r=>n(e.setResult(r,t)),setError:r=>n(e.setError(r,t))}})(i),a=(()=>{const r=e(!1);return t(()=>(r.current=!0,()=>{r.current=!1}),[]),()=>r.current})(),l=(()=>{const t=e(null);return{set:e=>t.current=e,get:()=>t.current,is:e=>t.current===e}})(),d=e=>a()&&l.is(e),g=(...e)=>{const t=n(...e);if(t instanceof Promise)return l.set(t),c.setLoading(),t.then(e=>{d(t)&&c.setResult(e)},e=>{d(t)&&c.setError(e)}),t;{const e=t;return c.setResult(e),Promise.resolve(e)}},v=!a();return t(()=>{v?i.executeOnMount&&g(...s):i.executeOnUpdate&&g(...s)},s),{...c.value,set:c.set,execute:g,currentPromise:l.get()}},u=(e,t,r)=>s(e,t,r),i=(t,r,n)=>{const o=e();return u(async(...e)=>{o.current&&o.current.abort();const r=new AbortController;o.current=r;try{return await t(r.signal,...e)}finally{o.current===r&&(o.current=void 0)}},r,n)},c=e=>s(e,[],{executeOnMount:!1,executeOnUpdate:!1,initialState:()=>({loading:!1,result:void 0,error:void 0})});export{u as useAsync,i as useAsyncAbortable,c as useAsyncCallback};
//# sourceMappingURL=react-async-hook.es.production.js.map

@@ -36,3 +36,3 @@ (function (global, factory) {

const useAsyncState = (options) => {
const [value, setValue] = react.useState(options.initialState());
const [value, setValue] = react.useState(() => options.initialState());
return {

@@ -115,3 +115,3 @@ value,

};
const useAsync = (asyncFunction, params, options) => useAsync(asyncFunction, params, options);
const useAsync = (asyncFunction, params, options) => useAsyncInternal(asyncFunction, params, options);
const useAsyncAbortable = (asyncFunction, params, options) => {

@@ -118,0 +118,0 @@ const abortControllerRef = react.useRef();

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

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):(e=e||self,t(e["react-async-hook"]={},e.React))}(this,function(e,t){"use strict";const r={loading:!0,result:void 0,error:void 0},n={initialState:()=>r,executeOnMount:!0,executeOnUpdate:!0,setLoading:e=>r,setResult:(e,t)=>({loading:!1,result:e,error:void 0}),setError:(e,t)=>({loading:!1,result:void 0,error:e})},s=(e,r,s)=>{const o=(e=>({...n,...e}))(s),u=(e=>{const[r,n]=t.useState(e.initialState());return{value:r,set:n,setLoading:()=>n(e.setLoading(r)),setResult:t=>n(e.setResult(t,r)),setError:t=>n(e.setError(t,r))}})(o),c=(()=>{const e=t.useRef(!1);return t.useEffect(()=>(e.current=!0,()=>{e.current=!1}),[]),()=>e.current})(),i=(()=>{const e=t.useRef(null);return{set:t=>e.current=t,get:()=>e.current,is:t=>e.current===t}})(),a=e=>c()&&i.is(e),l=(...t)=>{const r=e(...t);if(r instanceof Promise)return i.set(r),u.setLoading(),r.then(e=>{a(r)&&u.setResult(e)},e=>{a(r)&&u.setError(e)}),r;{const e=r;return u.setResult(e),Promise.resolve(e)}},d=!c();return t.useEffect(()=>{d?o.executeOnMount&&l(...r):o.executeOnUpdate&&l(...r)},r),{...u.value,set:u.set,execute:l,currentPromise:i.get()}},o=(e,t,r)=>o(e,t,r);e.useAsync=o,e.useAsyncAbortable=((e,r,n)=>{const s=t.useRef();return o(async(...t)=>{s.current&&s.current.abort();const r=new AbortController;s.current=r;try{return await e(r.signal,...t)}finally{s.current===r&&(s.current=void 0)}},r,n)}),e.useAsyncCallback=(e=>s(e,[],{executeOnMount:!1,executeOnUpdate:!1,initialState:()=>({loading:!1,result:void 0,error:void 0})}))});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):(e=e||self,t(e["react-async-hook"]={},e.React))}(this,function(e,t){"use strict";const r={loading:!0,result:void 0,error:void 0},n={initialState:()=>r,executeOnMount:!0,executeOnUpdate:!0,setLoading:e=>r,setResult:(e,t)=>({loading:!1,result:e,error:void 0}),setError:(e,t)=>({loading:!1,result:void 0,error:e})},s=(e,r,s)=>{const o=(e=>({...n,...e}))(s),u=(e=>{const[r,n]=t.useState(()=>e.initialState());return{value:r,set:n,setLoading:()=>n(e.setLoading(r)),setResult:t=>n(e.setResult(t,r)),setError:t=>n(e.setError(t,r))}})(o),c=(()=>{const e=t.useRef(!1);return t.useEffect(()=>(e.current=!0,()=>{e.current=!1}),[]),()=>e.current})(),i=(()=>{const e=t.useRef(null);return{set:t=>e.current=t,get:()=>e.current,is:t=>e.current===t}})(),a=e=>c()&&i.is(e),l=(...t)=>{const r=e(...t);if(r instanceof Promise)return i.set(r),u.setLoading(),r.then(e=>{a(r)&&u.setResult(e)},e=>{a(r)&&u.setError(e)}),r;{const e=r;return u.setResult(e),Promise.resolve(e)}},d=!c();return t.useEffect(()=>{d?o.executeOnMount&&l(...r):o.executeOnUpdate&&l(...r)},r),{...u.value,set:u.set,execute:l,currentPromise:i.get()}},o=(e,t,r)=>s(e,t,r);e.useAsync=o,e.useAsyncAbortable=((e,r,n)=>{const s=t.useRef();return o(async(...t)=>{s.current&&s.current.abort();const r=new AbortController;s.current=r;try{return await e(r.signal,...t)}finally{s.current===r&&(s.current=void 0)}},r,n)}),e.useAsyncCallback=(e=>s(e,[],{executeOnMount:!1,executeOnUpdate:!1,initialState:()=>({loading:!1,result:void 0,error:void 0})}))});
//# sourceMappingURL=react-async-hook.umd.production.js.map
{
"name": "react-async-hook",
"version": "3.0.1",
"version": "3.1.0",
"description": "Async hook",

@@ -5,0 +5,0 @@ "author": "Sébastien Lorber",

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

Sorry, the diff of this file is not supported yet