File tree Expand file tree Collapse file tree 1 file changed +16
-24
lines changed
src/createAsyncStoragePersisor-experimental Expand file tree Collapse file tree 1 file changed +16
-24
lines changed Original file line number Diff line number Diff line change 11import AsyncStorage from '@react-native-community/async-storage'
22
3- function throttle ( func , wait ) {
4- if ( wait === 0 ) {
5- wait = 100
6- }
7-
8- var timer = null
9- return function ( ) {
10- for (
11- var _len = arguments . length , args = new Array ( _len ) , _key = 0 ;
12- _key < _len ;
13- _key ++
14- ) {
15- args [ _key ] = arguments [ _key ]
16- }
17-
18- if ( timer === null ) {
19- timer = setTimeout ( function ( ) {
20- func . apply ( 0 , args )
21- timer = null
22- } , wait )
23- }
24- }
25- }
26-
273export const asyncStoragePersistor = ( { asyncStorageKey, throttleTime } ) => {
284 return {
295 persistClient : throttle ( function ( persistedClient ) {
@@ -43,3 +19,19 @@ export const asyncStoragePersistor = ({ asyncStorageKey, throttleTime }) => {
4319 } ,
4420 }
4521}
22+
23+ function throttle < TArgs extends any [ ] > (
24+ func : ( ...args : TArgs ) => any ,
25+ wait = 100
26+ ) {
27+ let timer : number | null = null
28+
29+ return function ( ...args : TArgs ) {
30+ if ( timer === null ) {
31+ timer = setTimeout ( ( ) => {
32+ func ( ...args )
33+ timer = null
34+ } , wait )
35+ }
36+ }
37+ }
You can’t perform that action at this time.
0 commit comments