fixed eslint issue of ArrayByCache and ArrayByCache.test.ts

This commit is contained in:
sunilyadav840 2021-10-05 15:32:01 +05:30
parent f968f57543
commit 9a1e9f7231
3 changed files with 8 additions and 10 deletions

View File

@ -44,8 +44,6 @@ src/Explorer/DataSamples/ContainerSampleGenerator.test.ts
src/Explorer/DataSamples/ContainerSampleGenerator.ts src/Explorer/DataSamples/ContainerSampleGenerator.ts
src/Explorer/DataSamples/DataSamplesUtil.test.ts src/Explorer/DataSamples/DataSamplesUtil.test.ts
src/Explorer/DataSamples/DataSamplesUtil.ts src/Explorer/DataSamples/DataSamplesUtil.ts
src/Explorer/Graph/GraphExplorerComponent/ArraysByKeyCache.test.ts
src/Explorer/Graph/GraphExplorerComponent/ArraysByKeyCache.ts
src/Explorer/Graph/GraphExplorerComponent/D3ForceGraph.test.ts src/Explorer/Graph/GraphExplorerComponent/D3ForceGraph.test.ts
src/Explorer/Graph/GraphExplorerComponent/D3ForceGraph.ts src/Explorer/Graph/GraphExplorerComponent/D3ForceGraph.ts
src/Explorer/Graph/GraphExplorerComponent/EdgeInfoCache.ts src/Explorer/Graph/GraphExplorerComponent/EdgeInfoCache.ts

View File

@ -6,7 +6,7 @@ describe("Cache arrays by key", () => {
const key = "key"; const key = "key";
cache.insert(key, 1, 0); cache.insert(key, 1, 0);
cache.clear(); cache.clear();
expect(cache.retrieve(key, 0, 1)).toBe(null); expect(cache.retrieve(key, 0, 1)).toBe(undefined);
}); });
it("should invalidate oldest key to keep cache size under maximum", () => { it("should invalidate oldest key to keep cache size under maximum", () => {
@ -21,7 +21,7 @@ describe("Cache arrays by key", () => {
cache.insert(key1, 2, 4); cache.insert(key1, 2, 4);
expect(cache.retrieve(key1, 0, 3)).toEqual([0, 2, 4]); expect(cache.retrieve(key1, 0, 3)).toEqual([0, 2, 4]);
expect(cache.retrieve(key2, 1, 1)).toEqual(null); expect(cache.retrieve(key2, 1, 1)).toEqual(undefined);
}); });
it("should cache and retrieve cached page within boundaries", () => { it("should cache and retrieve cached page within boundaries", () => {
@ -39,7 +39,7 @@ describe("Cache arrays by key", () => {
const key = "key"; const key = "key";
cache.insert(key, 0, 0); cache.insert(key, 0, 0);
cache.insert(key, 1, 1); cache.insert(key, 1, 1);
expect(cache.retrieve(key, 2, 1)).toEqual(null); expect(cache.retrieve(key, 2, 1)).toEqual(undefined);
}); });
it("should not retrieve cached page overlapping boundaries", () => { it("should not retrieve cached page overlapping boundaries", () => {
@ -48,7 +48,7 @@ describe("Cache arrays by key", () => {
cache.insert(key, 0, 0); cache.insert(key, 0, 0);
cache.insert(key, 1, 1); cache.insert(key, 1, 1);
cache.insert(key, 2, 2); cache.insert(key, 2, 2);
expect(cache.retrieve(key, 2, 4)).toEqual(null); expect(cache.retrieve(key, 2, 4)).toEqual(undefined);
}); });
it("should not insert non-contiguous element", () => { it("should not insert non-contiguous element", () => {
@ -57,7 +57,7 @@ describe("Cache arrays by key", () => {
cache.insert(key, 0, 0); cache.insert(key, 0, 0);
cache.insert(key, 1, 1); cache.insert(key, 1, 1);
cache.insert(key, 3, 3); cache.insert(key, 3, 3);
expect(cache.retrieve(key, 3, 1)).toEqual(null); expect(cache.retrieve(key, 3, 1)).toEqual(undefined);
}); });
it("should cache multiple keys", () => { it("should cache multiple keys", () => {

View File

@ -61,12 +61,12 @@ export class ArraysByKeyCache<T> {
* @param pageSize * @param pageSize
*/ */
public retrieve(key: string, startIndex: number, pageSize: number): T[] | null { public retrieve(key: string, startIndex: number, pageSize: number): T[] | null {
if (!this.cache.hasOwnProperty(key)) { if (!Object.prototype.hasOwnProperty.call(this.cache, key)) {
return null; return undefined;
} }
const elements = this.cache[key]; const elements = this.cache[key];
if (startIndex + pageSize > elements.length) { if (startIndex + pageSize > elements.length) {
return null; return undefined;
} }
return elements.slice(startIndex, startIndex + pageSize); return elements.slice(startIndex, startIndex + pageSize);