react-async-hook
Advanced tools
Comparing version 2.2.1 to 2.3.0
@@ -10,3 +10,3 @@ export declare type AsyncState<R> = { | ||
export declare type UseAsyncOptionsNormalized<R> = { | ||
initialState: AsyncState<R>; | ||
initialState: () => AsyncState<R>; | ||
executeOnMount: boolean; | ||
@@ -13,0 +13,0 @@ executeOnUpdate: boolean; |
@@ -22,3 +22,3 @@ 'use strict'; | ||
const DefaultOptions = { | ||
initialState: InitialAsyncState, | ||
initialState: () => InitialAsyncState, | ||
executeOnMount: true, | ||
@@ -25,0 +25,0 @@ executeOnUpdate: true, |
@@ -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=(t,n,s)=>{const u=(e=>({...r,...e}))(s),o=(t=>{const[r,n]=e.useState(t.initialState);return{value:r,set:n,setLoading:()=>n(t.setLoading(r)),setResult:e=>n(t.setResult(e,r)),setError:e=>n(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=()=>{const e=t(...n);return i.set(e),o.setLoading(),e.then(t=>{a(e)&&o.setResult(t)},t=>{a(e)&&o.setError(t)}),e},d=!c();return e.useEffect(()=>{d?u.executeOnMount&&l():u.executeOnUpdate&&l()},n),{...o.value,set:o.set,execute:l,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})},n=(t,n,s)=>{const u=(e=>({...r,...e}))(s),o=(t=>{const[r,n]=e.useState(t.initialState);return{value:r,set:n,setLoading:()=>n(t.setLoading(r)),setResult:e=>n(t.setResult(e,r)),setError:e=>n(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=()=>{const e=t(...n);return i.set(e),o.setLoading(),e.then(t=>{a(e)&&o.setResult(t)},t=>{a(e)&&o.setError(t)}),e},d=!c();return e.useEffect(()=>{d?u.executeOnMount&&l():u.executeOnUpdate&&l()},n),{...o.value,set:o.set,execute:l,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)}); | ||
//# sourceMappingURL=react-async-hook.cjs.production.js.map |
@@ -1,2 +0,2 @@ | ||
import{useEffect as t,useRef as e,useState as r}from"react";const n={loading:!0,result:void 0,error:void 0},o={initialState:n,executeOnMount:!0,executeOnUpdate:!0,setLoading:t=>n,setResult:(t,e)=>({loading:!1,result:t,error:void 0}),setError:(t,e)=>({loading:!1,result:void 0,error:t})},s=(n,s,u)=>{const c=(t=>({...o,...t}))(u),i=(t=>{const[e,n]=r(t.initialState);return{value:e,set:n,setLoading:()=>n(t.setLoading(e)),setResult:r=>n(t.setResult(r,e)),setError:r=>n(t.setError(r,e))}})(c),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=t=>a()&&l.is(t),g=()=>{const t=n(...s);return l.set(t),i.setLoading(),t.then(e=>{d(t)&&i.setResult(e)},e=>{d(t)&&i.setError(e)}),t},v=!a();return t(()=>{v?c.executeOnMount&&g():c.executeOnUpdate&&g()},s),{...i.value,set:i.set,execute:g,currentPromise:l.get()}},u=(t,r,n)=>{const o=e();return s(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)};export{s as useAsync,u as useAsyncAbortable}; | ||
import{useEffect as t,useRef as e,useState as r}from"react";const n={loading:!0,result:void 0,error:void 0},o={initialState:()=>n,executeOnMount:!0,executeOnUpdate:!0,setLoading:t=>n,setResult:(t,e)=>({loading:!1,result:t,error:void 0}),setError:(t,e)=>({loading:!1,result:void 0,error:t})},s=(n,s,u)=>{const c=(t=>({...o,...t}))(u),i=(t=>{const[e,n]=r(t.initialState);return{value:e,set:n,setLoading:()=>n(t.setLoading(e)),setResult:r=>n(t.setResult(r,e)),setError:r=>n(t.setError(r,e))}})(c),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=t=>a()&&l.is(t),g=()=>{const t=n(...s);return l.set(t),i.setLoading(),t.then(e=>{d(t)&&i.setResult(e)},e=>{d(t)&&i.setError(e)}),t},v=!a();return t(()=>{v?c.executeOnMount&&g():c.executeOnUpdate&&g()},s),{...i.value,set:i.set,execute:g,currentPromise:l.get()}},u=(t,r,n)=>{const o=e();return s(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)};export{s as useAsync,u as useAsyncAbortable}; | ||
//# sourceMappingURL=react-async-hook.es.production.js.map |
@@ -24,3 +24,3 @@ (function (global, factory) { | ||
const DefaultOptions = { | ||
initialState: InitialAsyncState, | ||
initialState: () => InitialAsyncState, | ||
executeOnMount: true, | ||
@@ -27,0 +27,0 @@ executeOnUpdate: true, |
@@ -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 u=(e=>({...n,...e}))(s),o=(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))}})(u),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=()=>{const t=e(...r);return i.set(t),o.setLoading(),t.then(e=>{a(t)&&o.setResult(e)},e=>{a(t)&&o.setError(e)}),t},d=!c();return t.useEffect(()=>{d?u.executeOnMount&&l():u.executeOnUpdate&&l()},r),{...o.value,set:o.set,execute:l,currentPromise:i.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,r,s)=>{const u=(e=>({...n,...e}))(s),o=(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))}})(u),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=()=>{const t=e(...r);return i.set(t),o.setLoading(),t.then(e=>{a(t)&&o.setResult(e)},e=>{a(t)&&o.setError(e)}),t},d=!c();return t.useEffect(()=>{d?u.executeOnMount&&l():u.executeOnUpdate&&l()},r),{...o.value,set:o.set,execute:l,currentPromise:i.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.2.1", | ||
"version": "2.3.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
66716