Skip to content

Criteria

ALexeyP0708 edited this page Jul 5, 2020 · 1 revision

Criteria - a set of parameters that describes a "member of the class" when inheriting an interface and is formed by the same member of the Interface. There are three types of criteria - property (CriteriaPropertyType) / method (CriteriaMethodType) / reactive property (CriteriaReactType). Criteria are created based on appropriate templates.

CriteriaPropertyType template is a simple object [object Object] that partially repeats the construction of the object [object CriteriaPropertyType].
CriteriaMethodType template is a simple object [object Object] that partially repeats the construction of the object [object CriteriaMethodType] CriteriaReactType template is a simple object [object Object] that partially repeats the construction of the object [object CriteriaReactType]

class MyType{};
 /* CriteriaPropertyType template */ 
 /* Сriteria are for class properties, class method arguments, class method return result, for get or set reactive class properties */ 
let criteriaProp={ 
	/*
	 expected value types as a result
	absence of parameter or absence of types is equivalent to types: ['mixed']
	if a constructor or object is specified in "types", then it will perform the following checks
	 [ObjectOrFunction === MyType] |
	 [ObjectOrFunction instanceof MyType] |
	 [MyType.isPrototypeOf(ObjectOrFunction)] |
	 [InterfaceManager.instaceOfInterface(ObjectOrFunction,MyType)] 
	*/
	 types:[ 
	 // list types and / or classes
			 'null', // or null
			 'undefined', // or undefined
			 'object', // [object ClassName]
			 'boolean', // or Boolean
			 'number', // or Number
			 'string', // or String
			 'symbol', // or Symbol
			 'function',
			 'mixed', // if specified, then all other types do not matter
			 MyType 
	 ], 
	 /*types:'number' //- one type */
	 
	/* 
	Expected values ​​as a result.
	If empty or missing, this rule does not apply. 
	If a constructor or object is specified in "includes", then it will perform the following checks
	 [ObjectOrFunction === MyType] |
	 [ObjectOrFunction instanceof MyType] |
	 [MyType.isPrototypeOf(ObjectOrFunction)] |
	 [InterfaceManager.instaceOfInterface(ObjectOrFunction,MyType)] 
	*/
	 includes:[], 
 /* 
 */
	
	/*
	Not expected values ​​as a result.
	If empty or missing, this rule does not apply.
	If a constructor or object is specified in "includes", then it will perform the following checks
	 [ObjectOrFunction === MyType] |
	 [ObjectOrFunction instanceof MyType] |
	 [MyType.isPrototypeOf(ObjectOrFunction)] |
	 [InterfaceManager.instaceOfInterface(ObjectOrFunction,MyType)] 
	*/
	 excludes:[],
 }
/*
 CriteriaMethodTypetemplate 
*/
let criteriaMethod={
	/*
	arguments criteria.
	CriteriaPropertyType templates are listed
	the absence of a parameter is equivalent, arguments:[]
	*/
	arguments:[
		{},
		{},
		//...
	],
	// CriteriaPropertyType template criteria for return result
	return:{}
}
/*
 CriteriaReactType template criteria for reactive properties
*/
let criteriaReact={
	get:{  // template CriteriaPropertyType or CriteriaMethodType {return:{}}
		types:[],
		includes:[],
		excludes:[]
	},
	set:{ // template CriteriaPropertyType or CriteriaMethodType {arguments:[{}]}
		types:[],
		includes:[],
		excludes:[]
	}
}

class MyInterface{
	method(){
		return criteriaMethod;
	}
	get react (){
		return criteriaReact.get;
	}
	set react (v){
		return criteriaReact.set;
	}
	static s_method(){
		return criteriaMethod;
	}
	static get s_react (){
		return criteriaReact.get;
	}
	static set s_react (v){
		return criteriaReact.set;
	}
}
MyInterface.prototype.prop=criteriaProp;
MyInterface.s_prop=criteriaProp;
MyInterface.isInterface=true;

class MyClass{}
InterfaceManager.extendInterfaces(MyClass,MyInterface);

Clone this wiki locally