@qixian.cs/github-contributors-list
Advanced tools
Comparing version 1.0.7 to 1.1.0
@@ -13,5 +13,7 @@ import React from 'react'; | ||
filter?: (item: AvatarListItem) => boolean; | ||
emptyRender?: (fileName: string, owner: string, repo: string) => React.ReactNode; | ||
renderItem?: (item?: AvatarListItem, loading?: boolean) => React.ReactNode; | ||
cache?: boolean; | ||
} | ||
declare const AvatarList: React.FC<ButtonProps>; | ||
export default AvatarList; |
@@ -433,2 +433,4 @@ import React, { useState, useEffect } from 'react'; | ||
var successCbQueue = []; | ||
var fetchLock = {}; | ||
// 获取头像列表 | ||
@@ -480,3 +482,6 @@ var getAvatarList = /*#__PURE__*/function () { | ||
return true; | ||
} : _ref3$filter; | ||
} : _ref3$filter, | ||
_ref3$cache = _ref3.cache, | ||
cache = _ref3$cache === void 0 ? false : _ref3$cache, | ||
emptyRender = _ref3.emptyRender; | ||
var _useState = useState([]), | ||
@@ -491,2 +496,11 @@ _useState2 = _slicedToArray(_useState, 2), | ||
useEffect(function () { | ||
if (cache && fetchLock[fileName]) { | ||
successCbQueue.push(function (items) { | ||
setList(items); | ||
setLoading(false); | ||
}); | ||
return; | ||
} | ||
// loading | ||
fetchLock[fileName] = true; | ||
setLoading(true); | ||
@@ -500,6 +514,16 @@ getAvatarList({ | ||
setLoading(false); | ||
cache && successCbQueue.forEach(function (fn) { | ||
return fn(data); | ||
}); | ||
}).catch(function () { | ||
setLoading(false); | ||
fetchLock[fileName] = false; | ||
}); | ||
}, [owner, repo, fileName]); | ||
useEffect(function () { | ||
return function () { | ||
fetchLock[fileName] = false; | ||
successCbQueue.splice(0, successCbQueue.length); | ||
}; | ||
}, [fileName]); | ||
if (loading) { | ||
@@ -516,2 +540,3 @@ return /*#__PURE__*/React.createElement("div", { | ||
} | ||
var displayList = list.filter(filter); | ||
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("ul", { | ||
@@ -526,3 +551,3 @@ className: className, | ||
}, style) | ||
}, list.filter(filter).map(function (item) { | ||
}, displayList.map(function (item) { | ||
if (renderItem) { | ||
@@ -545,5 +570,5 @@ return renderItem(item, loading); | ||
}))); | ||
}))); | ||
}), displayList.length === 0 && emptyRender && emptyRender(fileName, owner, repo))); | ||
}; | ||
export default AvatarList; |
@@ -439,2 +439,4 @@ 'use strict'; | ||
var successCbQueue = []; | ||
var fetchLock = {}; | ||
// 获取头像列表 | ||
@@ -486,3 +488,6 @@ var getAvatarList = /*#__PURE__*/function () { | ||
return true; | ||
} : _ref3$filter; | ||
} : _ref3$filter, | ||
_ref3$cache = _ref3.cache, | ||
cache = _ref3$cache === void 0 ? false : _ref3$cache, | ||
emptyRender = _ref3.emptyRender; | ||
var _useState = React.useState([]), | ||
@@ -497,2 +502,11 @@ _useState2 = _slicedToArray(_useState, 2), | ||
React.useEffect(function () { | ||
if (cache && fetchLock[fileName]) { | ||
successCbQueue.push(function (items) { | ||
setList(items); | ||
setLoading(false); | ||
}); | ||
return; | ||
} | ||
// loading | ||
fetchLock[fileName] = true; | ||
setLoading(true); | ||
@@ -506,6 +520,16 @@ getAvatarList({ | ||
setLoading(false); | ||
cache && successCbQueue.forEach(function (fn) { | ||
return fn(data); | ||
}); | ||
}).catch(function () { | ||
setLoading(false); | ||
fetchLock[fileName] = false; | ||
}); | ||
}, [owner, repo, fileName]); | ||
React.useEffect(function () { | ||
return function () { | ||
fetchLock[fileName] = false; | ||
successCbQueue.splice(0, successCbQueue.length); | ||
}; | ||
}, [fileName]); | ||
if (loading) { | ||
@@ -522,2 +546,3 @@ return /*#__PURE__*/React__default['default'].createElement("div", { | ||
} | ||
var displayList = list.filter(filter); | ||
return /*#__PURE__*/React__default['default'].createElement(React__default['default'].Fragment, null, /*#__PURE__*/React__default['default'].createElement("ul", { | ||
@@ -532,3 +557,3 @@ className: className, | ||
}, style) | ||
}, list.filter(filter).map(function (item) { | ||
}, displayList.map(function (item) { | ||
if (renderItem) { | ||
@@ -551,5 +576,5 @@ return renderItem(item, loading); | ||
}))); | ||
}))); | ||
}), displayList.length === 0 && emptyRender && emptyRender(fileName, owner, repo))); | ||
}; | ||
module.exports = AvatarList; |
{ | ||
"name": "@qixian.cs/github-contributors-list", | ||
"version": "1.0.7", | ||
"version": "1.1.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
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
64155
1658