Skip to content

Commit 494b755

Browse files
authored
Merge pull request #47 from PxaMMaxP/refactoring/search-class
Refactoring/search class
2 parents f18d50f + 74b23bc commit 494b755

File tree

14 files changed

+143
-15
lines changed

14 files changed

+143
-15
lines changed

.eslintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@
137137
"contexts": [
138138
"FunctionDeclaration",
139139
"MethodDefinition",
140-
"ClassDeclaration"
140+
"ClassDeclaration",
141+
"ClassExpression"
141142
],
142143
"descriptionStyle": "body",
143144
"exemptedBy": ["deprecated"]

jest.config.coverage.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
module.exports = {
22
preset: 'ts-jest',
33
testEnvironment: 'node',
4-
testMatch: ['**/__tests__/**/*.ts', '**/?(*.)+(spec|test).ts'],
4+
testMatch: ['**/__tests__/**/*.test.ts', '**/?(*.)+(test).ts'],
5+
testPathIgnorePatterns: ['\\.spec\\.ts$', '\\.performance\\.test\\.ts$'],
56
moduleNameMapper: {
67
'^src/(.*)$': '<rootDir>/src/$1',
78
},

jest.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
module.exports = {
22
preset: 'ts-jest',
33
testEnvironment: 'node',
4-
testMatch: ['**/__tests__/**/*.ts', '**/?(*.)+(spec|test).ts'],
4+
testMatch: ['**/__tests__/**/*.test.ts', '**/?(*.)+(test).ts'],
5+
testPathIgnorePatterns: ['\\.spec\\.ts$', '\\.performance\\.test\\.ts$'],
56
moduleDirectories: ['node_modules', 'src'],
67
moduleNameMapper: {
78
'^src/(.*)$': '<rootDir>/src/$1',

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "prj",
33
"name": "Prj Plugin",
4-
"version": "0.6.1",
4+
"version": "0.6.2",
55
"minAppVersion": "0.15.0",
66
"description": "Prj Plugin - Project, Document, and Task Management",
77
"author": "M. Passarello",

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "obsidian-prj-plugin",
3-
"version": "0.6.1",
3+
"version": "0.6.2",
44
"description": "Prj Plugin - Project, Document, and Task Management",
55
"main": "main.js",
66
"scripts": {
@@ -17,12 +17,12 @@
1717
"lint:fix": "eslint --fix --ext .ts .",
1818
"format": "prettier --write .",
1919
"version:show": "node -e \"console.log(require('./package.json').version)\"",
20-
"test": "jest --testPathIgnorePatterns=\\.performance\\.test\\.ts$",
20+
"test": "jest",
2121
"test:file": "jest --watch --onlyChanged --coverage=true --verbose",
22-
"test:verbose": "jest --verbose --testPathIgnorePatterns=\\.performance\\.test\\.ts$",
23-
"test:watch": "jest --watch --onlyChanged --verbose --testPathIgnorePatterns=\\.performance\\.test\\.ts$",
22+
"test:verbose": "jest --verbose",
23+
"test:watch": "jest --watch --onlyChanged --verbose",
2424
"test:performance": "jest --config jest.config.performance.js --runInBand --verbose",
25-
"test:coverage": "jest --config jest.config.coverage.js --coverage --testPathIgnorePatterns=\\.performance\\.test\\.ts$"
25+
"test:coverage": "jest --config jest.config.coverage.js --coverage"
2626
},
2727
"keywords": [],
2828
"author": "",

src/libs/BlockRenderComponents/TableBlockRenderComponent.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import RedrawableBlockRenderComponent from './RedrawableBlockRenderComponent';
1010
import { IProcessorSettings } from '../../interfaces/IProcessorSettings';
1111
import Helper from '../Helper';
1212
import MetadataCache, { FileMetadata } from '../MetadataCache';
13-
import Search from '../Search/Search';
13+
import { ISearch } from '../Search/interfaces/ISearch';
14+
import { Search } from '../Search/Search';
1415
import Table, { RowsState, TableHeader } from '../Table';
1516

1617
/**
@@ -444,7 +445,7 @@ export type BlockRenderSettings = {
444445
* Search terms array used to filter the models.
445446
* If undefined, no search filter is applied.
446447
*/
447-
search: Search | undefined;
448+
search: ISearch | undefined;
448449

449450
/**
450451
* The search text.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { IDIContainer, IDIContainer_ } from './interfaces/IDIContainer';
2+
3+
/**
4+
* Dependency Injection Container
5+
*/
6+
const DIContainer_: IDIContainer_ = class DIContainer implements IDIContainer {
7+
private _dependencies = new Map<string, unknown>();
8+
9+
/**
10+
* Register a dependency
11+
* @param identifier The identifier of the dependency
12+
* @param dependency The dependency to register
13+
*/
14+
public register<T>(identifier: string, dependency: T): void {
15+
this._dependencies.set(identifier, dependency);
16+
}
17+
18+
/**
19+
* Resolve a dependency
20+
* @param identifier The identifier of the dependency
21+
* @returns The resolved dependency
22+
* @throws Error if the dependency is not found
23+
*/
24+
public resolve<T>(identifier: string): T {
25+
const dependency = this._dependencies.get(identifier);
26+
27+
if (!dependency) {
28+
throw new Error(`Dependency ${identifier} not found`);
29+
}
30+
31+
return dependency as T;
32+
}
33+
};
34+
35+
export { DIContainer_ as DIContainer };
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { test_IDIContainer } from './IDIContainer.spec';
2+
import { DIContainer } from '../DIContainer';
3+
4+
test_IDIContainer(DIContainer);
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { IDIContainer_, IDIContainer } from '../interfaces/IDIContainer';
2+
3+
/**
4+
* Test the implementation of a DIContainer
5+
* @param Container The DIContainer implementation to test.
6+
* Must implement {@link IDIContainer}, {@link IDIContainer_}
7+
*/
8+
export function test_IDIContainer(Container: IDIContainer_) {
9+
describe('IDIContainer Implementation Tests', () => {
10+
let container: IDIContainer;
11+
12+
beforeEach(() => {
13+
container = new Container();
14+
});
15+
16+
it('should register and resolve a dependency', () => {
17+
const identifier = 'myDependency';
18+
const dependency = { value: 42 };
19+
20+
container.register(identifier, dependency);
21+
22+
const resolvedDependency =
23+
container.resolve<typeof dependency>(identifier);
24+
expect(resolvedDependency).toBe(dependency);
25+
});
26+
27+
it('should throw an error when resolving a non-registered dependency', () => {
28+
const identifier = 'nonExistentDependency';
29+
30+
expect(() => container.resolve<unknown>(identifier)).toThrow();
31+
});
32+
33+
// Add more tests as necessary
34+
});
35+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Dependency Injection Container Constructor Interface
3+
*/
4+
export interface IDIContainer_ {
5+
new (): IDIContainer;
6+
}
7+
8+
/**
9+
* Dependency Injection Container Interface
10+
*/
11+
export interface IDIContainer {
12+
/**
13+
* Register a dependency
14+
* @param identifier The identifier of the dependency
15+
* @param dependency The dependency to register
16+
*/
17+
register<T>(identifier: string, dependency: T): void;
18+
19+
/**
20+
* Resolve a dependency
21+
* @param identifier The identifier of the dependency
22+
*/
23+
resolve<T>(identifier: string): T;
24+
}

0 commit comments

Comments
 (0)