wappsto-blanket
Advanced tools
Comparing version 0.0.21 to 0.0.22
@@ -1,2 +0,2 @@ | ||
import { useState, useRef, useCallback } from 'react'; | ||
import { useState, useRef, useCallback, useEffect } from 'react'; | ||
import { getSession } from 'wappsto-redux/selectors/session'; | ||
@@ -25,2 +25,3 @@ import { useSelector } from 'react-redux'; | ||
const cancelFunc = useRef(); | ||
const unmounted = useRef(false); | ||
@@ -51,6 +52,8 @@ const setCurrentStatus = (status) => { | ||
let more = true; | ||
let offset = 0; | ||
try{ | ||
while(more && !isCanceled.current){ | ||
const url = `${getServiceUrl('log')}/${stateId}?start=${start}&end=${end}&offset=${offset}&type=state&limit=3600`; | ||
if(cachedData.current.length > 0){ | ||
start = cachedData.current[cachedData.current.length - 1].time; | ||
} | ||
const url = `${getServiceUrl('log')}/${stateId}?start=${start}&end=${end}&type=state&limit=3600`; | ||
const result = await axios.get(url, { | ||
@@ -66,5 +69,7 @@ headers: { "x-session": sessionId || activeSession.meta.id }, | ||
cachedData.current = cachedData.current.concat(result.data.data); | ||
offset = cachedData.current.length; | ||
more = result.data.more; | ||
} | ||
if(unmounted.current){ | ||
return; | ||
} | ||
if(!isCanceled.current){ | ||
@@ -75,2 +80,5 @@ setData(cachedData.current); | ||
} catch(e){ | ||
if(unmounted.current){ | ||
return; | ||
} | ||
if(!isCanceled.current){ | ||
@@ -85,2 +93,8 @@ setData(cachedData.current); | ||
useEffect(() => { | ||
return () => { | ||
unmounted.current = true; | ||
} | ||
}, []); | ||
const cancel = useCallback(() => { | ||
@@ -87,0 +101,0 @@ if(cancelFunc.current){ |
@@ -1,2 +0,2 @@ | ||
import { useState, useRef, useCallback, useMemo } from 'react'; | ||
import { useState, useRef, useCallback, useMemo, useEffect } from 'react'; | ||
import { useSelector, useDispatch } from 'react-redux'; | ||
@@ -31,2 +31,3 @@ import { setItem } from 'wappsto-redux/actions/items'; | ||
const isCanceled = useRef(false); | ||
const unmounted = useRef(false); | ||
@@ -74,2 +75,5 @@ const setCurrentStatus = (status) => { | ||
); | ||
if(unmounted.current){ | ||
return; | ||
} | ||
if(result.status !== 200){ | ||
@@ -84,2 +88,5 @@ throw new Error("error"); | ||
} catch(e){ | ||
if(unmounted.current){ | ||
return; | ||
} | ||
setCurrentStatus(STATUS.ERROR); | ||
@@ -90,2 +97,8 @@ } | ||
useEffect(() => { | ||
return () => { | ||
unmounted.current = true; | ||
} | ||
}, []); | ||
const cancel = useCallback(() => { | ||
@@ -92,0 +105,0 @@ if(cancelFunc.current){ |
{ | ||
"name": "wappsto-blanket", | ||
"version": "0.0.21", | ||
"version": "0.0.22", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "scripts": { |
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
27289
821