Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 9 additions & 0 deletions src/task_1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,12 @@ class Calculator {
return (this.a + this.b).toString();
}
}
class DecorateEn extends Calculator {
public exec(): string{
return `result of the addition operation ${this.a} + ${this.b} = ${super.exec()}`}
}
class DecorateRu extends Calculator {
public exec(): string{
return `результат сложения ${this.a} + ${this.b} = ${super.exec()}`}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


14 changes: 13 additions & 1 deletion src/task_2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,20 @@
* Когда присваивается корректный e-mail в консоль выводится сообщение email valid.
* Когда присваивается некорректный e-mail возбуждается ошибка.
*/
function validDecorator(target: Object, propertyKey: string):any{
let descriptor:PropertyDescriptor = {
set(email : string) {
if (email.match(/^([\w.*-]+@([\w-]+\.)+[\w-]{2,4})?$/g)){
console.log("email valid");
}
else throw "Invalid"
}
}
return descriptor;
}

class Example {
class Example{
@validDecorator
public email: string = "";
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 бала


Expand Down
42 changes: 35 additions & 7 deletions src/task_3/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,42 @@
abstract class Control<T> {
public name: string = "";

protected value: T;
protected value: T | undefined;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зачем используешь объединение типов?

/**взять значение из контрола */
public abstract getValue(): T;
public abstract getValue(): T | undefined;
/**установить значение в контрол */
public abstract setValue(val: T): void;
}
/**Класс описывает TextBox контрол */
class TextBox extends Control<string> {
protected val: string | undefined

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

зачем переопределил объект val?

public getValue(): string | undefined{
return this.val;
}
public setValue(val: string): void{
this.val = val;
}
}
/**value контрола selectBox */
class SelectItem {
public value: string;
public id: number;
public value: string | undefined;
public id: number | undefined;
}

/**Класс описывает SelectBox контрол */
class SelectBox extends Control<SelectItem> {
protected val: SelectItem | undefined;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

зачем поле в котором хранится значение ?

public getValue(): SelectItem | undefined{
return this.val;
}
public setValue(val: SelectItem): void{
this.val = val;
}
}

class Container {
public instance: Control<any>;
public type: string;
public type: string | undefined;
}

/**Фабрика которая отвечает за создание экземпляров контролов */
Expand All @@ -45,10 +59,24 @@ class FactoryControl {
this._collection = [];
}

public register<?>(type: ?) {
public register<T extends Control<any>>(type: new () => T){
const typeInstance: T = new type();
if (this.existType(typeInstance.name)) {
throw new Error("Already exists")
}
if (!(typeInstance instanceof Control)){
throw new Error("Invalid type");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нет регистрации типа и созданного объекта. Работать не будет.

}
}

public getInstance<?>(type: ?): ? {
public getInstance<T>(type: new () => Control<T>): Control<T>{
const typeInstance: Control<T> = new type();
const instances = this._collection.filter(g => g.type === typeInstance.name);
if (instances.length > 0) {
return instances[0].instance;
}
throw Error("Instance not found");
}

private existType(type: string) {
Expand Down
2 changes: 1 addition & 1 deletion src/task_4/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ function getProperty<T, K extends keyof T>(obj: T, key: K): T[K] {
return obj[key];
}

const x = undefined;
const x = { "m": "Ы" };

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 бала

console.log(getProperty(x, "m"));