Skip to content

0.2.0 type TData

Ivan S Glazunov edited this page Feb 20, 2015 · 5 revisions

type TData = Prototype|TSync|TAsync|Object|any;

Describes the Protocol data storage in unfinished form. When rendering with Templates.dataRender, depending on the type of data are converted into result format.

Details about the possible content.

Instance can be placed in several ways.

As instance

As instanceof Prototype

var data: TData = Templates.doubles.div()(); // As example.
As method

As a method with option __templatesInstance as reference to an instance of the Prototype. Any function automatically wraps using Templates.wrapMethod.

var content = Templates.doubles.div(); // Returns `.content` wrapped method.
var data: TData = content; // Not necessarily to call content.
var data: TData = Templates.doubles.div();
As class

As a direct reference to the function-class constructor heir of Prototype. Allows not create tag and simplify the writing.

var data: TData = Templates.doubles.div;

TSync

type TSync = () => any;

Form of transfer function returns a static result for rendering.

var sync: TSync = () => { return fs.readFileSync('data'); };
var data: TData = sync;

TAsync

type TAsync = (callback: TCallback) => void;

Form of transfer function returns a static result for rendering.

var sync: TAsync = (callback: (result: any) => void) => {
	fs.readFile('data', (error, result) => {
		callback(result);
	});
};
var data: TData = sync;

Object

Any other type of objects will be verified by key in the search for appropriate TData types.

Clone this wiki locally