Skip to content

Микрюков Максим#6

Open
loozmax wants to merge 4 commits intoRTF-Angular-2021:masterfrom
loozmax:maksim_mikryukov
Open

Микрюков Максим#6
loozmax wants to merge 4 commits intoRTF-Angular-2021:masterfrom
loozmax:maksim_mikryukov

Conversation

@loozmax
Copy link
Copy Markdown

@loozmax loozmax commented Apr 15, 2021

No description provided.

}
}

Object.defineProperty(target, propertyKey, {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Это не обязательно делать.

let exampleInstance = new Example1();
exampleInstance.email = "fkkldfjg"; // генерирует эксепшен
exampleInstance.email = "misha@mail.ru"; // выводит в консоль e-mail valid
exampleInstance.email = "misha@mail.ru"; // выводит в консоль e-mail valid 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.

3 бала

}

const test = new Calculator(10, 20);
test.exec();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Это не паттерн декоратор.
https://refactoring.guru/ru/design-patterns/decorator/typescript/example

const x = undefined;
const x = {m: 'some value'};

console.log(getProperty(x, "m")); 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.

3 бала


/**Класс описывает SelectBox контрол */
class SelectBox extends Control<SelectItem> {
protected value: 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.

Зачем переопределил? это поле имеет шаблонный тип в базовом классе.

const typeInst: Control<R> = new type();
const instance = this._collection.filter(element => element.type === typeInst.name);
return instance[0].instance;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Метод можно было сделать проще вот так
public getInstance<T extends Control>(type: new () => T): T {
const instance = this._collection.find(element => element.type === type.name);
return instance.instance as T;
}

const instance = this._collection.filter(element => element.type === typeInst.name);
return instance[0].instance;
}

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

}
}

const example = new Example(ValueExample1, ValueExample2);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Не правильно.
Цель данной задачи состояла в том , что бы понять как работает декоратор свойств и полей класса. В данном случае ты в свойство пытаешься установить тип, зачем?

В поле надо устанавливать объект, т.е. проверять это надо было вот так:

const example = new Example();
example.propValueExample1 = new ValueExample1("21", 21);
example.propValueExample2 = new ValueExample2();

}
}

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 propertyValue;
},
set(newVal: T) {
if (newVal === 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.

тут надо проверять тип передаваемого объекта вот так
newVal.constructor.name

@m-abrosimov
Copy link
Copy Markdown

Пока что 9 балов

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.

2 participants