Skip to content

Лебедкин Константин#13

Open
LNK09 wants to merge 2 commits into
RTF-Angular-2021:masterfrom
LNK09:Lebedkin_Konstantin
Open

Лебедкин Константин#13
LNK09 wants to merge 2 commits into
RTF-Angular-2021:masterfrom
LNK09:Lebedkin_Konstantin

Conversation

@LNK09
Copy link
Copy Markdown

@LNK09 LNK09 commented Apr 17, 2021

No description provided.

Comment thread src/task_1/index.ts
@DecorateEn
public exec(): string {
return (this.a + this.b).toString();
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment thread src/task_2/index.ts
@confirmMail
public email: string = "misha@mail.ru";
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

3 бала

Comment thread src/task_3/index.ts

/**Класс описывает SelectBox контрол */
class SelectBox extends Control<SelectItem> {
private item: SelectItem;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

зачем? у тебя ешь шаблонное поле value, которое выполняет туже самую функцию

Comment thread src/task_3/index.ts
}

public register<?>(type: ?) {
public register(type: Function) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

тут должны были использоваться generic-типы.

Comment thread src/task_3/index.ts
@@ -61,5 +102,5 @@ factory.register(SelectBox);

const selectBoxInstance = factory.getInstance(SelectBox);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

т.к. не используются generic-типы в этот метод можно передать любой тип.
Задача решена не верна

Comment thread src/task_4/index.ts

const x = undefined;
const x = { "year": 2016 };

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

3 бала

Comment thread src/task_5/index.ts
@validate(ValueExample2, "booleanProp")
public propValueExample2: any;
}
Object.defineProperty(target, propertyName, {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Это не обязательно, декоратор итак возвращает дескриптор

Comment thread src/task_5/index.ts
return type;
},
set(newType) {
if (newType === type) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

сюда залетает объект а не тип.

Comment thread src/task_5/index.ts
this.booleanProp = booleanProp;
}
}
function validate(type: object, propertyKey: string) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

нет проверки на принадлежность поля к типу. приложил правильное решени

Comment thread src/task_5/index.ts

@validate(ValueExample2, "booleanProp")
public propValueExample2: any;
} No newline at end of file
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

function validate<T, P extends keyof T>(type: new () => T, prop: P): (target: Object, propertyKey: string | symbol) => any {
let temp: T;
return (target: Object, propertyKey: string | symbol): PropertyDescriptor => {
let descriptor: PropertyDescriptor = {
get: function () {
return temp;
},
set: function (val: T) {
if (!(val instanceof type)) {
throw new Error("Устанавливается значение которое не соотвтетсвует типу");
}
if (temp[prop]) {
throw new Error("У требуемого поля не верный примитивный тип");
}
console.log("value valid");
temp = val;
}
};

    return descriptor;
};

}

class ValueExample1 {
public value: string;
public id: number;
}

class ValueExample2 {
public prop3: undefined;
public prop2: boolean;
}

class Example {
@Validate(ValueExample1, "id1")
public propValueExample1: any;

@validate(ValueExample2, "prop3")
public propValueExample2: any;

}

let ex1 = new Example();

let objValExample = new ValueExample1();
objValExample.id = 1;
objValExample.value = "qwe";
ex1.propValueExample1 = objValExample;

ex1.propValueExample2 = false;

@m-abrosimov
Copy link
Copy Markdown

итого 6 балов

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants