@azrico/reactgrid 1.1.0 → 1.1.2

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.
@@ -45,7 +45,7 @@ const filterValue = [{
45
45
  const contextMenuItems = ['test'];
46
46
  function getData() {
47
47
  const fd = [];
48
- for (let index = 0; index < 400; index++) {
48
+ for (let index = 0; index < 200; index++) {
49
49
  fd.push({
50
50
  __table_id: String(index),
51
51
  name: 'user-' + index,
package/dist/src/index.js CHANGED
@@ -19,6 +19,6 @@ Object.keys(_DataGrid).forEach(function (key) {
19
19
  });
20
20
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
21
21
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
22
- var _default = _DataGrid.default; //const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
22
+ var _default = _DataGrid.default; //const root = ReactDOM.createRoot(document.getElementById('testroot') as HTMLElement);
23
23
  //root.render(<ExampleGrid />);
24
24
  exports.default = _default;
@@ -15,6 +15,7 @@ var _helpers = require("../func/helpers");
15
15
  var _controls = require("@azrico/controls");
16
16
  var _reactdatagridEnterprise = _interopRequireDefault(require("@inovua/reactdatagrid-enterprise"));
17
17
  var _clsx = _interopRequireDefault(require("clsx"));
18
+ var _object = require("@azrico/object");
18
19
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
20
  /* -------------------------------------------------------------------------- */
20
21
  // const defaultfilterTypes: FilterTypes = {
@@ -61,22 +62,30 @@ function AzGrid(props) {
61
62
  /* Row changes */
62
63
  /* -------------------------------------------------------------------------- */
63
64
  const cached_data = _react.default.useRef();
64
- const last_ds = _react.default.useRef();
65
+ const last_cache_info = _react.default.useRef();
65
66
  const dataSource = _react.default.useCallback(async dt => {
66
67
  let result_data = undefined;
67
68
  let isUsingCache = false;
69
+ //console.log(dt);
70
+ const cacheInfo = {
71
+ ds: props.dataSource,
72
+ skip: dt.skip,
73
+ limit: dt.limit
74
+ };
68
75
  //check if we can used cached data
69
76
  //if the datasource is changed since last render, we should invalidate cache
70
- if (last_ds.current != props.dataSource) {
71
- //console.log('invalid cache', last_ds.current, props.dataSource);
77
+ if (!(0, _object.object_equals)(last_cache_info.current, cacheInfo)) {
78
+ //console.log('invalid cache', cacheInfo);
72
79
  cached_data.current = undefined;
73
- last_ds.current = props.dataSource;
80
+ last_cache_info.current = cacheInfo;
74
81
  }
75
82
  if (cached_data.current) {
76
83
  //cache is valid, use the cache
84
+ //console.log('use cache', cached_data.current);
77
85
  isUsingCache = true;
78
86
  result_data = cached_data.current;
79
87
  } else {
88
+ //console.log('use ds');
80
89
  //cache is invalid, use the datasource again
81
90
  isUsingCache = false;
82
91
  if (typeof props.dataSource === 'function') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azrico/reactgrid",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "main": "dist/index.js",
5
5
  "description": "React Datagrid",
6
6
  "author": "Azrideus <MehrdadTavangar@gmail.com>",
@@ -30,6 +30,7 @@
30
30
  },
31
31
  "dependencies": {
32
32
  "@azrico/controls": "1.3.0",
33
+ "@azrico/object": "^1.3.1",
33
34
  "@emotion/react": "^11.9.3",
34
35
  "@emotion/styled": "^11.9.3",
35
36
  "@inovua/reactdatagrid-enterprise": "^5.8.0",
package/public/index.html CHANGED
@@ -14,7 +14,7 @@
14
14
  <noscript>
15
15
  You need to enable JavaScript to run this app.
16
16
  </noscript>
17
- <div id="root" class="azgrid-filler azgrid-testborder azgrid-borderbox azgrid-nopad azgrid-nomargin"></div>
17
+ <div id="testroot" class="azgrid-filler azgrid-testborder azgrid-borderbox azgrid-nopad azgrid-nomargin"></div>
18
18
  </body>
19
19
 
20
20
  </html>
package/src/example.tsx CHANGED
@@ -33,7 +33,7 @@ const filterValue = [
33
33
  const contextMenuItems = ['test'];
34
34
  function getData() {
35
35
  const fd: any[] = [];
36
- for (let index = 0; index < 400; index++) {
36
+ for (let index = 0; index < 200; index++) {
37
37
  fd.push({ __table_id: String(index), name: 'user-' + index, age: 20 });
38
38
  if (index % 5 == 0) {
39
39
  const sub_selfid = 's' + index;
package/src/index.tsx CHANGED
@@ -7,5 +7,5 @@ import React from 'react';
7
7
  import ReactDOM from 'react-dom/client';
8
8
  export default AzGrid;
9
9
 
10
- //const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
10
+ //const root = ReactDOM.createRoot(document.getElementById('testroot') as HTMLElement);
11
11
  //root.render(<ExampleGrid />);
@@ -20,6 +20,7 @@ import { ContextMenu } from '@azrico/controls';
20
20
  import ReactDataGrid from '@inovua/reactdatagrid-enterprise';
21
21
  import { TypeOnSelectionChangeArg } from '@inovua/reactdatagrid-community/types/TypeDataGridProps';
22
22
  import clsx from 'clsx';
23
+ import { object_equals } from '@azrico/object';
23
24
  import { useResizeDetector } from 'react-resize-detector';
24
25
 
25
26
  /* -------------------------------------------------------------------------- */
@@ -154,25 +155,32 @@ export function AzGrid(props: AzGridProps) {
154
155
  /* -------------------------------------------------------------------------- */
155
156
 
156
157
  const cached_data = React.useRef<any>();
157
- const last_ds = React.useRef<any>();
158
+ const last_cache_info = React.useRef<any>();
159
+
158
160
  const dataSource = React.useCallback(
159
161
  async (dt) => {
160
162
  let result_data: any = undefined;
161
163
 
162
164
  let isUsingCache = false;
165
+ //console.log(dt);
166
+ const cacheInfo = { ds: props.dataSource, skip: dt.skip, limit: dt.limit };
163
167
  //check if we can used cached data
164
168
  //if the datasource is changed since last render, we should invalidate cache
165
- if (last_ds.current != props.dataSource) {
166
- //console.log('invalid cache', last_ds.current, props.dataSource);
169
+ if (!object_equals(last_cache_info.current, cacheInfo)) {
170
+ //console.log('invalid cache', cacheInfo);
167
171
  cached_data.current = undefined;
168
- last_ds.current = props.dataSource;
172
+ last_cache_info.current = cacheInfo;
169
173
  }
170
174
 
171
175
  if (cached_data.current) {
172
176
  //cache is valid, use the cache
177
+ //console.log('use cache', cached_data.current);
178
+
173
179
  isUsingCache = true;
174
180
  result_data = cached_data.current;
175
181
  } else {
182
+ //console.log('use ds');
183
+
176
184
  //cache is invalid, use the datasource again
177
185
  isUsingCache = false;
178
186