@blocklet/list 0.9.9 → 0.9.12

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.
@@ -19,6 +19,8 @@ var _urlJoin = _interopRequireDefault(require("url-join"));
19
19
 
20
20
  var _constant = _interopRequireDefault(require("../../libs/constant"));
21
21
 
22
+ var _utils = require("../../libs/utils");
23
+
22
24
  var _filter = require("../../contexts/filter");
23
25
 
24
26
  var _item = _interopRequireDefault(require("./item"));
@@ -33,8 +35,6 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
33
35
 
34
36
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
35
37
 
36
- const cachePool = new Map();
37
-
38
38
  function Autocomplete() {
39
39
  const containerRef = (0, _react.useRef)(null);
40
40
  const panelRootRef = (0, _react.useRef)(null);
@@ -48,22 +48,11 @@ function Autocomplete() {
48
48
  } = (0, _filter.useFilterContext)();
49
49
  const muiTheme = (0, _styles.useTheme)();
50
50
  const getResults = (0, _react.useCallback)(async params => {
51
- const key = JSON.stringify(params);
52
- const target = cachePool.get(key);
53
- if (target) return target.data;
54
51
  const {
55
52
  data
56
53
  } = await storeApi.get(_constant.default.blockletsPath, {
57
54
  params
58
55
  });
59
-
60
- if (cachePool.size > _constant.default.cacheSize) {
61
- cachePool.clear();
62
- }
63
-
64
- cachePool.set(key, {
65
- data: data.dataList
66
- });
67
56
  return data.dataList || [];
68
57
  }, [storeApi]);
69
58
 
@@ -110,7 +99,8 @@ function Autocomplete() {
110
99
  panel: 'bl-autocomplete-panel',
111
100
  label: 'bl-autocomplete-label',
112
101
  form: 'bl-autocomplete-form',
113
- input: 'bl-autocomplete-input'
102
+ input: 'bl-autocomplete-input',
103
+ clearButton: 'bl-autocomplete-clear'
114
104
  },
115
105
  placeholder: t('common.searchStore'),
116
106
  initialState: {
@@ -131,7 +121,7 @@ function Autocomplete() {
131
121
  keyword: query
132
122
  });
133
123
 
134
- return [{
124
+ return (0, _utils.debounced)([{
135
125
  sourceId: 'blocklets',
136
126
 
137
127
  getItems() {
@@ -183,7 +173,7 @@ function Autocomplete() {
183
173
  }
184
174
 
185
175
  }
186
- }];
176
+ }]);
187
177
  }
188
178
 
189
179
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/list",
3
- "version": "0.9.9",
3
+ "version": "0.9.12",
4
4
  "description": "Common ux components of blocklet",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -42,7 +42,7 @@
42
42
  "dependencies": {
43
43
  "@algolia/autocomplete-js": "^1.7.1",
44
44
  "@algolia/autocomplete-theme-classic": "^1.7.1",
45
- "@arcblock/ux": "^2.4.0",
45
+ "@arcblock/ux": "^2.4.6",
46
46
  "@emotion/react": "^11.10.0",
47
47
  "@emotion/styled": "^11.10.0",
48
48
  "@mui/icons-material": "^5.8.4",
@@ -65,8 +65,8 @@
65
65
  "@babel/preset-react": "^7.18.6",
66
66
  "@emotion/babel-plugin": "^11.10.0",
67
67
  "babel-plugin-inline-react-svg": "^2.0.1",
68
- "eslint": "^8.21.0",
68
+ "eslint": "^8.22.0",
69
69
  "prettier": "^2.7.1"
70
70
  },
71
- "gitHead": "bb89ecfc4767e5799d59141d633d5955666fd8bf"
71
+ "gitHead": "5b35c44cb3deebe12e854ca9901e4d6e630a1c07"
72
72
  }
@@ -7,11 +7,10 @@ import { ThemeProvider as MuiThemeProvider, useTheme } from '@mui/material/style
7
7
  import joinUrl from 'url-join';
8
8
 
9
9
  import constant from '../../libs/constant';
10
+ import { debounced } from '../../libs/utils';
10
11
  import { useFilterContext } from '../../contexts/filter';
11
12
  import Blocklet from './item';
12
13
 
13
- const cachePool = new Map();
14
-
15
14
  export default function Autocomplete() {
16
15
  const containerRef = useRef(null);
17
16
  const panelRootRef = useRef(null);
@@ -21,20 +20,8 @@ export default function Autocomplete() {
21
20
 
22
21
  const getResults = useCallback(
23
22
  async (params) => {
24
- const key = JSON.stringify(params);
25
- const target = cachePool.get(key);
26
-
27
- if (target) return target.data;
28
-
29
23
  const { data } = await storeApi.get(constant.blockletsPath, { params });
30
24
 
31
- if (cachePool.size > constant.cacheSize) {
32
- cachePool.clear();
33
- }
34
-
35
- cachePool.set(key, {
36
- data: data.dataList,
37
- });
38
25
  return data.dataList || [];
39
26
  },
40
27
  [storeApi]
@@ -76,6 +63,7 @@ export default function Autocomplete() {
76
63
  label: 'bl-autocomplete-label',
77
64
  form: 'bl-autocomplete-form',
78
65
  input: 'bl-autocomplete-input',
66
+ clearButton: 'bl-autocomplete-clear',
79
67
  },
80
68
  placeholder: t('common.searchStore'),
81
69
  initialState: {
@@ -91,7 +79,7 @@ export default function Autocomplete() {
91
79
  pageSize: 10,
92
80
  keyword: query,
93
81
  };
94
- return [
82
+ return debounced([
95
83
  {
96
84
  sourceId: 'blocklets',
97
85
  getItems() {
@@ -130,7 +118,7 @@ export default function Autocomplete() {
130
118
  },
131
119
  },
132
120
  },
133
- ];
121
+ ]);
134
122
  },
135
123
  });
136
124