nhanh-pure-function 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/User.d.ts CHANGED
@@ -1,26 +1,10 @@
1
1
  /**
2
- * 添加滚动触底事件
3
- * @param {滚动标签} element
2
+ * 滚动触底事件
4
3
  * @param {触底事件} callback
5
4
  */
6
- export function _AddScrollBottomListener(
7
- element: HTMLElement,
5
+ export function _ScrollBottomListener(
8
6
  callback: Function
9
- ): void;
10
-
11
- /**
12
- * 自动处理 currentPage * pageSize > total
13
- * @param ask 请求方法
14
- * @param config 请求参数
15
- */
16
- export function _PagingQuery<Ask extends (...args: any[]) => any>(
17
- ask: Ask,
18
- config: {
19
- currentPage: number;
20
- pageSize: number;
21
- [key: string]: any;
22
- }
23
- ): ReturnType<Ask> & { currentPage?: number };
7
+ ): (payload: Event) => void;
24
8
 
25
9
  /**
26
10
  * 纯数字转 数字加单位
package/lib/User.js CHANGED
@@ -1,48 +1,18 @@
1
- import { _IsObject, _IsWithinErrorMargin, _NotNull } from "./Utility";
1
+ import { _IsObject, _NotNull } from "./Utility";
2
2
 
3
3
  /**
4
- * 添加滚动触底事件
5
- * @param {滚动标签} element
4
+ * 滚动触底事件
6
5
  * @param {触底事件} callback
7
6
  */
8
- export function _AddScrollBottomListener(element, callback) {
9
- element.addEventListener("scroll", function () {
10
- if (
11
- _IsWithinErrorMargin(
12
- element.scrollTop + element.clientHeight,
13
- element.scrollHeight,
14
- 2
15
- )
16
- ) {
7
+ export function _ScrollBottomListener(callback) {
8
+ return function (payload) {
9
+ const target = payload.target;
10
+ const { scrollTop, scrollHeight, clientHeight } = target;
11
+ const bottom = scrollHeight - scrollTop - clientHeight;
12
+ if (bottom <= 1) {
17
13
  callback();
18
14
  }
19
- });
20
- }
21
-
22
- /**
23
- * 自动处理 currentPage * pageSize > total
24
- * @param ask 请求方法
25
- * @param config 请求参数
26
- */
27
- export function _PagingQuery(ask, config) {
28
- return new Promise(function (resolve, reject) {
29
- ask(config)
30
- .then((data) => {
31
- const { rows, total } = data;
32
- if (rows.length == 0 && total > 0) {
33
- config.currentPage = Math.ceil(total / config.pageSize);
34
- ask(config)
35
- .then((data) => {
36
- data.currentPage = config.currentPage;
37
- resolve(data);
38
- })
39
- .catch(reject);
40
- } else {
41
- resolve(data);
42
- }
43
- })
44
- .catch(reject);
45
- });
15
+ };
46
16
  }
47
17
 
48
18
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nhanh-pure-function",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "纯函数工具",
5
5
  "main": "lib/Index.js",
6
6
  "scripts": {