aio-class 2.1.1 → 2.1.3

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.
Files changed (3) hide show
  1. package/index.d.ts +9 -6
  2. package/index.js +9 -6
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -176,13 +176,11 @@ type I_sort<T> = {
176
176
  getValue: (row: T, dir: 'inc' | 'dec') => any;
177
177
  };
178
178
  type I_id = string | number;
179
- type I_EntityClass<T> = {
179
+ export type I_EntityMap<T> = {
180
180
  getChilds: (row: T) => T[] | undefined;
181
181
  setChilds: (row: T, childs: T[] | undefined) => T;
182
182
  getId: (row: T) => I_id;
183
183
  setId: (row: T) => T;
184
- getData?: () => T[];
185
- setData?: (v: T[]) => void;
186
184
  };
187
185
  type I_rowResult<T> = {
188
186
  row: T;
@@ -200,10 +198,14 @@ type I_rowResult<T> = {
200
198
  isLastChild: boolean;
201
199
  };
202
200
  export declare class EntityClass<T> {
203
- params: I_EntityClass<T>;
201
+ map: I_EntityMap<T>;
204
202
  getData: () => T[];
205
203
  setData: (v: T[]) => void;
206
- constructor(p: I_EntityClass<T>);
204
+ constructor(p: {
205
+ map: I_EntityMap<T>;
206
+ getData?: () => T[];
207
+ setData?: (v: T[]) => void;
208
+ });
207
209
  private getId;
208
210
  private setId;
209
211
  private getChilds;
@@ -248,7 +250,7 @@ export declare class EntityClass<T> {
248
250
  reOrderByDir: (data: T[], rowId: I_id, dir: 1 | -1) => T[];
249
251
  moveTo: (data: T[], fromIds: I_id[], toId: I_id) => T[];
250
252
  editByTraverse: (rows: T[], callback: (row: T) => T | false) => T[];
251
- traverse: (rows: T[], callback: (row: T, detail: I_rowResult<T>) => false | undefined) => T[];
253
+ traverse: (rows: T[], callback: (row: T, detail: I_rowResult<T>) => false | undefined) => void;
252
254
  };
253
255
  dataActions: {
254
256
  getRowDetailById: (rowId: any) => false | I_rowResult<T>;
@@ -269,6 +271,7 @@ export declare class EntityClass<T> {
269
271
  editByTraverse: (callback: (row: T) => T | false) => T[];
270
272
  getSortedTree: (sorts: I_sort<T>[]) => T[];
271
273
  getFilteredTree: (filter: (row: T, detail: I_rowResult<T>) => boolean | undefined) => T[];
274
+ traverse: (callback: (row: T, detail: I_rowResult<T>) => false | undefined) => void;
272
275
  };
273
276
  }
274
277
  type I_color = any;
package/index.js CHANGED
@@ -1501,10 +1501,10 @@ export class EntityClass {
1501
1501
  constructor(p) {
1502
1502
  this.getData = () => [];
1503
1503
  this.setData = () => { };
1504
- this.getId = (row) => this.params.getId(row);
1505
- this.setId = (row) => this.params.setId(row);
1506
- this.getChilds = (row) => this.params.getChilds(row);
1507
- this.setChilds = (row, childs) => this.params.setChilds(row, childs);
1504
+ this.getId = (row) => this.map.getId(row);
1505
+ this.setId = (row) => this.map.setId(row);
1506
+ this.getChilds = (row) => this.map.getChilds(row);
1507
+ this.setChilds = (row, childs) => this.map.setChilds(row, childs);
1508
1508
  this.getRowDetailsByIds = (data, rowIds) => {
1509
1509
  const fn = (data, parents, temp) => {
1510
1510
  const isFoundAll = () => Object.keys(temp).filter((rowId) => temp[rowId] === false).length === 0;
@@ -1826,7 +1826,6 @@ export class EntityClass {
1826
1826
  }
1827
1827
  };
1828
1828
  fn(rows, []);
1829
- return rows;
1830
1829
  };
1831
1830
  this.actions = {
1832
1831
  getId: this.getId,
@@ -1917,9 +1916,13 @@ export class EntityClass {
1917
1916
  const res = this.getFilteredTree(data, filter);
1918
1917
  this.setData(res);
1919
1918
  return res;
1919
+ },
1920
+ traverse: (callback) => {
1921
+ const data = this.getData();
1922
+ this.traverse(data, callback);
1920
1923
  }
1921
1924
  };
1922
- this.params = p;
1925
+ this.map = p.map;
1923
1926
  if (p.getData) {
1924
1927
  this.getData = p.getData;
1925
1928
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aio-class",
3
- "version": "2.1.1",
3
+ "version": "2.1.3",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/mohammadFeiz/aio-class#readme",
6
6
  "bugs": {