Skip to content

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

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

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

Conversation

@LNK09
Copy link
Copy Markdown

@LNK09 LNK09 commented Apr 17, 2021

No description provided.

@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.

@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 бала


/**Класс описывает 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, которое выполняет туже самую функцию

}

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-типы.

@@ -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-типы в этот метод можно передать любой тип.
Задача решена не верна


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 бала

@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.

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

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.

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

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.

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


@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