Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
refactor!: remove cellArrayUtils.filterCells
This function was intended to be private and can be easily replaced by the `Array.filter` function.

BREAKING CHANGES: The `cellArrayUtils.filterCells` function has been removed. Use the `Array.filter` function instead.
  • Loading branch information
tbouffard committed Apr 5, 2025
commit 8031f713fd5a5210ebc52e6b5ddec50bf33ea03e
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ _**Note:** Yet to be released breaking changes appear here._
- `get`, `getAll`, `load`, `post`, `submit` via `requestUtils`
- `error`, `popup` via `guiUtils`
- The `utils` namespace has been removed. The remaining properties associated to this namespace have been moved to the `guiUtils` namespace.
- The `cellArrayUtils.filterCells` function has been removed. Use the `Array.filter` function instead.

## 0.16.0

Expand Down
36 changes: 31 additions & 5 deletions packages/core/__tests__/view/GraphDataModel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,49 @@ limitations under the License.
import { describe, expect, test } from '@jest/globals';
import { Cell, GraphDataModel } from '../../src';

describe('filterCells', () => {
const model: GraphDataModel = new GraphDataModel();

test('Filter cells with a valid filter function', () => {
const cell1 = new Cell();
const cells = [cell1, new Cell()];
const filter = (cell: Cell) => cell === cell1;
const result = model.filterCells(cells, filter);
expect(result).toEqual([cell1]);
});

test('Filter cells with an empty array', () => {
const cells: Cell[] = [];
const filter = (_cell: Cell) => true;
const result = model.filterCells(cells, filter);
expect(result).toEqual([]);
});

test('Filter cells with a filter function that returns false for all cells', () => {
const cells = [new Cell(), new Cell()];
const filter = (_cell: Cell) => false;
const result = model.filterCells(cells, filter);
expect(result).toEqual([]);
});
});

describe('isLayer', () => {
const dm: GraphDataModel = new GraphDataModel();
const model: GraphDataModel = new GraphDataModel();
const root: Cell = new Cell();
dm.setRoot(root);
model.setRoot(root);

test('Child is null', () => {
expect(dm.isLayer(null)).toBe(false);
expect(model.isLayer(null)).toBe(false);
});

test('Child is not null and is not layer', () => {
expect(dm.isLayer(new Cell())).toBe(false);
expect(model.isLayer(new Cell())).toBe(false);
});

test('Child is not null and is layer', () => {
const child = new Cell();
root.children.push(child);
child.setParent(root);
expect(dm.isLayer(child)).toBeTruthy();
expect(model.isLayer(child)).toBeTruthy();
});
});
16 changes: 0 additions & 16 deletions packages/core/src/util/cellArrayUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,6 @@ import Cell from '../view/cell/Cell';
import Dictionary from './Dictionary';
import ObjectIdentity from './ObjectIdentity';

/**
* Returns the cells from the given array where the given filter function
* returns true.
*/
export const filterCells = (filter: Function) => (cells: Cell[]) => {
const result = [] as Cell[];

for (let i = 0; i < cells.length; i += 1) {
if (filter(cells[i])) {
result.push(cells[i]);
}
}

return result;
};

/**
* Returns all opposite vertices terminal for the given edges, only returning sources and/or targets as specified.
* The result is returned as an array of {@link Cell}.
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/view/GraphDataModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ export class GraphDataModel extends EventSource {
}

filterCells(cells: Cell[], filter: FilterFunction) {
return filterCells(filter)(cells);
return cells.filter(filter);
}

getRoot(cell: Cell | null = null) {
Expand Down
Loading