react-async-hook
Advanced tools
Comparing version 2.1.0 to 2.2.0
@@ -19,2 +19,3 @@ export declare type AsyncState<R> = { | ||
export declare type UseAsyncReturn<R> = AsyncState<R> & { | ||
set: (value: AsyncState<R>) => void; | ||
execute: () => Promise<R>; | ||
@@ -21,0 +22,0 @@ currentPromise: Promise<R> | null; |
@@ -37,2 +37,3 @@ 'use strict'; | ||
value, | ||
set: setValue, | ||
setLoading: () => setValue(options.setLoading(value)), | ||
@@ -97,2 +98,3 @@ setResult: result => setValue(options.setResult(result, value)), | ||
...AsyncState.value, | ||
set: AsyncState.set, | ||
execute: executeAsyncOperation, | ||
@@ -99,0 +101,0 @@ currentPromise: CurrentPromise.get(), |
@@ -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})},n=(n,s,u)=>{const o=(e=>({...r,...e}))(u),c=(r=>{const[n,s]=e.useState(t);return{value:n,setLoading:()=>s(r.setLoading(n)),setResult:e=>s(r.setResult(e,n)),setError:e=>s(r.setError(e,n))}})(o),a=(()=>{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}})(),l=e=>a()&&i.is(e),d=()=>{const e=n(...s);return i.set(e),c.setLoading(),e.then(t=>{l(e)&&c.setResult(t)},t=>{l(e)&&c.setError(t)}),e},g=!a();return e.useEffect(()=>{g?o.executeOnMount&&d():o.executeOnUpdate&&d()},s),{...c.value,execute:d,currentPromise:i.get()}};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)}); | ||
"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=(s,n,u)=>{const o=(e=>({...r,...e}))(u),c=(r=>{const[s,n]=e.useState(t);return{value:s,set:n,setLoading:()=>n(r.setLoading(s)),setResult:e=>n(r.setResult(e,s)),setError:e=>n(r.setError(e,s))}})(o),a=(()=>{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}})(),l=e=>a()&&i.is(e),d=()=>{const e=s(...n);return i.set(e),c.setLoading(),e.then(t=>{l(e)&&c.setResult(t)},t=>{l(e)&&c.setError(t)}),e},g=!a();return e.useEffect(()=>{g?o.executeOnMount&&d():o.executeOnUpdate&&d()},n),{...c.value,set:c.set,execute:d,currentPromise:i.get()}};exports.useAsync=s,exports.useAsyncAbortable=((t,r,n)=>{const u=e.useRef();return s(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,n)}); | ||
//# sourceMappingURL=react-async-hook.cjs.production.js.map |
@@ -1,2 +0,2 @@ | ||
import{useEffect as r,useRef as e,useState as t}from"react";const n={loading:!0,result:void 0,error:void 0},o={initialState:n,executeOnMount:!0,executeOnUpdate:!0,setLoading:r=>n,setResult:(r,e)=>({loading:!1,result:r,error:void 0}),setError:(r,e)=>({loading:!1,result:void 0,error:r})},u=(u,s,c)=>{const i=(r=>({...o,...r}))(c),a=(r=>{const[e,o]=t(n);return{value:e,setLoading:()=>o(r.setLoading(e)),setResult:t=>o(r.setResult(t,e)),setError:t=>o(r.setError(t,e))}})(i),l=(()=>{const t=e(!1);return r(()=>(t.current=!0,()=>{t.current=!1}),[]),()=>t.current})(),d=(()=>{const r=e(null);return{set:e=>r.current=e,get:()=>r.current,is:e=>r.current===e}})(),g=r=>l()&&d.is(r),v=()=>{const r=u(...s);return d.set(r),a.setLoading(),r.then(e=>{g(r)&&a.setResult(e)},e=>{g(r)&&a.setError(e)}),r},x=!l();return r(()=>{x?i.executeOnMount&&v():i.executeOnUpdate&&v()},s),{...a.value,execute:v,currentPromise:d.get()}},s=(r,t,n)=>{const o=e();return u(async(...e)=>{o.current&&o.current.abort();const t=new AbortController;o.current=t;try{return await r(t.signal,...e)}finally{o.current===t&&(o.current=void 0)}},t,n)};export{u as useAsync,s as useAsyncAbortable}; | ||
import{useEffect as e,useRef 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=(s,u,c)=>{const i=(e=>({...o,...e}))(c),a=(e=>{const[t,o]=r(n);return{value:t,set:o,setLoading:()=>o(e.setLoading(t)),setResult:r=>o(e.setResult(r,t)),setError:r=>o(e.setError(r,t))}})(i),l=(()=>{const r=t(!1);return e(()=>(r.current=!0,()=>{r.current=!1}),[]),()=>r.current})(),d=(()=>{const e=t(null);return{set:t=>e.current=t,get:()=>e.current,is:t=>e.current===t}})(),g=e=>l()&&d.is(e),v=()=>{const e=s(...u);return d.set(e),a.setLoading(),e.then(t=>{g(e)&&a.setResult(t)},t=>{g(e)&&a.setError(t)}),e},x=!l();return e(()=>{x?i.executeOnMount&&v():i.executeOnUpdate&&v()},u),{...a.value,set:a.set,execute:v,currentPromise:d.get()}},u=(e,r,n)=>{const o=t();return s(async(...t)=>{o.current&&o.current.abort();const r=new AbortController;o.current=r;try{return await e(r.signal,...t)}finally{o.current===r&&(o.current=void 0)}},r,n)};export{s as useAsync,u as useAsyncAbortable}; | ||
//# sourceMappingURL=react-async-hook.es.production.js.map |
@@ -39,2 +39,3 @@ (function (global, factory) { | ||
value, | ||
set: setValue, | ||
setLoading: () => setValue(options.setLoading(value)), | ||
@@ -99,2 +100,3 @@ setResult: result => setValue(options.setResult(result, value)), | ||
...AsyncState.value, | ||
set: AsyncState.set, | ||
execute: executeAsyncOperation, | ||
@@ -101,0 +103,0 @@ currentPromise: CurrentPromise.get(), |
@@ -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,s,u)=>{const o=(e=>({...n,...e}))(u),c=(e=>{const[n,s]=t.useState(r);return{value:n,setLoading:()=>s(e.setLoading(n)),setResult:t=>s(e.setResult(t,n)),setError:t=>s(e.setError(t,n))}})(o),i=(()=>{const e=t.useRef(!1);return t.useEffect(()=>(e.current=!0,()=>{e.current=!1}),[]),()=>e.current})(),a=(()=>{const e=t.useRef(null);return{set:t=>e.current=t,get:()=>e.current,is:t=>e.current===t}})(),l=e=>i()&&a.is(e),d=()=>{const t=e(...s);return a.set(t),c.setLoading(),t.then(e=>{l(t)&&c.setResult(e)},e=>{l(t)&&c.setError(e)}),t},f=!i();return t.useEffect(()=>{f?o.executeOnMount&&d():o.executeOnUpdate&&d()},s),{...c.value,execute:d,currentPromise:a.get()}};e.useAsync=s,e.useAsyncAbortable=((e,r,n)=>{const u=t.useRef();return s(async(...t)=>{u.current&&u.current.abort();const r=new AbortController;u.current=r;try{return await e(r.signal,...t)}finally{u.current===r&&(u.current=void 0)}},r,n)})}); | ||
!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,s,u)=>{const o=(e=>({...n,...e}))(u),c=(e=>{const[n,s]=t.useState(r);return{value:n,set:s,setLoading:()=>s(e.setLoading(n)),setResult:t=>s(e.setResult(t,n)),setError:t=>s(e.setError(t,n))}})(o),i=(()=>{const e=t.useRef(!1);return t.useEffect(()=>(e.current=!0,()=>{e.current=!1}),[]),()=>e.current})(),a=(()=>{const e=t.useRef(null);return{set:t=>e.current=t,get:()=>e.current,is:t=>e.current===t}})(),l=e=>i()&&a.is(e),d=()=>{const t=e(...s);return a.set(t),c.setLoading(),t.then(e=>{l(t)&&c.setResult(e)},e=>{l(t)&&c.setError(e)}),t},f=!i();return t.useEffect(()=>{f?o.executeOnMount&&d():o.executeOnUpdate&&d()},s),{...c.value,set:c.set,execute:d,currentPromise:a.get()}};e.useAsync=s,e.useAsyncAbortable=((e,r,n)=>{const u=t.useRef();return s(async(...t)=>{u.current&&u.current.abort();const r=new AbortController;u.current=r;try{return await e(r.signal,...t)}finally{u.current===r&&(u.current=void 0)}},r,n)})}); | ||
//# sourceMappingURL=react-async-hook.umd.production.js.map |
{ | ||
"name": "react-async-hook", | ||
"version": "2.1.0", | ||
"version": "2.2.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
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
66505
308