-
Notifications
You must be signed in to change notification settings - Fork 11
Зернюков Никита #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
daleunixal
wants to merge
3
commits into
RTF-Angular-2021:master
Choose a base branch
from
daleunixal:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,12 @@ abstract class Control<T> { | |
| } | ||
| /**Класс описывает TextBox контрол */ | ||
| class TextBox extends Control<string> { | ||
| getValue(): string { | ||
| return ""; | ||
| } | ||
|
|
||
| setValue(val: string): void { | ||
| } | ||
| } | ||
| /**value контрола selectBox */ | ||
| class SelectItem { | ||
|
|
@@ -29,11 +35,23 @@ class SelectItem { | |
|
|
||
| /**Класс описывает SelectBox контрол */ | ||
| class SelectBox extends Control<SelectItem> { | ||
| getValue(): SelectItem { | ||
| return undefined; | ||
| } | ||
|
|
||
| setValue(val: SelectItem): void { | ||
| } | ||
| } | ||
|
|
||
| class Container { | ||
| public instance: Control<any>; | ||
| public type: string; | ||
|
|
||
|
|
||
| constructor(instance: Control<any>, type: string) { | ||
| this.instance = instance; | ||
| this.type = type; | ||
| } | ||
| } | ||
|
|
||
| /**Фабрика которая отвечает за создание экземпляров контролов */ | ||
|
|
@@ -45,10 +63,17 @@ class FactoryControl { | |
| this._collection = []; | ||
| } | ||
|
|
||
| public register<?>(type: ?) { | ||
| public register<T extends Control<any>>(type: new () => T) { | ||
| const instanceType = (<Function>type).name; | ||
| if(this.existType(instanceType)) { | ||
| return; | ||
| } | ||
| this._collection.push(new Container(new type(), instanceType)); | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 instanceType = type.toString() | ||
| return this._collection.find(control => control.type === instanceType).instance; | ||
| } | ||
|
|
||
| private existType(type: string) { | ||
|
|
@@ -61,5 +86,5 @@ factory.register(SelectBox); | |
|
|
||
| const selectBoxInstance = factory.getInstance(SelectBox); | ||
|
|
||
| selectBoxInstance.setValue("sdfsdf") // компилятор TS не пропускает | ||
| //selectBoxInstance.setValue("sdfsdf") // компилятор TS не пропускает | ||
| selectBoxInstance.setValue(new SelectItem()) // компилятор TS пропускает | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,31 @@ | |
| * Если поле не заполнено, то генерируется эксепшен. | ||
| */ | ||
|
|
||
| function validate<T, P extends keyof T>(type: new () => T, prop: P) { | ||
| return (target: Object, propertyKey: string | symbol) : any => { | ||
| let property: T; | ||
| let descriptor: PropertyDescriptor = { | ||
| get() { | ||
| return property; | ||
| }, | ||
| set(value: T) { | ||
| if(!(value instanceof type)){ | ||
| throw new Error(`Input value has another type: ${type.name}`) | ||
| } | ||
| if (!(prop in value)) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Нет проверки на соответствие типа. |
||
| throw new Error(`${prop} not exist in value`) | ||
| } | ||
| if(!value[prop]) | ||
| throw new Error("Value must be defined") | ||
| console.log("VALID") | ||
| property = value; | ||
| } | ||
| } | ||
|
|
||
| return descriptor; | ||
| } | ||
| } | ||
|
|
||
| class ValueExample1 { | ||
| public value: string; | ||
| public id: number; | ||
|
|
@@ -25,10 +50,16 @@ class ValueExample2 { | |
| } | ||
| } | ||
|
|
||
| class Example { | ||
| class ExampleT { | ||
| @validate(ValueExample1, "id") | ||
| public propValueExample1: any; | ||
|
|
||
| @validate(ValueExample2, "booleanProp") | ||
| public propValueExample2: any; | ||
| } | ||
|
|
||
| let quarta = new ExampleT(); | ||
| let valueTest1 = new ValueExample1("Sharpest", 32); | ||
| let valueTest2 = new ValueExample2() | ||
| quarta.propValueExample1 = valueTest1; | ||
| quarta.propValueExample2 = valueTest2; | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
засчитано 1 бал